View Full Version : accessing events in external swf
miss_satsuma
10-25-2007, 06:29 PM
hello,
i have an swf, a.swf, that is loading b.swf using loadMovie().
I need to know when the user clicks a button in b.swf.
i have tried accessing the events by using addeventlistener, but it doesn't seem to work.
however, i can easily access the properties of movieclips in b.swf, through a.swf.
can anybody shed some light?
thanks,
K
Without seeing specific code and your fla... its hard to tell. Here are a few things to consider:
1) Use the MovieClipLoader class instead of loadMovie. You gain much more control and insight to any loading issues.
2) Understand that the target movieClip is replaced by what you are loading into it (all pre-load methods/properties are wiped out).
3) You cannot access the methods/properties of a loading mc until it has fully loaded. This detection is not possible with loadMovie, but is resolved when using MovieClipLoader....
... check out http://www.actionscript.org/resources/articles/3/1/MovieClipLoaders-Part-1/Page1.html
miss_satsuma
10-25-2007, 08:48 PM
thanks so much for your reply. those articles are so helpful.
The movieclip that is being loaded into the main movieclip has some onclick events (a play and pause button), which work fine when it is loaded into the main swf.
however, i need to know when the user presses the play button in the external swf, so that i can re-define a variable in the main swf.
My question is, is it even possible to access the events of the external movieclip in the main movieclip?
I don't have a problem accessing the properties of various movieClips which are in the external swf, in the main timeline, only the events, such as onPress.
thanks again,
K
miss_satsuma
10-25-2007, 08:51 PM
Here is the main swf code, accessing the loaded movie properties:
loadMovie("my.swf",_root.mcFrame);
var videotime = _root.mcFrame.video.totalTime; //video.totalTime is an FLVPlayback, which is coming from the external movieclip and works fine...shows the total time of the flv
please let me know if this is sufficient.
thanks so much
That should not be a problem... the issue you may have is correct path referencing.
Before setting up a listener, just try hardcoding references both ways:
the following assumes a.swf loads b.swf into holder_mc:
inside a.swf
var trackingVar:Number = 0;
inside b.swf
this.some_mc.onRelease = function(){
this._parent._parent.trackingVar++;
}
Be sure to understand the path referencing. a.swf is the _root mc (unless you set _lockroot = true once you load b.mc... whole other discussion).
So you have the code in a.swf that creates holder_mc and loads b.swf into it. b.swf can now be referenced as holder_mc within a.swf.
Now b.swf has an mc called some_mc. This can be called from within b.swf relatively, or an absolute path of _root.holder_mc.some_mc (I would avoid _root usage especially since you run into path issues like this). You could also use _parent._parent.some_mc to reference the _root.
from within a.swf, the mc within the loaded b.swf would be referenced as
this.holder_mc.some_mc
May appear confusing, but just make sure your paths are correct and you should be fine...
miss_satsuma
10-25-2007, 11:35 PM
Thanks so much for your help.
I tried your solution and unfortunately it does not work :(
It simply does not re-assign the variable when i trace it.
I'm starting to think that it is impossible, although i feel like i'm very close because why is a.swf able to access the properties of mc's and variables in the b.swf?
thanks again,
post both fla's or copies that simulate the problem...
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.