Actionscript 3 - load and library image on increment / counter
I have a very simple flash movie.
- 24 png images in the Library
- The image properties are set to 'Export for Actionscript' and the class named 'image1', 'image2' etc
- Single frame in the timeline
I need to dynamically load 'image1' on the stage at the start of the movie. I have been able to do this using BitmapData ojects.
On clicking the image, I need to increment an internal image and replace the image on screen with image2.
When I try to pass the library class开发者_运维技巧 as a variable it throws an error.
Can anyone help me with an example?
Any questions, just let me know.
Loading externally might be handy, but the library approach is doable. You need to either use loaderInfo's applicationDomain's getDefinition() method, or flash.utils.getDefinitionByName();
application domain example:
for(var i:int = 0 ; i < imagesNum ; i++){
var ImageClass:Class = this.loaderInfo.applicationDomain.getDefinition('YourLinkageID'+i) as Class;
//I add 0,0 because since you have png, they will extend BitmapData which has width and height as compulsory
//constructor arguments. If the thing doesn't look right, use the actual dimensions instead of 0,0
var bitmap:Bitmap = new Bitmap(new ImageClass(0,0));
//display it or do whatever
}
getDefinitionByName example:
import flash.utils.*;
for(var i:int = 0 ; i < imagesNum ; i++){
var ImageClass:Class = getDefinitionByName('YourLinkageID'+i) as Class;
var bitmap:Bitmap = new Bitmap(new ImageClass(0,0));
//display it or do whatever
}
HTH, George
You would be better creating a class and loading the images in using the Loader class. Is it imperitive you have the images in the library?
精彩评论