Variables

guys i need some help!

I have this MC called “notes” which is contained inside another MC called “score”.

therefore, “notes” can be called by using:
_root.score.notes right?

“notes” contains this code:


onClipEvent (load) {
pos=random(17)+1;
if (pos==1)
gotoAndStop(1);
else if (pos==2)
gotoAndStop(2);
else if (pos==3)
gotoAndStop(3);
else if (pos==4)
gotoAndStop(4);
else if (pos==5)
gotoAndStop(5);
else if (pos==6)
gotoAndStop(6);
else if (pos==7)
gotoAndStop(7);
else if (pos==8)
gotoAndStop(8);
else if (pos==9)
gotoAndStop(9);
else if (pos==10)
gotoAndStop(10);
else if (pos==11)
gotoAndStop(11);
else if (pos==12)
gotoAndStop(12);
else if (pos==13)
gotoAndStop(13);
else if (pos==14)
gotoAndStop(14);
else if (pos==15)
gotoAndStop(15);
else if (pos==16)
gotoAndStop(16);
else if (pos==17)
gotoAndStop(17);
}

Basically it just makes the clip go to and stop at a random frame. (each frame has a different graphic).

Now, in the “score” MC, I have some code on the first frame on a new layer which I called “actions”:


duplicateMovieClip(_root.score.notes,“notes2”,2);
duplicateMovieClip(_root.score.notes,“notes3”,3);
duplicateMovieClip(_root.score.notes,“notes4”,4);
_root.score.notes2._x=-20;
_root.score.notes3._x=30;
_root.score.notes4._x=80;

note1=_root.score.notes.pos;
note2=_root.score.notes2.pos;
note3=_root.score.notes3.pos;
note4=_root.score.notes4.pos;

_root.let1 = note1 + “,” + note2 + “,” + note3 + “,” + note4;

this dups this MC called “notes” 3 times and sets each duplicate’s _x position. This part is working fine.

Then I try to assign the pos variable to note1, note2, note3 and note4.

On the main scene I put a dynamic text field called “let1” to test if it is working. It’s not!

Now what I see in the text field is “,”

4 commas.

Thx in advance
:stuck_out_tongue:

first off… instead of that horriffic if/else clause could have used this…

onClipEvent (load) {
pos = random(17)+1;
gotoAndStop(pos);
}

secondly, if you are IN score, you dont HAVE to reference clips there from _root i.e. in score:
notes
is the same as
_root.score.notes
This is because you are already in score so you dont have to complicate things by referencing things all the way from _root, Back into score and then to your object

thirdly, and here is your problem, frame events on the main timeline execute BEFORE onClipEvent(load) events on movieclips. Because of this, your pos variables in your note clips arent even defined yet meaning you get nothing when you try to reference them. What you might want to do instead is have that pos definition right there in the frame so its run before your note signing. With the if/else mess replacement, its not as big of a deal as it would have been before
:wink:

notes.pos = random(17)+1;
notes.gotoAndStop(pos);
duplicateMovieClip(_root.score.notes,“notes2”,2);
notes2.pos = random(17)+1;
notes2.gotoAndStop(pos);
duplicateMovieClip(_root.score.notes,“notes3”,3);
notes3.pos = random(17)+1;
notes3.gotoAndStop(pos);
duplicateMovieClip(_root.score.notes,“notes4”,4);
notes4.pos = random(17)+1;
notes4.gotoAndStop(pos);

notes2._x=-20;
notes3._x=30;
notes4._x=80;

note1=notes.pos;
note2=notes2.pos;
note3=notes3.pos;
note4=notes4.pos;

_root.let1 = note1 + “,” + note2 + “,” + note3 + “,” + note4;

thanks senocular! :smirk: :geek:

i just started doing flash but my supervisor wants me to do all these hard things… grrrr

didnt come to my mind that i could do that random thing in 3 lines of code, heh
:ub:

Urhhh…

I just tried your method senocular: putting all the code in the actions frame on “score”

Apparently the “notes” and its dups dont gotoAndStop
They start playing from the first frame and loop continuously!

I want each duplicate to stop at a separate graphic so that I have 4 different notes on a music score :o

The “let1” textfield does work though, now I see different pos values :trout:

If its not too much trouble pls download this fla file if reference is needed (its only 70kb)
http://www.thx.to/webspace/thybalt/pics/guitar2.fla

thx in advance:rambo:

now you know at least :slight_smile: dont worry about it… the more you use it the better you’ll get and the esier things will come to you. You’ll catch on to things and things will eventually star making sense…

A good thing to do is to go through the tutorials, even if they are things you dont need to know. The thing is they can offer insights into coding styles and other non specific ways to help you easily achieve a mundane task such as the random pos and gotoAndStop. Flash can be tricky; it just takes some experience to know what booby-traps exist and how not to fall into them.

… while Im at it… dont use scenes :wink:

ok… hold on… didnt see that post… getting fla now

take your time =>

woops… heh

ok whats going on is the pos in the gotoAndStop is not the right pos… actually its no pos. What you need (which I just neglected in my copy and pasting of your old code ;)) is to include that clips name because the pos variable resides inside that clip. ie.

duplicateMovieClip(notes,“notes2”,2);
notes2.pos = random(17)+1;
notes2.gotoAndStop(notes2.pos);

^also the _root.score can be taken out of the duplicateMovieclip (I meant to do that too… :))

thanks senocular and all the great flash gurus helping on this forum =) i love this place!

oh yea it works perfect now. i’m a careless person so i dont see such little glitches. guess im not up for scripting :smirk:

hope i will improve with experience :sigh:

And where’s sector 7G? You work there?

btw im 19 from Singapore, how old r u?

Yuck!
This is disgusting!
As a programmer I must PROTEST!
NO If Then Else chain should be that long!
THERE MUST BE RULES TO THIS CHAOS!!!

*Originally posted by thybalt *
And where’s sector 7G? You work there?

thats where Homer works in the Springfield power plant on the Simpsons :wink: