Skip to main content
Inspiring
January 4, 2013
Answered

Can not get rid of xml loaded image scroller when navigate out of the page.

  • January 4, 2013
  • 2 replies
  • 7201 views

I have an xml loaded thumb scroller which stays on the screen when I exit the frames where it exists.

Here is the set up which I have tried to fix this issue. It was suggested that I put an mc on the frames with the image scroller and call it dummy_mc.

Then I put the code on the frames which are not supposed to have thumb scroller:

dummy_mc.visible = false;

function removeScrollerF2(e:Event=null):void{

if(scroller){//prevents a problem if you were to use the same navigation code after the scroller is removed

scroller.removeEventListener(Event.ENTER_FRAME, moveScrollerThumbs);

removeChild(scroller);

scroller=null;  // if, when you want to re-create your scroller, it fails to be re-created, remove this line of code.

}

    trace("dummy2_mc works on null");

}

dummy_mc.addEventListener(Event.REMOVED_FROM_STAGE,removeScrollerF2);

---------------------------------------------------------------------------------------------------------------------------

I have this argument error in the output panel:

ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.

    at flash.display::DisplayObjectContainer/removeChild()

    at acolyte51c_AppsPopUpsThumbs_fla::mainsite_mc_2/removeScrollerF2()[acolyte51c_AppsPopUpsThumbs_fla.mainsite_mc_2::frame73:399]

    at flash.display::MovieClip/gotoAndPlay()

    at acolyte51c_AppsPopUpsThumbs_fla::mainsite_mc_2/gotoFrame2()[acolyte51c_AppsPopUpsThumbs_fla.mainsite_mc_2::frame73:372]

This is the frame73:399
removeChild(scroller);


This topic has been closed for replies.
Correct answer kglad

Forgot about it.

When the site opens and you see how the collage of images animates on the screen into place, please click on any of them. It will bring you to the screen whith the clicked image bigger version and an image thumb scroller at the bottom of the screen. If you click on any of the smaller thumb nails then you are still in the same labeled section and no error happens. If you click on any of the main navigation buttons on top or any of the small products pictures (which light up on roll over) on the right of the large image then you navigate out of this labeled section. This is when the error happens, when a user leaves the labeled section with the xml loaded image thumb scroller. The scroller still stays on the screeen and all the errrors happen.


on mainsite_mc frame 73:

replace line 38:

this.addChild(scroller);

with

dummy_mc.addChild(scroller);

and replace the code from 407+ with:

//dummy_mc.visible = false;  <- remove the graphics from the stage of dummy_mc

dummy_mc.addEventListener(Event.REMOVED_FROM_STAGE,removeScrollerF2);

function removeScrollerF2(e:Event=null):void{

scroller.removeEventListener(Event.ENTER_FRAME, moveScrollerThumbs);

}

2 replies

kglad
Community Expert
Community Expert
January 4, 2013

use:

dummy_mc.visible = false;

function removeScrollerF2(e:Event=null):void{

if(scroller){//prevents a problem if you were to use the same navigation code after the scroller is removed

scroller.removeEventListener(Event.ENTER_FRAME, moveScrollerThumbs);

scroller.parent.removeChild(scroller);

scroller=null;  // if, when you want to re-create your scroller, it fails to be re-created, remove this line of code.

}

    trace("dummy2_mc works on null");

}

dummy_mc.addEventListener(Event.REMOVED_FROM_STAGE,removeScrollerF2);

nikolaigAuthor
Inspiring
January 4, 2013

I still have the same error:

ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.

    at flash.display::DisplayObjectContainer/removeChild()

    at acolyte51c_AppsPopUpsThumbs_fla::mainsite_mc_2/removeScrollerF2()[acolyte51c_AppsPopUpsThumbs_fla.mainsite_mc_2::frame73:404]

    at flash.display::MovieClip/gotoAndPlay()

    at acolyte51c_AppsPopUpsThumbs_fla::mainsite_mc_2/gotoFrame2()[acolyte51c_AppsPopUpsThumbs_fla.mainsite_mc_2::frame73:372]

Line refers to this:
scroller.parent.removeChild(scroller);

