all groups > flash actionscript > june 2006 >
You're in the

flash actionscript

group:

Passing variables between loaded clips


Re: Passing variables between loaded clips Motion Maker
6/6/2006 3:19:28 PM
flash actionscript:
Not reliable to set variables in an external swf using loadMovie. The
problem is that the load timing is dependent on the network and not the
script. The loadMovie line does not pause the script until the external swf
is loaded. Thus the next line looking for the external swf can and probably
does execute before the movie is loaded.

You want to look at MovieClipLoader Actionscript class as a technique for
detecting when an external movie is loaded and ready for Actionscript.

An overview appears at
http://livedocs.macromedia.com/flash/8/main/00002538.html

Probably the example for onLoadComplete is a good place to start:
http://livedocs.macromedia.com/flash/8/main/00002543.html

However if you want to start using before the entire movie is loaded, you
can look ot onLoadInit also shown in the onLoadComplete example.

In the onLoadComplete method you can have targe_mc.thisVar = 1;

There are also other customized techniques using onEnterFrame and
setInterval to monitor the presence of a loaded external swf that you can
pursue.

--
Lon Hosford
www.lonhosford.com
Flash, Actionscript and Flash Media Server examples:
http://flashexamples.hosfordusa.com
May many happy bits flow your way!
[quoted text, click to view]
So i have one main swf, that dynamically loads in several copies of another
swf.

Within the Child movie there are buttons that call out to the HTML to
various
JavaScript functions, I need each instanct of the Child movie to have a
unique
ID variable set by the container film..

Can someone show me a working version of the following as I cannot find
anything that can pass a variable to the child.


_root.createEmptyMovieClip("child1",1);
loadMovie("child.swf","child1");
child1.thisVar = 1;

_root.createEmptyMovieClip("child2",2);
loadMovie("child.swf","child2");
child2.thisVar = 2;

Passing variables between loaded clips g1r2e3g
6/6/2006 6:53:25 PM
So i have one main swf, that dynamically loads in several copies of another swf.

Within the Child movie there are buttons that call out to the HTML to various
JavaScript functions, I need each instanct of the Child movie to have a unique
ID variable set by the container film..

Can someone show me a working version of the following as I cannot find
anything that can pass a variable to the child.


_root.createEmptyMovieClip("child1",1);
loadMovie("child.swf","child1");
child1.thisVar = 1;

_root.createEmptyMovieClip("child2",2);
loadMovie("child.swf","child2");
child2.thisVar = 2;
Re: Passing variables between loaded clips g1r2e3g
6/6/2006 7:13:07 PM
maybe i didnt write that properly... what I mean is...

Re: Passing variables between loaded clips Rothrock
6/6/2006 7:20:42 PM
Most likely your problem is that you aren't waiting until "child.swf" has
finished loading into child1. Any properties, code, variables attached to
child1 will be replaced once the external file loads completely.

You need a preloader to wait until the clip is completely loaded and then
assign your ID. If you need help with that we can work it out.

If you are publishing for Flash 7 or higher, I recommend using the
MovieClipLoader class. You could then use the onLoadInit event to assign your
ID.

Of course I'm not understanding the need for a unique ID. If they all have
unique names, e.g. child1, child2, etc., then that could be your unique ID.
Just a thought!

(PS why call it thisVar ? a combination of two reserved words which is likely
to cause confusion ? when myID seems so much more sensible.)
Re: Passing variables between loaded clips g1r2e3g
6/6/2006 8:28:28 PM
I am pubilshing for flash 6. Also my variable wasn't actually caled thisVar,
sorry about that. Also, calling it a unique ID may not have made sense..

basically the child movie is a set of 24 buttons that represent time values (1
hour blocks) over a 24 hour period. This movie as I said is repeated many time
as each new instance represents different activities that the user needs to
specify as completed over the 24 hours.

The flash is actually a replacement for an existing HTML form and for
financial reasons the HTML is not being replaced completely by flash, therefore
instead of the flash talking directly with the database via ASP or some other
method I have it calling out to javascript functions that manipulate the HTML
form which is now hidden with CSS.

So in the child movie each of the buttons calls

getURL("javascript:setCheckbox(" + _root.activityID + ",1);doSave();");

How can I set the value activityID within each instance of the movie?


AddThis Social Bookmark Button