0

sorry, new to actionscript 3.

I have a display() function for an object rotator(image based like a QT object movie). It first saves the current image in a helper variable and then allocates a new image, from the library, beneath the old one. To get a nice crossfade effect, the old image's alpha is looped down via enter_frame and then removed.

Which is where there seems to be an issue with the display list, maybe recognizing oldImg's value as being already added? (it's not a first pass error)

Btw, do i have to remove the old image or can i leave it, for when it's being called up via the mouse position again? (the image number can get fairly large)

Does anyone have further insight? Thanks!

function display(num:Number):void   //num: image number
{
   ...    
   oldImg = newImg;   

   ClassReference = getDefinitionByName("Class"+num) as Class;
   imgBD = new ClassReference(0,0);
   newImg = new Bitmap(imgBD);

   images.addChild(newImg); 
   newImg.x=0;
   newImg.y=0;

}


function onEnter(evt:Event):void
{
    if (oldImg) 
    {
        if (oldImg.alpha > 0) oldImg.alpha -= 0.15; 
        **else images.removeChild(oldImg);**              
    }
        ...
}
Richard Inglis
  • 5,888
  • 2
  • 33
  • 37
Mocca
  • 1
  • What is 'images' and where does the error get thrown – Matti Lyra Apr 06 '10 at 09:55
  • Images is just a mc, layered beneath a cursor mc (grab hand), which has to be visible all the time. The error gets thrown at removeChild. – Mocca Apr 06 '10 at 10:14
  • is the fade out occuring? if it is then you are likely trying to remove teh image multiple times, try using if(oldImg && images.contains(oldImg)) – longstaff Apr 06 '10 at 10:49

3 Answers3

0

well, onEnter seems to be an enter frame handler. what you forgot is to remove the listener, once your object is faded out. once alpha is 0, the image is removed. but one frame later, the handler still gets called. now oldImg is no longer a child of images.

edit: maybe you should just use a tween library. Personally, I suggest eaze.

Taryn
  • 242,637
  • 56
  • 362
  • 405
back2dos
  • 15,588
  • 34
  • 50
0

Thanks guys, indeed i have to test for

if ( (oldImg) && images.contains(oldImg) ) 

if i don't use a separate enter_frame event handler for each image object, which i guess is the better solution.

Mocca
  • 1
-1

You never add oldImg to images, thus oldImg is not a child of the caller (images) and cannot be removed from that movieclip. I think this happens the first time EnterFrame is called.

Matti Lyra
  • 12,828
  • 8
  • 49
  • 67
  • `oldImg` was `newImg` (or is `null` which is excluded) und thus has previously been added. – back2dos Apr 06 '10 at 10:43
  • You don't know that without seeing the code above the assignment – Matti Lyra Apr 06 '10 at 10:46
  • based on the assumption that the code posted is all that is relevant and on the OP's description on what he does, I am very certain. It is definitely more likely than the possibilty, that the code that's been edited out, would have side effects that cause "`oldImg` never to be added to `images`". – back2dos Apr 06 '10 at 11:40