Monday, May 12, 2008

Placing Assets

To place an asset on the stage (display an image, video, or play music), an asset library must first be created.
  1. Right click and save this image () as star.png in the src directory. On my machine, the full path is:
    /home/kca/workspace/hello_world/src/
  2. Copy and paste this XML into asset.xml in the src directory
  3. At the command prompt, run this command in the src directory:
    swfmill simple asset.xml asset.swf
  4. If you have swfmill installed correctly, a new SWF file should now exist in the src directory called asset.swf. This is the asset library.
  5. Return to Eclipse and right click on your project name, e.g., hello_world. Select Properties
  6. On the left, select AS2 Builder; on the right, select the entry for Application
  7. Click Edit
  8. Enter src/asset.swf in the Input SWF box
  9. Click OK to return to the Properties dialog
  10. Click OK to return to the Eclipse editor
  11. Double click source file Application.as to edit
  12. At the bottom of the class constructor, add this code:
    var my_star:MovieClip = attachMovie("asset_star", "my_star", this.getNextHighestDepth()) ;
    my_star._x = 250 ;
    my_star._y = 50 ;
    my_star._xscale = 400 ;
    my_star._yscale = 400 ;
  13. Save the file, and the SWF file is automatically rebuilt by Eclipse. Click to see a star image in the top right of the Flash demo.
A few important notes:
  • Inside the asset.xml file, the movie width, height, and framerate are inherited by the SWF file output by your project. Some might call this a weakness of the Eclipse integration or MTASC. This may change in the future, but be aware of it now. This can be difficult to debug if you forget!
  • Assets are not limited to a single placement. They may be placed zero, one, or many times. Only the MovieClip name, e.g., my_star, must be different for each instance.
  • Currently, MTASC is limited to one asset library, but it may be possible to merge multiple asset libraries using swfmill.
  • Read more about swfmill here.


1 comment:

VirtualFlavius said...

Your link to google code is broken.

Thanks for this great tutorial series.

VirtualFlavius