I tried adding .parent one at a time and retest but it did not work either. I added up to five instances (scroller.parent.parent.parent.parent.parent.removeChild(scroller);

kglad
Community Expert
Community Expert
January 4, 2013

then scroller is not added to the stage.  use:

if(scroller){//prevents a problem if you were to use the same navigation code after the scroller is removed

if(scroller.stage){

scroller.removeEventListener(Event.ENTER_FRAME, moveScrollerThumbs);

scroller.parent.removeChild(scroller);

scroller=null;  // if, when you want to re-create your scroller, it fails to be re-created, remove this line of code.

}

}

Chipleh
Inspiring
January 4, 2013

You need to reference scroller first, i.e.:

function removeScrollerF2(e:Event=null):void

{

     //I'm guessing your scroller is on the root timeline, else, MovieClip(root) will need to be changed to the instance name of clip where your scroller is located

     var scroller:Object = MovieClip(root).getChildByName("yourScroller'sInstanceName");

     if(scroller){

hth,

~Chipleh

nikolaigAuthor
Inspiring
January 4, 2013

I implemented your code like this:

var scroller:Object = MovieClip(root).getChildByName("thisOne");

I get no more errors, but the scroller is still stays on the screen.

Maybe it helps - here is the code section where I construct the scroller:

//thumb scroller////////////////////////////////////////////////////////////////////////

//load xml

var xmlLoader:URLLoader = new URLLoader();

/////Parse XML

var xmlData:XML = new XML();

var xmlPath:String = "loadingAssets/appThumbnails/slideshow_image_scroller_ActiveTuts_mine/app_thmbs_imgs60x90.xml";

xmlLoader.load(new URLRequest(xmlPath));

xmlLoader.addEventListener(Event.COMPLETE, LoadXML);

function LoadXML(e:Event):void {

    xmlData = new XML(e.target.data);

    buildScroller(xmlData.image); //rather than trace the xmlList, we send it to our buildScroller function

}

/////Build Scroller MovieClip to Contain Each Image

var scroller:MovieClip = new MovieClip();

var padding:Number = 5;//creating a var for padding to be used later on in easier calculations

//making the mask+boundaries

scroller.mask = maskRctngl;

var maskBorders:Number = 93;// distance from stage borders 88 px + padding 5 px

this.addChild(scroller);

scroller.y = 645;

scroller.x = maskBorders;

var thumbSmall:Number = 1;//setting up scale Tween on rollover

var thumbLarge:Number = 1.05;//setting up scale Tween on rollover

/////

/////Parse XML

//build scroller from xml

function buildScroller(imageList:XMLList):void{

   

    for (var item:uint = 0; item<imageList.length();item++) {

        var thisOne:MovieClip = new MovieClip();

       

       

        //outline

        var thumbFadeOut:Number = .3;//setting Border Tweens//doesn't work with TweenMax transitions

        var thumbFadeIn:Number = .7;//setting Border Tweens//doesn't work with TweenMax transitions

       

        var blackBox:Sprite = new Sprite();

        blackBox.graphics.beginFill(0xFFFFFF);

        blackBox.graphics.drawRect(-1, -1, 62, 92);

        blackBox.alpha = thumbFadeOut;//setting Border Tweens

        thisOne.addChild(blackBox);

        thisOne.blackBox = blackBox;//setting Border Tweens

       

       

        thisOne.x = thisOne.myx = (60 + padding) *item;

        thisOne.itemNum = item;

        thisOne.title = imageList[item].attribute("title");

        thisOne.link = imageList[item].attribute("url");

        thisOne.src = imageList[item].attribute("src");

        thisOne.alpha = 0;//makes all thumb images at alpha=0 before they are fully loaded

       

        //Loading and Adding the Images

        //image container

        var thisThumb:MovieClip = new MovieClip();

        //add image

        var ldr:Loader = new Loader();

        var urlReq:URLRequest = new URLRequest(thisOne.src);

        ldr.load(urlReq);

        //assign event listeners for Loader

        ldr.contentLoaderInfo.addEventListener(Event.COMPLETE,completeHandler_AppPopUps);//tells us when the loading is complete

        ldr.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, errorHandler_AppPopUps);//tells us if there are any typo errors when the loading is complete

        thisThumb.addChild(ldr);

        thisOne.addChild(thisThumb);

       

        //create listeners for this thumb

        thisOne.buttonMode = true;//makes boxes act as buttons

        thisOne.addEventListener(MouseEvent.CLICK, clickScrollerItem_AppPopUps);//makes boxes act as buttons

        thisOne.addEventListener(MouseEvent.MOUSE_OVER, overScrollerItem_AppPopUps);//traces the title when the mouse is over the bounding box in the Output Panel

        thisOne.addEventListener(MouseEvent.MOUSE_OUT, outScrollerItem_AppPopUps);//traces the title when the mouse is out the bounding box in the Output Panel

       

        //add item

        scroller.addChild(thisOne);

    }

    scroller.addEventListener(Event.ENTER_FRAME, moveScrollerThumbs);//adding movement on mouse position

   

}

Chipleh
Inspiring
January 4, 2013

//This will add the scroller to the root timeline

addChild(scroller);

//This will give the scroller an instance name of 'theScroller'

scroller.name = "theScroller"

//This will remove the instance of scroller

var scroller:Object = MovieClip(root).getChildByName('theScroller");

if(scroller)

{

     removeChild(scroller)

}