Groups | Blog | Home
all groups > flash actionscript > october 2007 >

flash actionscript : Running AFTER a function's been executed?



Mr. Aztek
10/2/2007 11:01:54 PM
Below is the current code I'm using. It works fine and does what I need it to
do, no problems.

However, I'd previously tried to use a conditional statement to have the last
two tweens (3x and 4y) to wait until all the previous ones had finished, and
have been unsuccessful and been getting a syntax error for onLoad. I don't know
how adding a boolean conditional statement (i.e. dLaunchDone = true) gave me a
syntax error for onLoad, but it did. Could be my computer's acting funny, but
that's wishful thinking.

I'll be okay if it can't be done, just wondering how I get a function to wait
until another has been completely executed before running as well.

stop();
//importing tweens
import mx.transitions.Tween;
import mx.transitions.easing.*;

//setting Title to 0 transparency
mcTitle._alpha = 0;

//functions
//slides title down and fades it in
function Launch ():Void
{
//slides title down
var tween1y:Tween = new Tween(this.mcTitle, "_y", Regular.easeOut, this._y,
10, 30, false);
//fades title in
var mcAlpha1:Tween = new Tween(this.mcTitle, "_alpha", Regular.easeOut, 0,
100, 50, false);
//slides blue tab up
var tween2y:Tween = new Tween(this.mcBlueTab, "_Y", Regular.easeOut, 613.0,
135.1, 70, false);
//slides black tab left
var tween1x:Tween = new Tween(this.mcBlackTab, "_x", Regular.easeOut, 551.0,
91.1, 70, false);
//scale the table X
var tween2x:Tween = new Tween(this.mcTable, "_xscale", Regular.easeOut, 0,
100, 70, false);
//scale the table Y
var tween3y:Tween = new Tween(this.mcTable, "_yscale", Regular.easeOut, 0,
100,70, false);
//slide H Grid left
var tween3x:Tween = new Tween(this.mcHGrid, "_x", Regular.easeOut, 629, 90,
70, false);
//slide V Grid down
var tween4y:Tween = new Tween(this.mcVGrid, "_y", Regular.easeOut, -372.1,
134.1, 70, false);
}

//execute on load
onLoad = Launch;
kglad
10/2/2007 11:10:54 PM
use an onMotionFinished method for each tween that you want to complete before
starting your 3x and 4y tweens. in each method you can assign true to a
variable and then call a function to check if all variables have been assigned
true.
Mr. Aztek
10/3/2007 3:52:17 PM
Hey KG,

Thanks for the assist. I tried doing what you suggested, but I think my newbie
ineptitude is working against me here. Attached is what I've gotten down (we've
done away witht he fade in and I now need this to advance to the next frame
after all the tweens have finished), but I don't quite have it right yet...

stop();
//importing tweens
import mx.transitions.Tween;
import mx.transitions.easing.*;

//variables
//var dDone:Boolean = false;
var dOne:Boolean = false;
var dTwo:Boolean = false;
var dThree:Boolean = false;
var dFour:Boolean = false;
var dFive:Boolean = false;
var dSix:Boolean = false;
var dSeven:Boolean = false;
var dEight:Boolean = false;

//setting 0 transparency
mcTitle._alpha = 0;
mcBlackHeader._alpha = 0;
mcBlueHeader._alpha = 0;

//slides title down and fades it in
function Launch ():Void
{
//slides title down
var tween1y:Tween = new Tween(this.mcTitle, "_y", Regular.easeOut, this._y,
10, 30, false);
tween1y.onMotionFinished = function():Void
{
dOne=true;
};
//fades title in
var mcAlpha1:Tween = new Tween(this.mcTitle, "_alpha", Regular.easeOut, 0,
100, 50, false);
mcAlpha1.onMotionFinished = function():Void
{
dTwo=true;
};
//slides blue tab up
var tween2y:Tween = new Tween(this.mcBlueTab, "_Y", Regular.easeOut, 613.0,
135.1, 70, false);
tween2y.onMotionFinished = function():Void
{
dThree=true;
};
//slides black tab left
var tween1x:Tween = new Tween(this.mcBlackTab, "_x", Regular.easeOut, 551.0,
91.1, 70, false);
tween1x.onMotionFinished = function():Void
{
dFour=true;
};
//scale the table X
var tween2x:Tween = new Tween(this.mcTable, "_xscale", Regular.easeOut, 0,
100, 70, false);
tween2x.onMotionFinished = function():Void
{
dFive=true;
};
//scale the table Y
var tween3y:Tween = new Tween(this.mcTable, "_yscale", Regular.easeOut, 0,
100,70, false);
tween3y.onMotionFinished = function():Void
{
dSix=true;
};
//slide H Grid left
var tween3x:Tween = new Tween(this.mcHGrid, "_x", Regular.easeOut, 629, 90,
70, false);
tween3x.onMotionFinished = function():Void
{
dSeven=true;
};
//slide V Grid down
var tween4y:Tween = new Tween(this.mcVGrid, "_y", Regular.easeOut, -372.1,
134.1, 70, false);
tween4y.onMotionFinished = function():Void
{
dEight=true;
};
};

