Groups | Blog | Home
all groups > flash actionscript > january 2006 >

flash actionscript : EMPTY MC


tralfaz
1/20/2006 10:44:38 AM
[quoted text, click to view]

To make an object reference out of a string you can do it this way..

function Resolve() {
for (var j=1; j<10; j++) {
for (var i=1; i < 24; i++) {
var mc = this["joint"+i];
mc.resolveDistanceConstrain();
mc.resolveAngleConstrain();
mc.main();
}
}
mc.updatePosition();
}

Your J loop doesn't seem to be used anywhere. Is something missing?

For older versions of Flash like Flash 5 and earlier there is another
syntax to convert strings to clip references. Looks like this..
var mc = eval("joint"+i);

tralfaz








combava
1/20/2006 5:38:55 PM
Dear all,

I have a general actionscripting question as well as a specific case scenario.
I'm relatively new to actionscripting but have quite a bit of Lingo experience.

I need to write some code that with update continuously (in order to animate a
character dynamically).
My first impulse would be, as a general rule, to write ALL of my code in the
first frame of the main timeline.
And then to call the animation functions I need onEnterFrame of an empty movie
clip located off-screen.
In this way, it seems to me but please correct me if i'm wrong, the functions
will be called as often as possible without blocking the machine....

More specificallly, I need to perform three actions (in a fixed order), repeat
on 23 remaining body parts ten times, then update the screen. Thus, a loop
within a loop, at least in Lingo... The function woud look something like this :

function Resolve() {
for (var j=1; j<10; j++) {
for (var i=1; i < 24; i++) {
joint = "joint" + i ; //DOES THIS WORK IN ACTIONSCRIPT ?
joint.resolveDistanceConstrain();
joint.resolveAngleConstrain();
joint.main();
}
}
joint.updatePosition();
}

Then I would call this function from the empty movie clip onEnterFrame, though
I'm not exactly sure how. It would look something like this :

this.onEnterFrame = function() {
Resolve(); // WHAT IS THE CORRECT WAY TO CALL THIS FUNCTION
}

My questions are : is it correct to call a continually-executing code from
within an empty mc ?
Can you concatenate (see joint+i above) the mc name you are trying to address ?
What is the correct syntax needed to call the function from the mc ?

THANK YOU !!



ClayHalliwell
1/20/2006 9:06:33 PM
Clips (well, all objects in general), can be referenced using array syntax or
object syntax. These can be freely mixed in ActionScript. In your example,
"joint" isn't an object, it's a string containing the NAME of an object. So you
have to resolve this reference.

Array style:
joint = this["joint" + i]

Object style:
joint = eval("joint" + i)

Eh, I think that's right. Been a while since I used eval().
combava
1/20/2006 9:52:18 PM
I should note that "joint" is a movie clip in the library
AddThis Social Bookmark Button