Skip to main content
Known Participant
April 17, 2010
Question

How to change alpha of an array?

  • April 17, 2010
  • 3 replies
  • 900 views

It's me again.

I am trying to dynamically change the alpha value of a set of movieclips on a timer.  The timer works but I get an error message from the function.     

This is the error:

TypeError: Error #1010: A term is undefined and has no properties.
at piedacoulisse_timer_fla:MainTimeline/zoom/piedacoulisse_timer_fla:onTime()[piedacoulisse_timer_fla.MainTimeline::frame1:124]
at flash.utils::Timer/flash.utils:Timer::_timerDispatch()
at flash.utils::Timer/flash.utils:Timer::tick()

This is the code:


  var txt:Array = ["txt1","txt2","txt3","txt4","txt5"];
 
  var flashTimer:Timer = new Timer(3000,5);
  flashTimer.addEventListener(TimerEvent.TIMER, onTime);
  flashTimer.start();
  var frame:int = 0;
 
  function onTime(evt:TimerEvent):void{
   zoomIn.slider_mc.txt[frame].alpha = 1;  \\ line 124
   frame ++;  
  }


Can anyone tell me what the problem is and how to fix it?

This topic has been closed for replies.

3 replies

Ned Murphy
Legend
April 17, 2010

I don't think the first two responses above will answer your problem.  It is unlikely the first will because it is using a string object as if it is an instance name of an object ( zoomIn.slider_mc.txt[frame].alpha = 1; ).  The second offering ( zoomIn.slider_mc["txt" + frame].alpha = 1;)  is likely off in not realizing that the strings in the array are the intended instance names (there will not be a txt0, which that solution would have happen on the first shot when frame = 0).

Since it contains string values, they cannot be directly targeted as objects, so the correct implementation may be...

  zoomIn.slider_mc[txt[frame]].alpha = 1;

where the brackets surrounding the array value tell the processor to treat the string value as an instance name

Known Participant
April 18, 2010

Sorry guys, no luck.  I tried all three suggestions and got the same error.  I ended up using timeline animation to change the alpha of my movieclips.  That worked but I am getting the error again when I try to stop some of the mc's from playing.  Here's the error:

TypeError: Error #1010: A term is undefined and has no properties.
at piedacoulisse_timer3_fla:MainTimeline/zoom/piedacoulisse_timer3_fla:onTime()[piedacoulisse_timer3_fla.MainTimeline::frame1:136]
at flash.utils::Timer/flash.utils:Timer::_timerDispatch()
at flash.utils::Timer/flash.utils:Timer::tick()

Here's the complete code, in case there is something I am not seeing elsewhere in the program:

slider_mc.tickMark_mc.stop();
slider_mc.stop();

var myRectangle:Rectangle = new Rectangle(9,9,125, 420);
var slideRectangle:Rectangle = new Rectangle(body_mc.x + 24.5,body_mc.y + 1,219.5,.01);
var startSlide:Number;
var deltaSlide:Number = 0;
var startMoveX:Number = 0;
var startMoveY:Number = 0;
var endMoveX:Number = 0;
var endMoveY:Number = 0;
var contactTop:Boolean = false;
var contactBottom:Boolean = false;
var contactPoint:String;

body_mc.addEventListener(MouseEvent.MOUSE_DOWN,pickUp);
body_mc.addEventListener(MouseEvent.MOUSE_UP,dropIt);
body_mc.addEventListener(MouseEvent.MOUSE_OUT,dropIt);
slider_mc.addEventListener(MouseEvent.MOUSE_DOWN,beginSlide);
slider_mc.addEventListener(MouseEvent.MOUSE_UP,stopSlide);
slider_mc.addEventListener(MouseEvent.MOUSE_OUT,stopSlide);
topMask.addEventListener(Event.ENTER_FRAME,moveMask);
botMask.addEventListener(Event.ENTER_FRAME,moveMask);
bodyMask.addEventListener(Event.ENTER_FRAME,moveMask);
stage.addEventListener(Event.ENTER_FRAME,zoom);

//  blockIt stops the draggable mc's when they hit the phone_mc


function blockIt(event:Event):void{
if(topMask.hitTestObject(phone_mc) == true){
  reply.text = "top hit";
  contactTop = true;
  event.currentTarget.stopDrag();
  contactPoint =  "top";
  nudgeIt(null);
}else if(botMask.hitTestObject(phone_mc) == true){
  reply.text = "bottom hit";
  contactBottom = true;
  event.currentTarget.stopDrag();
  contactPoint = "bottom";
  nudgeIt(null);
}else if(bodyMask.hitTestObject(phone_mc) == true){
  reply.text =  "body hit";
  event.currentTarget.stopDrag();
  contactPoint = "body";
  nudgeIt(null);
}
}

