Link to home
Start Free TrialLog in
Avatar of aarmstr2
aarmstr2Flag for United Kingdom of Great Britain and Northern Ireland

asked on

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

ASKER CERTIFIED SOLUTION
Avatar of Rob
Rob
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of aarmstr2

ASKER

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?
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();
}
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!!!
to correct myself "i didnt know that was available"
no problem :)