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."