Saturday, February 11, 2012

FlashDevelop and ActionScript 3 - how to embed image - fast tip

When you use the official flash ide, using images is as easy as clicking several buttons. Actually using images with FlashDevelop is even easier but if you haven't done it you will need this info.
First copy the desired image into folder of the project, for example I'll name my folder assets.
Add a variable to your class:
private var myImg:Class;
And place your cursor on the row above it. Right mouse button on the image and select Generate Embed Code:


You will get something like this:

[Embed(source="../assets/s1.png")]
private var myImg:Class;

Add this where you want to use the image:

var bitmap:Bitmap = new myImg();
addChild(bitmap);

Easy, isn't it?

2 comments :

  1. nice, but i accustomed to using Visual Studio.
    and CodeDrive provide development on ACtionScript 3, see http://www.codedrive.com/

    ReplyDelete
  2. I have done this..but in my 3D environment(flashDevelop) i just see a white screen
    when I switch back to just color material...it works:

    [Embed(source = "assets/cube.png")]
    private var cubeBitmap:Class;

    used light this:
    var materialBitmap:BitmapData = new cubeBitmap();
    material = new TextureMaterial(new BitmapTexture(materialBitmap));

    however in flash ...import the image to lib, then export for actionscript
    (no need to embed)
    and the above code works

    I though if I just add the embed...the usage wil be same?

    can anyone help me?

    ReplyDelete