Skip to main content
Known Participant
March 12, 2011
Answered

Seemingly easy AS2 code that I can't figure out...

  • March 12, 2011
  • 2 replies
  • 662 views

Long story short, I simply want a mc (acting as a button) that when I click it tells a instanced mc to advance a frame, and if I click the button again the instanced mc goes back a frame. Another way to look at it is, click once advance a frame, click again go back a frame. Clicking repeatedly alternates.

Using AS2 I'm a little confused, and I definitely tried to Google this and I ask my friend who's more of a AS3 coder. Originally I put the var function within the event after the on(release) which gave me no errors. My friend says that if the var statement is within the result will always be true.

I will admit that I'm definitely not familiar with conditional statements and this will be my first attempt at doing so. My confusion was how does the button know what true and false is. I was told putting forward=!forward would inherent the switching mechanism based on the active boolean statement.

var forward:Boolean = true;

on(release)

{

   if (forward = true) {

_parent.keyboards.nextFrame();

} else {

_parent.keyboards.prevFrame();

}

forward=!forward

}

This topic has been closed for replies.
Correct answer Ned Murphy

You're welcome.  AS2 can be written in the timeline just like AS3... if some protocol is forcing you to use on() code, whoever defined it needs to get educated.

2 replies

Ned Murphy
Legend
March 12, 2011

Repeating myself...  You should get away from the practice of placing code on() objects and use the timeline

Known Participant
March 13, 2011

Hey Ned,

I'll try to see if those code hints you gave me work when I get to work Monday.

In regards to coding the timeline... as I said before as well... I absolutely agree. When I work on my own stuff (or freelance work) I do everything on frames in AS3. But at my current contract gig I'm just following protocol. I need to tag objects in AS2, unfortunately.

Thanks again for your help.

Known Participant
March 13, 2011

You're welcome.  AS2 can be written in the timeline just like AS3... if some protocol is forcing you to use on() code, whoever defined it needs to get educated.


=) I couldn't agree more and I'm glad someone feels my pain.

Ned Murphy
Legend
March 12, 2011

if (forward = true) {  should be either

if (forward == true) {

OR

if (forward) {