Skip navigation
Currently Being Moderated

Timer to alternately show/hide 2 objects

May 6, 2012 5:35 AM

Hi,

 

I'm trying to learn how to use a Timer and AS3 to set up 2 objects (for example, 2 squares, each with a separate instance name) that would show/hide alternately for 500 ms each for 30 seconds (30000 ms) total. Easy enough to do using a timeline, but instead, I need to set this up to include using AS3 to add to a companion .as script file (Main.as), which loads and all runs on Frame 1. I first looked at using setTimeout or setInterval, but these don't seem to have enough properties to do what is needed. So, Timer is probably the best choice. I've read the online documents and examples for a Timer, but still can't figure out how for example to alternate one object's 500 ms show with the other's 500 ms hide, then alternate/switch them, and stop the alternating sequence after 30 seconds.

 

Any help, example AS3 script would be great help.

 

Regards,

 
Replies
  • Currently Being Moderated
    May 6, 2012 6:11 AM   in reply to saratogacoach

    To control showing and hiding just use the visible properties of your objects, setting one to be the opposite of the other.  As far as controlling the timing goes, study/experiment with the Timer to see how you can set the delay and the repeat count to meet your needs

     
    |
    Mark as:
  • Currently Being Moderated
    May 6, 2012 8:16 AM   in reply to saratogacoach

    Yeah, it looks like you are over-thinking it.  One timer should be all you need. 

     

    The problem with giving you a simple example is that the simplest example is the solution to what you say you are trying to learn how to do.  Doing it for you is not you learning how.

     

    As I said, you just need to make the one object's visible property the oppostite of what the other is each time you change the other...

     

    mcsquare1.visible = !mcsquare1.visible;    // switches the visible state to the opposite

    mcsquare2.visible = !mcsquare1.visible;    // ditto

     
    |
    Mark as:
  • Currently Being Moderated
    May 6, 2012 9:04 AM   in reply to saratogacoach

    You need to reread my reply.

     
    |
    Mark as:
  • Currently Being Moderated
    May 6, 2012 10:33 AM   in reply to saratogacoach

    Use the button to start the timer.

     
    |
    Mark as:
  • Currently Being Moderated
    May 6, 2012 2:05 PM   in reply to saratogacoach

    You're welcome ( looks like they are literally "messing" around with the forums )

     
    |
    Mark as:
  • Currently Being Moderated
    May 7, 2012 8:58 AM   in reply to saratogacoach

    Thanks a ton for the posting's on this. Fishing through all the random link's on the Google's, Yahoo's, Bing's, etc's... Of the world was killing me. Now I know... And if I can remember correctly... Knowing is half the battle

     

    Thanks again!

     

    B

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points