Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 02-10-2011, 05:39 PM   #21
Vinyl
Registered User
 
Join Date: Apr 2010
Location: Nantes - France
Posts: 31
Default

Thank you xxneon

The solution you've given me is perfect :

ActionScript Code:
MovieClip(parent.root).doSomething();

In fact, i was really close to the solution but you help me a lot. Thanks !
Vinyl is offline   Reply With Quote
Old 01-05-2013, 08:52 PM   #22
Vinyl
Registered User
 
Join Date: Apr 2010
Location: Nantes - France
Posts: 31
Default call a function isnide a function ?

Hello,

In this post, i've learnt how to call from a child a function inside a parent with :

ActionScript Code:
MovieClip(parent.root).doSomething();

It's perfect.

But, i want to call a function inside an other function.

I'me using ADDED_TO_STAGE in parent swf like this :

ActionScript Code:
start_application(); function start_application():void {        if (stage)     {         initialiser_application();     }     else if (stage == null)     {        addEventListener(Event.ADDED_TO_STAGE, initialiser_application);     } } // Init application function initialiser_application(event : Event = null):void { // function actionUnloadGaleriePhoto(evt:MouseEvent = null):void     {         GaleriePhoto.unload();        } }

I would like to call the function actionUnloadGaleriePhoto (in parent) from the child.

Can you help to do this ? Thanks.
Vinyl is offline   Reply With Quote
Old 01-05-2013, 11:08 PM   #23
[afz]snickelfitz
Senior Member
 
[afz]snickelfitz's Avatar
 
Join Date: Dec 2011
Location: Tucson, AZ
Posts: 2,408
Default

This is a very poor way to structure your code. The parent method call creates a hard-coded dependency between parent and child. This means that if you change the method name or parent>child relationship, the child class will throw an error.

A less egregious way to do this is to dispatch an event from the child. Register for that event in the parent. Any child that dispatches this event can then be removed. No hard-coded links between parent and child are created, and the child remains an autonomous sealed black box.
[afz]snickelfitz is offline   Reply With Quote
Old 01-06-2013, 03:34 AM   #24
henke37
Senior Member
 
henke37's Avatar
 
Join Date: Mar 2009
Location: Sweden
Posts: 10,886
Send a message via Skype™ to henke37
Default

I think that you are too harsh there. A dependency from child to parent isn't the end of the world. It's usually fine.

Using events to hide the dependency is not something I recommend. If you have an event that acts like an order then you have an error in your design. Events should not imply that the listeners must do something specific. That's a poorly disguised function call.
__________________
Signature: I wrote a pair of articles about the timeline.
henke37 is offline   Reply With Quote
Old 01-06-2013, 11:11 AM   #25
Vinyl
Registered User
 
Join Date: Apr 2010
Location: Nantes - France
Posts: 31
Default

Hello,

If you look at my previous post (2-04-2011), first, i've used in the child swf :

ActionScript Code:
dispatchEvent(new Event("actionUnload2", true, true));

and in the parent :

ActionScript Code:
addEventListener("actionUnload2", handleDoSomething); function handleDoSomething(event:Event):void {     loader.unload(); }


But we talk with xxneon and he explained me it was a better solution to use :

ActionScript Code:
MovieClip(stage.getChildAt(0)).doSomething();

or
ActionScript Code:
MovieClip(parent.root).doSomething();

Also, do you know if it's possible to call the function actionUnloadGaleriePhoto() in my code from the child swf ?
Vinyl is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Parent SWF callng a child SWF functions clivegh ActionScript 2.0 1 10-04-2007 07:35 PM
have bright colors of a child clip "poke through" a darkened parent clip jimmi ActionScript 3.0 1 10-01-2007 04:06 AM
a "close" button on child swf bloombloom ActionScript 2.0 0 02-14-2007 01:26 AM
Loading a remote swf into parent, default arraycollection result of httpservice fails jmars Flex 2, 3 & 4 0 02-08-2007 04:00 PM
Parent swf talking to Child swf vasquez888 ActionScript 2.0 12 05-17-2005 05:03 PM


All times are GMT. The time now is 09:12 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.