aarmstr2
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();
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.onMotionFinish ed = function() {
tweenWhite();
}
though... if you want tweenWhite() to be called when twYmoveMain has finished animating then you can use the onMotionFinished event:
twYmoveMain.onMotionFinish
tweenWhite();
}
ASKER
did know that was available! Thanks, just spotted where i was goin wrong though. Instead of
twYmoveMain.onMotionFinish ed = function() {
tweenWhite();
}
it should be
twYmoveWhite.onMotionFinis hed = function() {
tweenWhite();
}
Thanks for all your help!!!
twYmoveMain.onMotionFinish
tweenWhite();
}
it should be
twYmoveWhite.onMotionFinis
tweenWhite();
}
Thanks for all your help!!!
ASKER
to correct myself "i didnt know that was available"
no problem :)
ASKER
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?