if (dOne == true && dTwo == true && dThree == true && dFour == true && dFive
== true && dSix == true && dSeven == true && dEight == true)
{
gotoAndStop(2);
}

//execute on load
onLoad = Launch;
clbeech
10/3/2007 4:23:04 PM
Hey MrA! how about making the tweens progressive until the process is
complete, like:


function Launch ():Void {
var tween1y:Tween = new Tween(this.mcTitle, "_y", Regular.easeOut, this._y,
10, 30, false);
tween1.onMotionFinished = function() {
var tween2y:Tween = new Tween(this.mcBlueTab, "_Y", Regular.easeOut,
613.0, 135.1, 70, false);
tween2.onMotionFinished = function() {
var tween1x:Tween = new Tween(this.mcBlackTab, "_x", Regular.easeOut,
551.0, 91.1, 70, false);
tween1x.onMotionFinished = function() {
var tween2x:Tween = new Tween(this.mcTable, "_xscale",
Regular.easeOut, 0, 100, 70, false);
var tween3y:Tween = new Tween(this.mcTable, "_yscale",
Regular.easeOut, 0, 100,70, false);
tween3y.onMotionFinished = function() {
var tween3x:Tween = new Tween(this.mcHGrid, "_x", Regular.easeOut,
629, 90, 70, false);
var tween4y:Tween = new Tween(this.mcVGrid, "_y", Regular.easeOut,
-372.1, 134.1, 70, false);
tween4y.onMotionFinished = function() {
gotoAndStop(2);
}
}
}
}
}
}
Mr. Aztek
10/3/2007 4:51:35 PM
Hey CLB,

I tried your approach but now all I get is a blank stage..ack!

stop();
//importing tweens
import mx.transitions.Tween;
import mx.transitions.easing.*;

//setting 0 transparency
mcTitle._alpha = 0;

//slides title down and fades it in
function Launch ():Void {
var tween1y:Tween = new Tween(this.mcTitle, "_y", Regular.easeOut, this._y,
10, 30, false);
tween1.onMotionFinished = function() {
var tween2y:Tween = new Tween(this.mcBlueTab, "_Y", Regular.easeOut,
613.0, 135.1, 70, false);
tween2.onMotionFinished = function() {
var tween1x:Tween = new Tween(this.mcBlackTab, "_x", Regular.easeOut,
551.0, 91.1, 70, false);
tween1x.onMotionFinished = function() {
var tween2x:Tween = new Tween(this.mcTable, "_xscale",
Regular.easeOut, 0, 100, 70, false);
var tween3y:Tween = new Tween(this.mcTable, "_yscale",
Regular.easeOut, 0, 100,70, false);
tween3y.onMotionFinished = function() {
var tween3x:Tween = new Tween(this.mcHGrid, "_x", Regular.easeOut,
629, 90, 70, false);
var tween4y:Tween = new Tween(this.mcVGrid, "_y", Regular.easeOut,
-372.1, 134.1, 70, false);
tween4y.onMotionFinished = function() {
gotoAndStop(2);
};
};
};
};
};
};

//execute on load
onLoad = Launch;
clbeech
10/3/2007 4:54:22 PM
Mr. Aztek
10/3/2007 5:22:50 PM
Mr. Aztek
10/3/2007 5:37:03 PM
Oo oo... I think I got it, but (typos just before the first two
onMotionFinished)...now mcTitle won't appear....D'oh! I swear if it's not one
thing, it's another...

