PDA

View Full Version : Changing symbol and every instance of it at once



hihabyte
July 9th, 2003, 07:45 AM
This is what I have:
I have a variable called "framenumber" and a movieclip(drawing) with six frames. Each frame of the movieclip has another drawing in it.
In the main movie, this movieclip exists over several frames and keyframes. I even do a motion tween with the clip. Now what I want to do, is change the value of framenumber (for example 2) and then do a drawing.gotoandstop(framenumber). So then, the drawing in frame 2 of the movieclip should be shown. But here comes the problem. If I do that,the drawing (in frame 2 of the movieclip) only appears in the frame of the main movie where I put the drawing.gotoandstop(framenumber) command. But in the other frames of the main movie, the initial drawing is kept. How can I let the drawing change everywhere where the movieclip exists?

IF YOU DON'T HAVE MUCH TIME READ THIS:)
So actually I want to know how I can change every instance of a movieclip, no matter where it is in the movie. Or maybe there's a way to change the (library) symbol itself, so that every instance of it changes along with the library symbol?

I hope you guys can help me!

kode
July 9th, 2003, 07:55 AM
you could try putting this code in the first frame actions of the MovieClip:

this.gotoAndStop(_parent.frameNumber);
i think it should work. =)

eki
July 9th, 2003, 09:44 AM
Of course you can change every instance of a movieclip, no matter where it is in the movie as long as it exists on its parent timeline when you use the command that's going to make the change.

Note that an instance of the same symbol with different name won't be changed

It looks to me like the different instances of your MC don't have the same instance name.

hihabyte
July 9th, 2003, 12:46 PM
Owkaayy, It works, but I don't really understand it:crazy:. Something really weird happened by the way. I just copied your piece of code into the movieclip, and I hadn't defined or declared frameNumber anywhere in the file yet. But when I published it, it automatically went to the second frame of the movieclip... Why???

And why does it change immediately after the 'framenumber' is changed? Does the movieclip automatically check the variable??

Actually, I wanted to wait with the change until frame 25, by putting a command there that changes the frame of the movieclip to 'framenumber'.
But now the movieclip changes immediately after I push the button(frame14) that changes the variable. How can I work according to what I had in mind?

I feel like I'm being very demanding... So don't understand me wrong, I am véry gratefull for the tips!!=)

kode
July 9th, 2003, 12:58 PM
ok now i'm confused. :P

try this:

if (_parent._currentframe == 25) this.gotoAndStop(_parent.frameNumber);
if that doesn't solve the problem, could you attach your FLA? :)

eki
July 9th, 2003, 02:09 PM
Plas, plas, plas, Kax campeon!

hihabyte
July 9th, 2003, 02:15 PM
Here's the fla.
It worked without the "if frame 25..." statement. But now it doesn't. I think it might have to do with the stop() I put in the movieclip. If I don't put it there the movieclip plays, and it shouldn't, but If I put it there, nothing happens. Well, you can see it yourself now:)

hihabyte
July 10th, 2003, 06:13 AM
Maybe I'll just put my site online? Then I can more easily explain what I mean, and you will more easily understand if you see it...

:)

eki
July 10th, 2003, 06:47 AM
Yes plz

hihabyte
July 10th, 2003, 08:05 AM
Okay, I published the swf on a webserver. So now you can go and watch it. When you come at the site you will see 'music' in big blue, alpha letters behind all the content. This is the movieclip where I'm talking about. Now, when you push one of the buttons to the right, you will see the 2 outer panes move away and you will see that the movieclip has changed and goes away to.
But what I want is that is doesn't change until it's outside the screen and after that is has to come back, changed.
Example:
This is how it is now:
If you push the gitaar-button, the movieclip changes from 'music' to 'guitar', goes away and then comes back.
This is how I want it:
If you push the button, the movieclip stays on music, goes away, changes and then comes back as 'guitar'
The flash is also here, so maybe you can compare and find out how to do it??
Thanx!!! =)=)

