Copy link to clipboard
Copied
Hi,
Currently I have 20 separate png images in the library each made into a MC. So there are 20 MC's, each one holding a specific image for which it is the correct size.
What I would like to set up instead, and need some help with, is dynamically loading a different set of 20 images (that I can add to the library), each to one of the MC's.
I think that first I would need to create 20 empty MC's to hold one or another of these sets of 20 png's each.
What I need help with: how to script this so that 2 buttons could be used: one button would load the first set, each image into a specific empty MC which is sized to hold it (20 MC's total), and a second button to load the second set of 20 images, one each to a specific empty MC which also would be its correct size. I checked out the loader class but this seems to be for external URL's not images already in the library.
Any help, suggestions appreciated.
saratogacoach
1 Correct answer
Hopefully you are familiar with how to dynamically add movieclips from the library. You do it by assigning a class name to the movieclip in the library and then you declare a new instance of the movieclip, much like you just did for the generic MovieClip class.
It can work somewhat the same way for adding images. Right click the image in the library and click on Properties. In the panel that opens, access the Actionscript tab in it and assign it a class name. Let's say you name it ImageA. To
...Copy link to clipboard
Copied
An mc's size is defined by the size of the content it holds. So if you dynamically create the mc's that should be all you need.
Copy link to clipboard
Copied
Hi Ned,
Thanks for the lead. OK:
var _mc:MovieClip = new MovieClip();
_mc.x = 100;
_mc.y = 30;
_mc.name = "_mcName";
addChild(_mc);
This would create one of my 20 MC's. But how do I load into it, either imageA.png or imageB.png, which I would add to the library, depending on which choice (which button they click) the user makes? And, then whichever image is chosen, how to change/replace it with the other image if that choice to replace/change it is made later by the user?
saratogacoach
Copy link to clipboard
Copied
Hopefully you are familiar with how to dynamically add movieclips from the library. You do it by assigning a class name to the movieclip in the library and then you declare a new instance of the movieclip, much like you just did for the generic MovieClip class.
It can work somewhat the same way for adding images. Right click the image in the library and click on Properties. In the panel that opens, access the Actionscript tab in it and assign it a class name. Let's say you name it ImageA. To load it into the movieclip you just created you can use...
var _mcImage:Bitmap = new Bitmap(new ImageA(0, 0));
_mc.addChild(_mcImage);
Copy link to clipboard
Copied
Hi Ned,
Thank you for your help with getting it started. I began to search further, using your suggestions, and came up with an efficient way to load images at runtime into each of the 20 MC's.
I'll keep experimenting to get it working.
Again, thank you very much!
Best Wishes,
saratogacoach

