Copy link to clipboard
Copied
Hey there, I'm pretty new to AS3 but I'm trying to get a small action to work as a test case for a project at work. Basically there will be a dynamic text field that is counting up from 0 to 999 (call it dtext_1), when dtext_1 hits a certain value (999) I want to make another instance (unlocked_mc) visible. I was thinking that I could start unlocked_mc at alpha 0 and switch it to 1 when the number is hit? I'm just not sure how to go about it exactly.
So : I'm basically trying to transpose "when dtext_1 >= 999, unlocked_mc.alpha = 1" into something useable in AS3. Any suggestions?
Thanks!
You can use the function that is updating your text. Something like this:
import flash.events.Event;
stop();
unlocked_mc.alpha = 0;
var myNumber:Number = 0;
dText_1.addEventListener(Event.ENTER_FRAME,addUp);
function addUp(event:Event):void {
myNumber ++;
dText_1.text = myNumber.toString();
if(myNumber > 999) {
unlocked_mc.alpha = 1;
}
}
Copy link to clipboard
Copied
You can use the function that is updating your text. Something like this:
import flash.events.Event;
stop();
unlocked_mc.alpha = 0;
var myNumber:Number = 0;
dText_1.addEventListener(Event.ENTER_FRAME,addUp);
function addUp(event:Event):void {
myNumber ++;
dText_1.text = myNumber.toString();
if(myNumber > 999) {
unlocked_mc.alpha = 1;
}
}
Copy link to clipboard
Copied
Presumably there is a variable that is counting up, that you then put into the text field? Like this at the start:
var counter:int = 0;
unlocked_mc.alpha = 0;
and this each time it increases:
counter++;
dtext_1.text = counter;
If that's the case you could check the value of the counter each time it's increased:
counter++;
if(counter>=999){
unlocked_mc.alpha = 1;
}
Copy link to clipboard
Copied
Yep this works great, thanks!
Copy link to clipboard
Copied
You're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now