• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Dispatching and Event in Parent SWF & Receiving it in Child SWF

New Here ,
Jul 17, 2011 Jul 17, 2011

Copy link to clipboard

Copied

Hi All...

      I  would like to receive an event(Dispatchd in Parent swf) in Child SWF,  the bold italic text represents the piece of coding i require help with

     //in PARENT SWF i have -----------------------------

        dispatchEvent(new Event("CloseDoors"))

    // in Child SWF --------------------------------

       here i need a code that catches the event dispatched in parent.addEventListener("closeDoors",closedoor)


       Please let me know if there are alternative ways to do it. I think some  people prefer to listen to the event also in Parent file and run

       the function in CHild from parent file....i would like to learn the  best practive to INFORM CHILDREN through a PARENT FILE...

     Thanks.

TOPICS
ActionScript

Views

449

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 17, 2011 Jul 17, 2011

Copy link to clipboard

Copied

This is not a very good idea to make child listen to events from parent for it is not manageable very well. If there is dependency of child on parent - it is better to create a method in child and call this method from parent on child's instance.

Of course you can do that in the child:

parent.addEventListener("BLAH", handler); but, again, it is not a good approach. methods API is better  (and faster). Events are the best when asynchronous/unpredictable things happen. When you know when things happen - calling methods is more appropriate.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 17, 2011 Jul 17, 2011

Copy link to clipboard

Copied

Thanks....

Could you pls show me in a brief code what does it look like to create a method, i am also searching web regarding API to find out more by myself, I will appreciate an example...a brief code showing examples of Lines i have to write in PARENT file and CHILD....thanks.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 17, 2011 Jul 17, 2011

Copy link to clipboard

Copied

Method is a function. I assume you know how to write functions in AS3...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 17, 2011 Jul 17, 2011

Copy link to clipboard

Copied

LATEST

Perfect....just to make sure i m taking care of it in a nice practical way....here is how i learned to access a file located in Child (researching other posts)

is this the way you recommend it?

(LoaderName.content as MovieClip).functionName(new Event("whatever"))

and in Child File we have

function functionName(e:Event)

i have seen other ways of calling a function in Child Swf , like using EmbedSWF and etc. wanna make sure which one is a better practice. Thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines