A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: be sure mc is added to stage before controlling it?

  1. #1
    Senior Member
    Join Date
    Apr 2000
    Location
    Minneapolis
    Posts
    2,127

    be sure mc is added to stage before controlling it?

    Hi,
    if I do this to add a movieclip are there any issues with immediately saying clip.gotoAndPlay(2)?
    could the play be fired before the clip is added fully?
    If so how do you deal with that?
    PHP Code:
        clip MovieClip(sectionArray[nextBanner].content);
        
    banners_mc.removeChildAt(0);
        
    banners_mc.addChild(clip); 
    thanks
    mark

  2. #2
    Total Universe Mod jAQUAN's Avatar
    Join Date
    Jul 2000
    Location
    Honolulu
    Posts
    2,429
    The only real limitations to dealing with descendants of DisplayObject who are not on a display list is dealing with their .stage property since it will be null and changing their depth (swapChildren(), setChildIndex(), etc.). Otherwise timeline control is in tact and the only risk is not seeing some frames while it's being added to the list.

    You can always just listen for the ADDED_TO_STAGE event.

    Actionscript Code:
    clip.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
    function onAddedToStage(e:Event):void{
      clip.removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
      clip.gotoAndPlay(2);
    }

  3. #3
    Senior Member
    Join Date
    Apr 2000
    Location
    Minneapolis
    Posts
    2,127
    thanks that was exactly what I was looking for.

  4. #4
    Senior Member
    Join Date
    Apr 2000
    Location
    Minneapolis
    Posts
    2,127
    I have run into a problem, when I add the added_to_stage function it does not get called? clip is getting added to the stage.
    If I remve the added to stage and use the commented out clip.gotoAndStop(2) in the swapItem function it works.
    PHP Code:
    function swapItem(evt:Event):void {
        
    clip.gotoAndStop(1);//remove old clip
        
    clip.removeEventListener("All Done"swapItem);
       
    banners_mc.removeChildAt(0);
        
    clip MovieClip(sectionArray[nextBanner].content);
        
        
    banners_mc.addChild(clip);
        
    clip.addEventListener(Event.ADDED_TO_STAGEonAddedToStage);
        
    clip.addEventListener("All Done"swapItem);
        
    //clip.gotoAndStop(2);
        
    clearAllButtonStates();    
        if (
    currentBanner sectionArray.length 1) {
            
    currentBanner++;
        } else {
            
    currentBanner 0;
        }
        if (
    nextBanner sectionArray.length 1) {
            
    nextBanner++;
        } else {
            
    nextBanner 0;
        }
        
    numBtnArray[currentBanner].gotoAndStop("Selected");
        
    previousNumBtn numBtnArray[currentBanner];
    }

    function 
    onAddedToStage(e:Event):void{
      
    clip.removeEventListener(Event.ADDED_TO_STAGEonAddedToStage);
      
    clip.gotoAndStop(2);
      
    trace("added to stage");


  5. #5
    Senior Member
    Join Date
    Apr 2000
    Location
    Minneapolis
    Posts
    2,127
    DOH!
    I needed to add the event listener before doing addChild.
    PHP Code:
        clip MovieClip(sectionArray[nextBanner].content);       
        
    clip.addEventListener(Event.ADDED_TO_STAGEonAddedToStage);
        
    banners_mc.addChild(clip); 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center