Need help with AS3 if statement!

HI all, im learning actionscript at the mo and just figured some essential fundamentals movieclip loader etc. However, im having difficulty trying to make this 'if' statement work, when the condition is met it is supposed to trigger a function which makes and already tweening instance do an xscale, however it doesnt seem to want to work when the condition is met (instance getting to a soecified 'y' position, heres my code..
//load mx tween package
import mx.transitions.Tween;
 
//create empty movieclip
var main:MovieClip = this.createEmptyMovieClip("mainholder_mc", 1);
 
 
//attach an 'instance' of 'main_mc' nested in the movieclip 'mainholder_mc' 
main.attachMovie("main_mc", "main_mc", 10);
main.attachMovie("white_mc", "white_mc", 20);
 
 
//set defaults
main.main_mc._y = 0;
main.main_mc._x = -5;
main.main_mc._alpha = 0;
main.white_mc._y = 4;
main.white_mc._xscale = 5;
main.white_mc._x = 80;
main.white_mc._alpha = 0;
 
//white_mc tween function
tweenWhite = function(){
	var twXmoveWhite:Tween = new Tween(main.white_mc, "_xscale", null, 0, 50, 0.5, true);
	}
 
//mx tween class' (to manipulate the instance)
var twYmoveMain:Tween = new Tween(main.main_mc, "_yscale", null, 0, 2850, 1, true);
var twAlphaMain:Tween = new Tween(main.main_mc, "_alpha", null, 0, 100, 1, true);
var twAlphaWhite:Tween = new Tween(main.white_mc, "_alpha", null, 0, 100, 2, true);
var twYmoveWhite:Tween = new Tween(main.white_mc, "_yscale", null, 0, 2190, 1.5, true);
 
//call tweenWhite funtion under a condition
if (main.white_mc._yscale >= 100) {
	tweenWhite();
}
 
end();

Open in new window

LVL 1
aarmstr2Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RobOwner (Aidellio)Commented:
Your 'if' statement will only work if this frame is constantly polled so that when then _yscale reaches a certain point the function will be called

I would use the event onMotionChanged of the Tween Class to monitor this value
//load mx tween package
import mx.transitions.Tween;
 
//create empty movieclip
var main:MovieClip = this.createEmptyMovieClip("mainholder_mc", 1);
 
 
//attach an 'instance' of 'main_mc' nested in the movieclip 'mainholder_mc' 
main.attachMovie("main_mc", "main_mc", 10);
main.attachMovie("white_mc", "white_mc", 20);
 
 
//set defaults
main.main_mc._y = 0;
main.main_mc._x = -5;
main.main_mc._alpha = 0;
main.white_mc._y = 4;
main.white_mc._xscale = 5;
main.white_mc._x = 80;
main.white_mc._alpha = 0;
 
//white_mc tween function
tweenWhite = function(){
        var twXmoveWhite:Tween = new Tween(main.white_mc, "_xscale", null, 0, 50, 0.5, true);
        }
 
//mx tween class' (to manipulate the instance)
var twYmoveMain:Tween = new Tween(main.main_mc, "_yscale", null, 0, 2850, 1, true);
var twAlphaMain:Tween = new Tween(main.main_mc, "_alpha", null, 0, 100, 1, true);
var twAlphaWhite:Tween = new Tween(main.white_mc, "_alpha", null, 0, 100, 2, true);
var twYmoveWhite:Tween = new Tween(main.white_mc, "_yscale", null, 0, 2190, 1.5, true);
 
//call tweenWhite funtion under a condition
var bRunTween:Boolean = true;
twYmoveMain.onMotionChanged = function() {
    if ((main.white_mc._yscale >= 100) && (bRunTween)) {
        bRunTween = false;
        tweenWhite();
    }
}
 
end();

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
aarmstr2Author Commented:
thanks, that works. A couple of questions tho.. the boolean variable, is that declared just so it can be used to balance out the if statement argument? also, the values i declare in the tweens,e.g var twYmoveWhite:Tween = new Tween(main.white_mc, "_yscale", null, 0, 2190, 1.5, true); the 2190 is that supposed to be pixels, because when i use the if statement like this:

if ((main.white_mc._yscale >= 2190) && (bRunTween)) {...........         nothing happens when i use this value, the highest i can go is about 1500, and that doesnt animate to the point of 2190? Any ideas?
0
RobOwner (Aidellio)Commented:
I've used the boolean variable so that the tweenWhite() function is only called once.  As the tween continues the _yscale will still be greater than 100 and you wouldn't want the tweenWhite function called continuously...

though... if you want tweenWhite() to be called when twYmoveMain has finished animating then you can use the onMotionFinished event:

twYmoveMain.onMotionFinished = function() {
        tweenWhite();
}
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

aarmstr2Author Commented:
did know that was available! Thanks, just spotted where i was goin wrong though. Instead of

twYmoveMain.onMotionFinished = function() {
        tweenWhite();
}

it should be

twYmoveWhite.onMotionFinished = function() {
        tweenWhite();
}

Thanks for all your help!!!
0
aarmstr2Author Commented:
to correct myself "i didnt know that was available"
0
RobOwner (Aidellio)Commented:
no problem :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.