Attaching MC dynamically to button state

Hi there,

This is my first post in Kirupa, so it’s the opportunity for me to congratulates admins and contributors’ s works in here : I learnt a lot from this forum and the tutorials beside.

Now to the point.

How to dynamically attach a specific MC to each Button’s states ?

In order to be able to change them at run-time, I’d like to attach a MC on the button’s <UP> state , another MC on the button’s <OVER> state, and so on, with the possibility to change these MC later on. The button is, itself, encapsulated in another MC.

If I made myself clear :crazy:, would you have any suggestion ?

PS : I’m using mx2004.

well i’m not to sure what you mean :-, but if you want to change another movieclip’s properties or anything on a buttons OVER state, then you’ll havta use actionscript.

something like:

on (rollOver) {
blahblah
}

where ‘blahblah’ are your actions. :slight_smile:

Sorry for my Alien speaking way… :alien: I’ll try to be more precise : :slight_smile:

I don’t plan to handle any particular button 's behavior like : “what’s happening if I roll mouse pointer over the button”, or that kind of action thing. And you’re right, this is the way to handle it at runtime, if desired.

What I 'd like is : to BUILD a button dynamically, and to BUILD its different states layout in it (each one with a specific MovieClip).

So, I guess, there’s something to do with the attachMovie method, but I don’t have it working.

Do you see ?

do you ahve an example?!? i’m confused :-\

As it is a project yet, I don’t Have any *.fla to propose at the moment :puzzle:

But mainly, here is the scenario :

1/ loading img#1, img#2, img#3 from outside, into MC#1, MC#2, MC#3, so that I can animate these image.

2/ putting MC#1, 2 & 3 in button states Up, Over, Down (in order to have a animation different for each state, based upon the loaded images)

3/ putting this button into a last MC, so that I can animate the button itself on the stage.

later in the animation, I want to have the possibility to change the base images I loaded, with any other newly loaded. It’s a kind of SKIN feature for my animation.

Hope this is better explained :q: (sorry, my englsh is a pity:sigh: )

ok i think it is clearer now :stuck_out_tongue:

for 1) since you saw you are loading it from outside, does this mean you are trying to load SWF’s in? If so, it would be loadMovie instead of attachMovie.

  1. I think you mean when you rollover a button, you want one of the MC’s to play right?? Then you would use actionscript for that. Such as what i mentioned above…on (rollover) blah blah blah…

ok so thats what you do, but i’m not sure which parts you’re stuck on :-\ I hope i am right in what you want to achieve though :stuck_out_tongue:

No, again, this has nothing to do with a roll over action… the image has to be loaded in the button state’MC before any user action (runtime built-in).

I’ve just made up a short *.fla to help me explain :fe:

Check the frame 2 comments to know about what I need to do.

Hope it’ll help my poor explanations abilities :ne:

Thanxx :slight_smile:

****…i’m guessing you are using flash 2004 :-\ I’m only on MX so i can’t view your file :-\ sorry :frowning:

Hi :slight_smile:

Please find attached here the same file, but this time I saved it in MX2004 as a MX file. Hope the conversion will be ok :}

ok well i’m not sure why you need to create an empty movieclip if you’re going to move it, so the better way would to just directly load the clip INTO the button you want it to go into :slight_smile:

This is what it looks if you load it into the emptyMovieClip

[AS]
stop();
_root.createEmptyMovieClip(“myContener1”, 1);
myContener1.loadMovie(“image1.jpg”, 1);
bytes_loaded = _root.getBytesLoaded();
bytes_total = _root.getBytesTotal();
if (bytes_loaded == bytes_total) {
_root.gotoAndPlay(3);
}
[/AS]

and on frame 2 put the code:

[AS]
_root.gotoAndPlay(1)
[/AS]

and frame 3:

[AS]
stop();
[/AS]

If you aren’t going to do anything with the empty movieclip - just change the code to:

[AS]
_root.MC1.MC2.loadMovie(“image1.jpg”, 1);
//delete the createemptyMovieClip bit
//MC1 and MC2 are the instance names of the clips in the library
[/AS]

This is what you wanted right??! hope so :stuck_out_tongue:

Cool, I think we’re nearly at it, THUMBS UP ! :beam:

Now, could you just tell me, once you’ve done with image loading in the “contener”, and being at frame 3, how would you move this image (or the clip in which the image stands) from the root towards inside the button (and more precisely, inside one of the different states a button can have) ?

By the way, why do I need to first load the image into a “dummy” contener that I don’t even want to see ?
Well, it’s because I need to do some ‘control’ tests on the image, and I need to repeat these operations for other images in other contener clips. If all control tests are ok, then I want to “transfer” these images (without loading them again) from their contener into their final destination (where they’re going to be actually seen and used).
This is a way to validate a whole bunch of layout assets before using it as a complete new user “skin”.
I want to be able to operate like this during the run time, so that I can change my skin anytime I want.
I want to let te user the ability to change his skin, so I let him choose its own images for that. But I can’t let him propose whatever format, size, and uncomplete skin (a missing image, for example).
That’s why I need these controls BEFORE “instantiating” the animation with his personal skin.

Woo, I’ve been long this time… still there :skull: ?
Sorry :hangover: … :}

Ok i think i know what you mean, but the only way i can think of to move the image from the container(contener) to another MC is to move the actual container…I don’t think there is another way. Either that or directly loading it to a different location :-\

Instead of changing the clip that holds the imported data, just set the _visible propety to false do your test, to make sure everything is okay then set _visible back to true.
and as far as loadMovie is concerned, if you use it as a method your dont have to put the layer.
ie [AS]_root.MC1.loadMovie(“image1.jpg”);[/AS]
the jpg will take over the lowest layer of the movieclip you load it into by default.
Also if you have a lot of actionscript you want to apply to the container clip, I would suggest making an empty movieClip on the stage giving it all the actionscript and then using duplicateMovieClip to make more containers as they are needed.