stop();
//importing tweens
import mx.transitions.Tween;
import mx.transitions.easing.*;

//setting 0 transparency
mcTitle._alpha = 0;

//slides title down and fades it in
function Launch ():Void {
var tween1y:Tween = new Tween(mcTitle, "_y", Regular.easeOut, -70.0, 10, 30,
false);
tween1y.onMotionFinished = function() {
var tween2y:Tween = new Tween(mcBlueTab, "_Y", Regular.easeOut, 613.0,
135.1, 70, false);
tween2y.onMotionFinished = function() {
var tween1x:Tween = new Tween(mcBlackTab, "_x", Regular.easeOut, 551.0,
91.1, 70, false);
tween1x.onMotionFinished = function() {
var tween2x:Tween = new Tween(mcTable, "_xscale", Regular.easeOut, 0,
100, 70, false);
var tween3y:Tween = new Tween(mcTable, "_yscale", Regular.easeOut, 0,
100,70, false);
tween3y.onMotionFinished = function() {
var tween3x:Tween = new Tween(mcHGrid, "_x", Regular.easeOut, 629,
90, 70, false);
var tween4y:Tween = new Tween(mcVGrid, "_y", Regular.easeOut,
-372.1, 134.1, 70, false);
tween4y.onMotionFinished = function() {
gotoAndStop(2);
}
}
}
}
}
}

//execute on load
onLoad = Launch;
Mr. Aztek
10/3/2007 9:35:07 PM
Grr.

Okay so I probably should have been more specific. All of this is contained
within a movie clip ("mcPMCV"). What I want is that when the instance is placed
on frame 3 of the main timeline, the functions should execute. After they have
all executed, it should advance the main timeline to frame 4. Despite my best
efforts such as changing the tween paths, onLoad attempts (when I tell it to go
to Frame 2 of mcPMCV it works fine, but when it goes to frame 1 on mcPMCV,
nothing happens), and swapping out the functions into the main timeline, it
just is not executing. I'm hoping there's still a solution here, otherwise I'll
just make this movie clip it's own SFW that gets called into the stage on a
different level to save myself any further headaches.
clbeech
10/3/2007 10:10:34 PM
Sorry I've been out for a while :) glad you got the tweens cleared up.

well, it should just be a path issue, try calling:

Mr. Aztek
10/4/2007 2:25:51 PM
OKay I've moved everything off the movie clip and onto the main timeline (which
I should have done in the first place). I've made one change to the code but
now it's only performing 10% of each tween before executing the next one. What
did I do wrong?

stop();
//importing tweens
import mx.transitions.Tween;
import mx.transitions.easing.*;

//slides each mc in sequence
function Launch ():Void {
var tween1y:Tween = new Tween(mcTitle, "_y", Regular.easeOut, -70, 10, 30,
false);
tween1y.onMotionFinished = function() {
var tween2y:Tween = new Tween(mcBlueTab, "_Y", Regular.easeOut, 551, 135,
70, false);
tween2y.onMotionFinished = function() {
var tween1x:Tween = new Tween(mcBlackTab, "_x", Regular.easeOut, 613,
91, 70, false);
tween1x.onMotionFinished = function() {
var tween2x:Tween = new Tween(mcTable, "_xscale", Regular.easeOut, 0,
100, 70, false);
var tween3y:Tween = new Tween(mcTable, "_yscale", Regular.easeOut, 0,
100, 70, false);
tween3y.onMotionFinished = function() {
var tween3x:Tween = new Tween(mcHGrid, "_x", Regular.easeOut, 652,
90, 70, false);
var tween4y:Tween = new Tween(mcVGrid, "_y", Regular.easeOut, -450,
136, 70, false);
tween4y.onMotionFinished = function() {
gotoAndStop(4);
}
}
}
}
}
}

//execute on Entering this frame (3)
onEnterFrame = Launch;
clbeech
10/4/2007 2:40:44 PM
OH!!! I see what's happening, you're using an 'onEnterFrame' event, this would be restarting the function at 30fps!!! Just call the Launch function once!

Mr. Aztek
10/4/2007 3:06:04 PM
{smacks forehead}

Oy.

clbeech
10/4/2007 3:16:15 PM
AddThis Social Bookmark Button