Skip to main content
Inspiring
January 22, 2013
解決済み

How do I remove eventListener on the main time line out of the loaded SWF?

  • January 22, 2013
  • 返信数 1.
  • 1294 ビュー

I have a set up where my main time line is keyframed out into labeled sections. In one of the labeled sections I load and SWF file using greensock SWF Loader. In the loaded SWF there is a command where I need to remove/addEventListeners on the main timeline of the flash file out of the loaded SWF.

The set up with "MovieClip(parent.parent.parent.parent)." works for navigation and loading and all other functions. However I get the error "1120: Access of unidetified property" if I want to use a line of code such as this:

                    //MovieClip(parent.parent.parent.parent).mainNav_buttonsGroup_mc.Applications_btn_mc.removeEventListener(MouseEvent.ROLL_OVER, overHandler_Applications_btn);

Do I need to simply write up this EventListeners again in the loading SWF file (thus repeating them again as they are specified on the main time line already) or there is a better method to it?

appImgBtns_mc.testBtns2_mc.addEventListener(MouseEvent.CLICK, onClick_testBtns2);

function onClick_testBtns2(event:MouseEvent) :void {

          /////////

                    ////disabling the button onClick by removeEventListener

                    //MovieClip(parent.parent.parent.parent).mainNav_buttonsGroup_mc.Applications_btn_mc.removeEventListener(MouseEvent.ROLL_OVER, overHandler_Applications_btn);

                    //MovieClip(parent.parent.parent.parent).mainNav_buttonsGroup_mc.Applications_btn_mc.removeEventListener(MouseEvent.ROLL_OUT, outHandler_Applications_btn);

                        //MovieClip(parent.parent.parent.parent).mainNav_buttonsGroup_mc.Applications_btn_mc.removeEventListener(MouseEvent.CLICK, onClick_Applications_btn);

                    ////coloring the button

        MovieClip(parent.parent.parent.parent).Applications_btn_timeLine.play();

 

                    //Products_btn_mc

                    //MovieClip(parent.parent.parent.parent).mainNav_buttonsGroup_mc.Products_btn_mc.addEventListener(MouseEvent.ROLL_OVER, overHandler_Products_btn);

                    //MovieClip(parent.parent.parent.parent).mainNav_buttonsGroup_mc.Products_btn_mc.addEventListener(MouseEvent.ROLL_OUT, outHandler_Products_btn);

                    //MovieClip(parent.parent.parent.parent).mainNav_buttonsGroup_mc.Products_btn_mc.addEventListener(MouseEvent.CLICK, onClick_Products_btn);

                    //discoloring the button

        MovieClip(parent.parent.parent.parent).Products_btn_timeLine.reverse();

 

 

          MovieClip(parent.parent.parent.parent).sourceVar_AppPopUpsLoader_fromPrdcts="images/app_images/original/icysophistication_new_tl.swf";

          MovieClip(parent.parent.parent.parent).gotoAndPlay("appPopUps_fromPrdcts");

}

このトピックへの返信は締め切られました。
解決に役立った回答 Chipleh

You can communicate with the Main timeline by dispatching events from the child swf.

When the child Swf is loaded, dispatch an event, i.e. - dispatchEvent(new Event("DoTimeLineCode"));

Then on your main timeline, listen for the event and execute the functions you want:

MovieClip(root).addEventListener("DoTimeLineCode", mainTimeLineFunctions);

function mainTimeLineFunctions(e:Event):void

{

     MovieClip(root).Applications_btn_timeLine.play();

           //etc...

}

Chasing down MovieClip(parent.parent.parent.parent) has always been a losing battle for me. It's best practice to use event dispatchers and listeners to instantiate "things" from the parent child paradigm.

~Chipleh

返信数 1

Chipleh
Chipleh解決!
Inspiring
January 22, 2013

You can communicate with the Main timeline by dispatching events from the child swf.

When the child Swf is loaded, dispatch an event, i.e. - dispatchEvent(new Event("DoTimeLineCode"));

Then on your main timeline, listen for the event and execute the functions you want:

MovieClip(root).addEventListener("DoTimeLineCode", mainTimeLineFunctions);

function mainTimeLineFunctions(e:Event):void

{

     MovieClip(root).Applications_btn_timeLine.play();

           //etc...

}

Chasing down MovieClip(parent.parent.parent.parent) has always been a losing battle for me. It's best practice to use event dispatchers and listeners to instantiate "things" from the parent child paradigm.

~Chipleh

nikolaig作成者
Inspiring
January 22, 2013

Thanks, that seems to work. I dont seem to be able to get to the MovieClip(root)

Maybe you can glance at my code and suggest how it has to be specified.

Here is how SWF is being loaded onto the stage. I am using greensock.com SWF loader

var sourceVar_ProductsPopUps:String;//has to be specified only once for the rest of all the buttons so individual SWFs may be loaded into LoaderMax or UILoader

var loaderProductPopUps:SWFLoader;

loaderProductPopUps = new SWFLoader(sourceVar_ProductsPopUps, //the value of sourceVar_ProductsPopUps allows to load mulitple SWFs from the products page.

                                                                                                    { container:holderMovieClip,

"holderMovieClip" is where the SWF loader is placed.

Here is my code from the main time line:

MovieClip(holderMovieClip).addEventListener("DoTimeLineCode", mainTimeLineFunctions);

function mainTimeLineFunctions(e:Event):void{

     MovieClip(holderMovieClip).Applications_btn_timeLine2.play();

}

Chipleh
Inspiring
January 22, 2013

This will work:

MovieClip(root).holderMovieClip.addEventListener("DoTimeLineCode", mainTimeLineFunctions);

Another option:

If you want to directly reference the actual Movie Clip, something like this will work:

var holderClip:DisplayObject = MovieClip(root).getChildByName("holderMovieClip");//assumes there is a Movie Clip on your stage named "holderMovieClip"

if(holderClip != null)//verify it exists and if it does. add the listener

{

     holderClip.addEventListener("DoTimeLineCode", mainTimeLineFunctions);

}

Either one of these should "make it go"

Hope that helps,

~Chipleh