gotosite (http://users.pandora.be/hihabyte/homepage.html)


PS: In the published swf, the if-suggestion from kax hasn't been used yet, because then I have the stop()-problems etc...etc...

hihabyte
July 10th, 2003, 08:06 AM
I'm sorry, the buttons are to the left, of course... OOPS! :)

eki
July 10th, 2003, 08:45 AM
Hi,
OK , I see what you mean.
I've had a look at your Fla and I'd separate things into MCs so everithing fits in one frame but with what you've got at the moment I would do something like this:


//code in buttons (I'm using gitaar as an example)
on (release) {
this.play();
this.onEnterFrame = function(){
if(this._currentframe == 13){//it would be better to label frames
doWhatYouneed(); //
this.onEnterFrame = undefined;
}
}

}




hope it helps

SHO

hihabyte
July 10th, 2003, 12:16 PM
And how do I label frames? I used your script and I tried to use it for loading the movies too, but it doesn't work, maybe because I didn't label?

hihabyte
July 10th, 2003, 07:09 PM
Kax, your last tip (if_parent 25...) seemed so logical because it worked without the if part, changing the mc immediately, but it doesn't work with the if-part. Any ideas why it doesn't?
THX

eki
July 11th, 2003, 06:54 AM
Hi,

I'm posting your original fla file with the example of gitaar working. Have a look and tell me if thatys what u want to achieve.

SHO

hihabyte
July 11th, 2003, 08:17 AM
Well, the piece of code in 'lettersclip' doesn't seem to work. I saw the trace you made. But the lettersclip (this is the movieclip where's it's all about) still comes back as music, instead of guitar.
Guitar is frame 2 of the lettersclip, so I want every instance to show their second frame...
Does it work the way I want it to with you? Maybe there's something wrong here, some bug or something?

eki
July 11th, 2003, 09:40 AM
There you go!
I`d asumed you'd know how to do the rest

SHO

hihabyte
July 11th, 2003, 11:46 AM
I searched for 15 minutes what you changed in the second one!:) I didn't see that the frame in the ifstatement was still on 14 in the first version. Guess I didn't look good enough! But now it al works nice and smooothh owyeah!
Thank you very much, eki!!!! =)

hihabyte
July 11th, 2003, 11:50 AM
One last question: I always thought that 'this' referred to the object to which you assign the code, but here it seems to refer to the movie and not the gitaar-button. Why?

eki
July 11th, 2003, 12:12 PM
Hi,

You are welcome!:)

This refers to the object you're working on or , in plain English,
the timeline you're working on.
In this case note that the gitaar symbol is a button and as button it hasn't got its own timeline so this refers to the timeline it is in.
If you where to use movieClip symbols rather than buttons(which I recommend but that's another story) to refer to the main timeline you'd have to use 'this._parent ' as 'this' would refer to the timeline within itself.

Hope it helps

SHO

:) :)

eki
July 11th, 2003, 12:19 PM
And by the way:

Click on frame 25 and on the propeties pane, on your left there is a text field under the word "frame". There is where you label frames. You'll a flag with its name on the timeline when you do it.

Let's say that you call frame 25 'trigger'. Then you can use:
if(this._currentframe == "trigger"){
...........................
}


and so you only have to move that frame in case you want to give it more or less frames without having to go into the code to chnge the frame number.(USE A LAYER ONLY FOR LABELS AND ANOTHER ONE ONLY FOR ACTIONS).

Cheers

SHO:) :) :)

hihabyte
July 11th, 2003, 12:52 PM
Thanks for the labeling info!
I think maybe there's a bug somewhere in my file after all. The file I sent you was one that had been 'cut' because the real file was to big to post here. And the files you gave back to me all work. But when I copy the same code into the bigger file I have here, it doesn't work for some reason. And I've checked every single line of code, it's all the same. I did the trace I tried the debugger but I don't find the problem. So I'll probably take your working file and just copy everything from the big file into yours!
You've been of great help to me! :)

eki
July 11th, 2003, 01:20 PM
Any time

:thumb:


SHO:) :)