Home Tutorials Forums Articles Blogs Movies Library Employment Press Buy templates

Go Back   ActionScript.org Forums > Flash General Questions > Flash 9 General Questions

Reply
 
Thread Tools Rate Thread Display Modes
Old 07-29-2007, 12:23 PM   #1
scc
Registered User
 
Join Date: Jul 2007
Posts: 6
Default Actionscript execution order with attachMovie statements

Hi I wonder if anyone's got any decent solutions to this...

Basically whenever I have a script generating an interface by dynamically placing movie clips (using the attachMovie method), I often need the actionscript of the attached movie clip to execute before the rest of the code in the main script continues.

According to normal actionscript execution order, the current script finishes before 1st frame actionscript of any attached movies is executed, so say for example I had the following in frame 1 of my root timeline:

trace("start");
this.attachmovie("myMovieClip","movieClip1",this.g etNextHighestDepth());
trace("end");


and the movie clip in my library with the linkage identifier "myMovieClip" has the following on frame 1 of its timeline:

trace("middle");

Normally this would output:

start
end
middle


However I want it to output:

start
middle
end



The only appropriate way I've found so far to do this is to have a function that is called on completion of the myMovieClip actions, i.e. in the root timeline:

trace("start");
this.attachmovie("myMovieClip","movieClip1",this.g etNextHighestDepth());
movieClip1.onLoaded=function() {
trace("end");
}


and in the timeline of the myMovieClip movie clip:

trace("middle");
this.onLoaded();



But the problem with this is that if I rather than the trace("end"); statement I want a series of other commands, some of them in turn using attachMovie methods, again wanting the scripts to execute in the order above, I'm going to end up with a lot of nested onLoaded functions and it's going to end up looking pretty ugly!


Any thoughts?
scc is offline   Reply With Quote
Old 07-29-2007, 12:57 PM   #2
neilmmm
Senior Member
 
neilmmm's Avatar
 
Join Date: Oct 2005
Location: dorset
Posts: 902
Default

i don't know if this is a good solution but you could do this;
Code:
function secondTrace() {
	trace("middle");
}
function thirdTrace() {
	trace("end");
}
trace("start");
var mc:MovieClip = attachMovie("myMovieClip", "movieClip1", this.getNextHighestDepth());
mc = secondTrace();
mc = thirdTrace();
or just

Code:
trace("start");
var mc:MovieClip = attachMovie("myMovieClip", "movieClip1", this.getNextHighestDepth());
mc = trace("middle");
mc = trace("end");
neilmmm is offline   Reply With Quote
Old 07-29-2007, 03:06 PM   #3
scc
Registered User
 
Join Date: Jul 2007
Posts: 6
Default

The problem is that ideally I want the trace("middle"); function (or whatever it would be replaced with in a more complex scenario) to be part of the movie clip in some way, so that every time that movie clip is created the same actions are performed.

What does the mc = secondTrace(); syntax actually do? I haven't come across that before - I presume it calls the function, does it do it within the scope of mc or something?

I've had the idea of defining a class for the movieclip and storing the relevant actions (i.e. trace("middle");) in the constructor of this class (with the class for the relevant symbol in the library set appropriately in the Linkage options), as these actions are then called when the movie clip is attached rather than on frame 1 of the movie clip, which seems to be producing the desired effect, although I'm still going through my code correcting scopes etc... does this sound like a good idea? Or are there any problems you can think of that might arise from this?
scc is offline   Reply With Quote
Old 08-06-2007, 08:20 AM   #4
noahgenius
Registered User
 
Join Date: Aug 2007
Posts: 4
Default

Quote:
Originally Posted by scc View Post
I've had the idea of defining a class for the movieclip and storing the relevant actions (i.e. trace("middle");) in the constructor of this class (with the class for the relevant symbol in the library set appropriately in the Linkage options), as these actions are then called when the movie clip is attached rather than on frame 1 of the movie clip, which seems to be producing the desired effect, although I'm still going through my code correcting scopes etc... does this sound like a good idea? Or are there any problems you can think of that might arise from this?
yes, and i think it's the only solution to do that because attachMovie is equal to build a mc instance and it will not return until constructor finishes.
If you write codes in mc's timeline, it will run later, maybe according to the priority of thread(maybe run behind flash )
noahgenius 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
focus and tab on Component TextInput & TextArea TylerNZ ActionScript 2.0 6 04-21-2004 03:51 PM
actionscript and order of execution lbower ActionScript 1.0 (and below) 4 10-09-2002 03:48 PM
attachmovie and actionscript on MC's Smirnoff ActionScript 1.0 (and below) 5 09-13-2002 04:46 PM
Inheritance and attachmovie,duplicatemovie ainden ActionScript 1.0 (and below) 3 04-16-2001 08:09 AM


All times are GMT. The time now is 01:03 AM.


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