I did this many years ago and I tried searching for this but did not find what I was looking for. I basically have a group of buttons and I want the buttons to load movie clips into an empty mc and then have the movie clip close again when the user clicks somewhere else. Do I actually have to save the movie clips as swf files first and then load them in to the empty mc?
You can save them as swfs if you like, or you can have them as movieclips in your library and add them from there. To add them from the library you need to assign a class name for each one and then you can create a new instance using the class name. To assign a class name, right click the mc in the library and select Linkage. In the panel that appears select the option to export for actionscript and then assign a clas name for the object in the field labeled as such.
Then to add it to your empty movieclip you would use... (assume you gave it a class name of "NewMC", and your empty movieclip is named "emptyMC")...
var newmc:NewMC = new NewMC();
"newmc" is just an arbirtrary name assigned to the instance being created
So I created an actions layer and pasted the code in. I replaced what I thought I needed to replace with the names I have given. I got an error when I tried previewing that said: 1046: Type was not found or was not a compile-time constant: empty_mc.
Here's my AS:
var newmc:bio_mc = new bio_mc();
It's been a while since I've used Flash and done actionscripting so appolgies for my newb questions.
You probably haven't created your empty_mc movieclip, or at least you haven't named it that.(instance names are assigned in the properties panel.)
Until you get the empty_mc figured out you can create it dynamically using...
var empty_mc:MovieClip = new MovieClip(); // creates an empty movieclip
var newmc:bio_mc = new bio_mc(); // creates the mc you want to put in it
empty_mc.addChild(bio_mc); // puts the mc in the empty one
addChild(empty_mc); // puts the empty mc on the display list
I do have my empty_mc labled with the instance of empty_mc. This is the error I just got now:
|Scene 1, Layer 'actions', Frame 1, Line 5||1067: Implicit coercion of a value of type Class to an unrelated type flash.display:DisplayObject.|
I missed that error...
should be: empty_mc.addChild(newmc);
bio_mc is the class name. Class names as a standard start with capital letters (as in Bio_mc) to help avoid confusing them with variables and instance names.
So that fixed the error, but it's loading the mc right when I test the movie instead of when I click the bio button? I also need to know how to specifiy where to load the empty mc because right now half of the bio_mc is getting cut off halfway off the screen.
If you expect a button to process those commands, then you need to incorporate those commands into the button's event handler function.
It sounds like you have the registration mark centered if it is halfway off where you think it should be. You can always adjust the objects x and y properties to place it wherever you want it to be.