Skip to main content
Inspiring
June 26, 2008
Answered

Visible property = true on frame 100

  • June 26, 2008
  • 2 replies
  • 941 views
I have a series of (6) buttons placed directly on the stage that I don't want to see until frame 100, or basically after "100 frames in time" which is when everything on the stage is settled in and done animating. I can't seem to get this seemingly simple task to work. I have an "actions" layer on the first frame with this statement for (1) of the (6) buttons as an example:

btnSoundIsOff.visible = false;

This of course works like a champ, you can't see this button at all. Unfortunately I can't seem to get it to become visible. I tried placing this statement on Frame 100 of the main timeline and realized that it can't possibly work:

btnSoundIsOff.visible = true;

I only have (1) Frame on the main timeline not including a preloader, so of course Frame 100 never gets played. I have also tried adding the visible button statements at frame 100 of my last movie clip animation but then I get run-time errors of undefined this and that. I am not grasping a important fundamental concept of AS3 apparently. I need the buttons to appear after 100 frames and also be able to work. What am I missing? Thank you, I hope I have explained enough of my crisis if not please let me know.




This topic has been closed for replies.
Correct answer Craig Grummitt
Have a look at the Timer class; using it you can request something happen in x milliseconds. this could be sufficient for you.

alternatively, if you have to measure in frames rather than milliseconds, you could set up an ENTER_FRAME event that constantly adds 1 to a variable. when it reaches 100, you could do your button setup.

2 replies

cfordsAuthor
Inspiring
June 27, 2008
The TIMER class was what I needed, thank you. Now my buttons are on the stage but invisible until 3500ms of time from the start of the movie, then they are visible. Here is what I ended up with (modified code example) and of course it works:

<<BEGIN CODE>>

// Import the utils package for the TIMER class
import flash.utils.*; // I have a question about this.

//Turn off button visibility. btnSoundIsOff to stay invisible until
//btnSoundIsOn is clicked on the stage (toggle).

btnSoundIsOff.visible = false;
btnSoundIsOn.visible = false;
btn1.visible = false;
btn2.visible = false;
btn3.visible = false;
btn4.visible = false;
btn5.visible = false;

// Create a new Timer object with a delay of 3500 ms to
// be called once for buttons to appear on the stage.

var buttonTimer:Timer = new Timer(3500, 1);
buttonTimer.addEventListener("timer", buttonsVisible);

// Start the timer

buttonTimer.start();

// Function will be called once to make buttons visible on stage.

function buttonsVisible(eventArgs:TimerEvent)

{
btnSoundIsOn.visible = true;
btn1.visible = true;
btn2.visible = true;
btn3.visible = true;
btn4.visible = true;
btn5.visible = true;
}

<<END CODE>>

I do have another question, tho. I have run into this before and it seems odd to me and worth mentioning. In many of the code examples for AS3 that I have seen it is mentioned that in order to use certain classes, we must import them, such as the call to "import flash.utils.*;" at the start of my code example. I also noticed this when I started futzing with soundchannel and soundtransform. However, I noticed that my code works whether I import them first or not. For example, the following bit of code works perfectly with nothing "imported", at least not by me:

//Add sounds for buttons prior to button creation.
var btnsnd:buttonclick = new buttonclick();
var btnturnsoundon:rooster = new rooster();

//Introduce SoundChannel Controls for Mute Button Toggle.
var trans:SoundTransform = new SoundTransform(0, 0);
//var channel:SoundChannel = btnsnd.play(0, 1, trans); //commented //out for now so sound doesn't play when movie is loaded.
var musicOn:Boolean = true;

So, what exactly is the deal with import? Thank you, but it seems again as if I must be missing something, otherwise 6000 code examples would not have used "import".


Craig Grummitt
Craig GrummittCorrect answer
Inspiring
June 27, 2008
Have a look at the Timer class; using it you can request something happen in x milliseconds. this could be sufficient for you.

alternatively, if you have to measure in frames rather than milliseconds, you could set up an ENTER_FRAME event that constantly adds 1 to a variable. when it reaches 100, you could do your button setup.
cfordsAuthor
Inspiring
June 27, 2008
Thank you, either one of those solutions sounds perfect. I will post the results when I get this working.