Skip to main content
September 25, 2008
Answered

Help! Need help translating AS3 to AS2!

  • September 25, 2008
  • 1 reply
  • 531 views
Good afternoon. I have a very simple roll over animation that I want to use in Captivate 3. However, all of my experience with Flash is with AS3 which is not recognized by C3. Attached is my code snippet for the event that is not being supported. Would anyone be willing to tell me where to start to make this into AS2 (or 1)?

Thank you in advance for any assistance.
This topic has been closed for replies.
Correct answer Newsgroup_User
MrFrankZ,

Here's the code from your first post, and I understand you'd like to
convert it to ActionScript 2.0 (or even 1.0):

>>> gotoAndPlay("notRolled");
>>> rollBox.addEventListener(MouseEvent.MOUSE_OVER, onRoll);
>>>
>>> function onRoll(event:MouseEvent):void
>>> {
>>> gotoAndPlay("rolled");
>>> }
>>> stop();

To that, someone replied this:

>> It's using AS 2. Can you display all of the code?

... which turns out to be incorrect. The code you're showing is indeed AS3.
Telltale signs include the MouseEvent class reference, the MOUSE_OVER event
constant, and the lowercase :void reference.

> The compiler is "The class or interface 'MouseEvent' could not be
> loaded."

That makes sense for a FLA file configured for AS2, because AS2 doesn't
have a MouseEvent class. Fortunately, this is a simple scenario, so let's
break it down.

The first line doesn't change at all:

gotoAndPlay("notRolled");

That does the same thing in either AS2 or AS3; namely, it invokes the
MovieClip.gotoAndPlay() method on a particular MovieClip instance (happens
to be the timeline in which this code appears) and sends that movie clip's
timeline to a frame labeled "notRolled".

Wiring up the event handler is your biggest change. AS2 does support
the addEventListener() method, but only for components. In AS2, there are
(bewilderingly) five different ways to assign event handlers, and the one
that's going to work here -- and feel most this AS3 version -- looks like
this:

rollBox.onRollOver = onRoll;

In principle, it's doing the same thing. I'm assuming rollBox is a
movie clip symbol, so to see what functionality has has available to it,
you'll look up the MovieClip class in the ActionScript 2.0 Language
Reference. When you do, you'll see headings for Properties (characteristics
of the object), Methods (things the object can do), and Events (things the
object can react to). A mouse-over is something the movie clip will react
to, which makes it an event. What I've shown in my sample suggestion is the
MovieClip.onRollOver event, as associated with your rollBox instance.

The syntax is different from AS3, but the basic functionality is the
same: "rollBox, when the mouse rolls over you, perform the onRoll()
function."

And now for that function:

function onRoll():Void {
gotoAndPlay("rolled");
};

Only two small changes: a) drop the event:MouseEvent parameter and b)
change :void to :Void.

Here it is altogether:

// AS2
gotoAndPlay("notRolled");
rollBox.onRollOver = onRoll;
function onRoll():Void {
gotoAndPlay("rolled");
};

And to make this work in AS2, all you have to do is drop the strong
typing (in this case, the :Void):

// AS1
gotoAndPlay("notRolled");
rollBox.onRollOver = onRoll;
function onRoll() {
gotoAndPlay("rolled");
};


David Stiller
Co-author, The ActionScript 3.0 Quick Reference Guide
http://tinyurl.com/2s28a5
"Luck is the residue of good design."


1 reply

September 25, 2008
It's using AS 2. Can you display all of the code?
September 25, 2008
That is the entire code for the action. I have been reading into AS2 to AS3 migration, and unfortunately I have no idea about AS2 to draw my knowledge from. What it is is a simple mouse over animation that goes from frame label "notRolled" to "rolled" after the mouse passes over the defined rollBox. The compiler is "The class or interface 'MouseEvent' could not be loaded."

Does that help any. Thanks in advance.