probably really simple q, but this is my first day in actionscript territory.
I want to define functions to move a movie clip around the stage, my code works when i define it STRAIGHT to the movie, but when i define it as functions it doesn’t.
onClipEvent(enterFrame) {
if (this._x<=253.2) {
this._x += _global.movespeed; }
if (this._alpha<=100) {
this._alpha += _global.fadespeed; }
if (this._rotation<=45) {
this._rotation += _global.movespeed; }
if (this._y<=178.2) {
this._y += _global.movespeed; }
}
but when i put this into actions, i did it like this. i tried splitting it into 2 since 1 didn’t work.
function loadme () {
this._x = 0
this._y = 0
this._alpha = 0
this._rotation = 0
}
function move () {
if (this._x<=253.2) {
this._x += _global.movespeed; }
if (this._alpha<=100) {
this._alpha += _global.fadespeed; }
if (this._rotation<=45) {
this._rotation += _global.movespeed; }
if (this._y<=178.2) {
this._y += _global.movespeed; }
}
then assigned this code to the movie
onClipEvent (load) {
box.loadme();
}
onClipEvent (enterFrame) {
box.move();
}
and that doesn’t work.
I have no experience in coding so forgive me if this is obvious.
Well you are going about the _global thing all wrong.
_lobal is like this like this (taken from Macromedias reference)…
_global
Availability
Flash Player 6.
Usage
_global.identifier
Parameters
None.
Returns
A reference to the global object that holds the core ActionScript classes, such as String, Object, Math, and Array.
Description
Identifier; creates global variables, objects, or classes. For example, you could create a library that is exposed as a global ActionScript object, much like the Math or Date object. Unlike Timeline-declared or locally-declared variables and functions, global variables and functions are visible to every Timeline and scope in the Flash movie, provided they are not obscured by identifiers with the same names in inner scopes.
Example
The following example creates a top-level function factorial that is available to every Timeline and scope in a Flash movie:
_global.factorial = function (n) {
if (n <= 1) {
return 1;
} else {
return n * factorial(n-1);
}
}
Do define a variable you don’t need _global there.
Just have it as
fadespeed = 15
then call it like this
if (this._alpha<=100) {
this._alpha += _root.fadespeed; }
I started learning with MX, so I don’t know how to make it reverse compatible. What I can do is try and figure out an MX way and post it here, then a Flash 5 user can try and convert it maybe.
<U>This goes on a Frame</U>
MovieClip.prototype.loadme = function() {
this._x = 0;
this._y = 0;
this._alpha = 0;
this._rotation = 0;
};
MovieClip.prototype.move = function(fadespeed, movespeed) {
if (this._x<=253.2) {
this._x += movespeed;
}
if (this._alpha<=100) {
this._alpha += fadespeed;
}
if (this._rotation<=45) {
this._rotation += movespeed;
}
if (this._y<=178.2) {
this._y += movespeed;
}
};
<U>This goes on the Movie Clip</U>
onClipEvent (load) {
this.loadme();
}
onClipEvent (enterFrame) {
this.move(1, 2);
}
I optimized the code also. You can define the movespeed and fade speed for each individual movie clip you apply this to. As you see the function called on the movie clip where it says (1, 2) coresponds with MovieClip.prototype.move = function(fadespeed, movespeed)
I hope this helps:)
PS: My mind isn’t functioning correctly tonight, so if it is not what you wanted I am terribly sorry.
Really? That is good info. I kind of regret not starting with 5, because there are so many questions I am not sure of about Flash 5 AS compared to MX AS.