//  drags the hit-detection objects - I needed to do this to allow for a U-shaped object to surround another object.


function moveMask(event:Event){
topMask.x = body_mc.x+19;
topMask.y = body_mc.y+108;
botMask.x = slider_mc.x+32;
botMask.y = slider_mc.y+108;
bodyMask.x = body_mc.x+100;
bodyMask.y = body_mc.y+38;
}

//  drags the movable mc's


function pickUp(event:MouseEvent):void{
event.currentTarget.startDrag(false,myRectangle);
slider_mc.addEventListener(Event.ENTER_FRAME,followMe);
body_mc.addEventListener(Event.ENTER_FRAME,blockIt);
startMoveX = event.currentTarget.x;
startMoveY = event.currentTarget.y;
contactTop = false;
}


//  drops the movable mc's

function dropIt(event:MouseEvent):void{
event.currentTarget.stopDrag();
slider_mc.removeEventListener(Event.ENTER_FRAME,followMe);
endMoveX = event.currentTarget.y;
endMoveY = event.currentTarget.y;
contactBottom = false;
}

//  moves the slider with the body when it is dragged


function followMe(event:Event) {  
     slideRectangle.y = body_mc.y;
  slideRectangle.x = body_mc.x + 24.5;
  slider_mc.x = slideRectangle.x + deltaSlide;
  slider_mc.y = body_mc.y;
}

//  drags the slider along the body

function beginSlide(event:MouseEvent):void{
event.currentTarget.startDrag(false,slideRectangle);
deltaSlide = slider_mc.x - slideRectangle.x
contactBottom = false;
}


// drops the slider

function stopSlide(event:MouseEvent):void{
event.currentTarget.stopDrag();
}

// adjusts the postion of the draggable mc's to just butt up against the phone_mc - I did this so the mc's can be dragged again.  Without it, they are

locked in place by the hitTest.
function nudgeIt(event:Event):void{
if(contactPoint == "top"){
  body_mc.x = body_mc.x - 1;
}else if(contactPoint == "bottom"){
  slider_mc.x = slider_mc.x + 1;
}else if(contactPoint == "body"){
  body_mc.y = body_mc.y - 1;
}
}

// "zooms" in on the image and adds text commentary.  tickMark and oval mc's animate and then stop
//  This is where the error messages started appearing
//  Lines 136 137 and 138 all throw the same error

function zoom(event:Event):void{
if(contactTop == true &&contactBottom == true){
  body_mc.removeEventListener(MouseEvent.MOUSE_DOWN,pickUp);

  slider_mc.removeEventListener(MouseEvent.MOUSE_DOWN,beginSlide);
  var zoomIn:MovieClip = new MovieClip;
  zoomIn.addChild(phone_mc);
  zoomIn.addChild(body_mc);
  zoomIn.addChild(slider_mc);
 
  zoomIn.scaleX = 2.5; zoomIn.scaleY =2.5;
  addChild(zoomIn);
  zoomIn.x = -150; zoomIn.y = -350;

 
  slider_mc.tickMark_mc.gotoAndPlay(2);
 
  var flashTimer:Timer = new Timer(2000,8);
  flashTimer.addEventListener(TimerEvent.TIMER, onTime);
  flashTimer.start();
  var frame:int = 2;
 
  function onTime(evt:TimerEvent):void{
   slider_mc.gotoAndPlay(frame);
   slider_mc.stop();
   frame ++; 
   if(frame == 3){zoomIn.slider_mc.tickMark_mc.gotoAndStop(1);}   // line 136
   if(frame == 5){zoomIn.slider_mc.oval1_mc.gotoAndStop(1);}        // line 137
   if(frame == 7){zoomIn.slider_mc.oval2_mc.gotoAndStop(1);}        // line 138
  }
}
}

Ned Murphy
Legend
April 18, 2010

You probably have a naming issue within your zoomIn or your slider_mc.

April 17, 2010

You're close:

   zoomIn.slider_mc.txt[frame].alpha = 1;

Should be:

   zoomIn.slider_mc["txt" + frame].alpha = 1;

Kartik_Mehta
Inspiring
April 17, 2010

Hi,

try following code :-

var txt:Array = ["txt1","txt2","txt3","txt4","txt5"];
 
  var flashTimer:Timer = new Timer(3000,5);
  flashTimer.addEventListener(TimerEvent.TIMER, onTime);
  flashTimer.start();
  var frame:int = 0;
 
  function onTime(evt:TimerEvent):void{

  if(zoomIn.slider_mc.txt[frame]!=undefined)

{
   zoomIn.slider_mc.txt[frame].alpha = 1;  \\ line 124
   frame ++; 

}
  }