all groups > flash actionscript > november 2004 >
You're in the

flash actionscript

group:

need advice about classes


need advice about classes XMLgirl
11/27/2004 6:47:39 PM
flash actionscript: Dear wise flashers,

I really need your advice here, as I am a stressed student towards finals.

I'm creating an animation of a fairytale.
My teacher suggested I use classes for each of my characters. Makes sense!

So, I created my first class called prince. In the class code I'm attaching a
prince MC. The prince begins by walk to the edge of the stage and then some
stuff happens, which i placed in the prince MC.
My problem is: if the movement of the price across the stage I'm controlling
through the class code, how do I wait for stuff that happens inside the prince
MC timeline and then have the prince walk again to the other side of the stage
through its class code?

It makes me wonder, is it the right way to go? or maybe every element on stage
should have a class rather than put them inside the prince MC?
But even if I do that, I'll still have some stuff happening inside the prince
MC on a timeline. So, again, how do I write a code in the class that waits for
the MC timeline to finish running and them do whatever through code.

Sorry if it's too confusing.
I really appreciate any advice.

Re: need advice about classes J_o_h_n_n_y
11/27/2004 7:35:49 PM
Re: need advice about classes XMLgirl
11/27/2004 8:11:41 PM
That's the code I have in my prince class (P1_1):

class P1_1 extends MovieClip {
private var b:Number = 0;
private var e:Number = 0;

function init1_1(b, e){
attachMovie("p"+b+"_"+e, "p",3, {_x:277, _y:-30});
onEnterFrame = moving;
}

function moving(){
_x += 5;
}
}

So then, all the other stuff is happening on timelines inside the prince MC
(p1_1. which I am attaching in the above code)

Thanks,
Re: need advice about classes J_o_h_n_n_y
11/27/2004 8:18:52 PM
Well, instead of using onenterframe = moving, you could could use a generalized
function. Like:

class P1_1 extends MovieClip {
private var b:Number = 0;
private var e:Number = 0;

function init1_1(b, e){
attachMovie("p"+b+"_"+e, "p",3, {_x:277, _y:-30});
mode = "movingRight";
onEnterFrame = doStuff;
}

function doStuff() {
if (mode == "movingRight") {
_x = _x + 5;
if (_x == Stage.width - 50) {
mode = "MovingLeft";
}
} else if (mode == "movingLeft") {
_x = _x - 5;
}
...ect...
}

Is this sorta what you are talking about?
Re: need advice about classes XMLgirl
11/27/2004 8:23:12 PM
another scenario to make my confusion more clear:
The prince lift his arm (which is happening in a timeline inside the prince MC)
...then, only after the prince lowered back his arm, then I need him to walk
away.
But the walking part is in the class code and the arm movement is in a
timeline in the prince MC
(sorry for repeating...)

Hopefully it's clear enough.
Thanks allot
Re: need advice about classes XMLgirl
11/27/2004 8:30:01 PM
I guess we posted a reply simultanously.

Not exactly. My problem is not to get him to move from one side to the other,
but rather, to get him to move to the other side only after his internal
timeline reach the end.

Thanks
Re: need advice about classes J_o_h_n_n_y
11/27/2004 8:31:25 PM
Well, hmm...

Since you are not doing this based off of any AI, and it is just straght
animation, maybe do all the timing on the main timline. As in:

(on the main timeline)
seconds = 0;
timer() {
seconds++;
if (seconds > 1 && seconds < 20) prince.walkRight(); // walk right for 20
seconds
if (seconds > 20 && seconds < 30) prince.walkLeft(); // walk right for 10
seconds
if (seconds > 30 && seconds < 5) prince.liftHand(); // lift hand
}
setInterval(timer,1000);

Obviously the code wouldn't exactly this, but maybe something like this where
one function acts as the "director" to the actors on the stage?
Re: need advice about classes XMLgirl
11/27/2004 9:08:14 PM
Thanks much Johnny,

I may need to use that idea if I don't have a choice.
But I'm wondering, isn't there a way to access the timeline inside a
dynamically attached MC?

In pseudo code it'll be:

prince _x += 5
if prince _x > 30 then
timeline inside the prince start play (prince.gotoAndPlay(2))
-----
if timeline marker (I think that's how it's called) is on frame 70 then
prince _x -= 5

I assume a code like that would be inside the prince class.

Know what I mean?


AddThis Social Bookmark Button