Skip to main content
Keithito15
Participant
June 15, 2017
Answered

Change the opacity of an instance when a dynamic text field reaches a certain value

  • June 15, 2017
  • 3 replies
  • 965 views

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!

This topic has been closed for replies.
Correct answer robdillon

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;

  }

}

3 replies

Keithito15
Participant
June 15, 2017

Yep this works great, thanks!

robdillon
Participating Frequently
June 15, 2017

You're welcome.

Colin Holgate
Inspiring
June 15, 2017

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;

}

robdillon
robdillonCorrect answer
Participating Frequently
June 15, 2017

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;

  }

}