Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

New Here ,
Jun 15, 2017 Jun 15, 2017

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!

TOPICS
ActionScript
917
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jun 15, 2017 Jun 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;

  }

}

Translate
LEGEND ,
Jun 15, 2017 Jun 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;

  }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 15, 2017 Jun 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;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 15, 2017 Jun 15, 2017

Yep this works great, thanks!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 15, 2017 Jun 15, 2017
LATEST

You're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines