Search code examples
actionscript-3flash-cs6

Create symbol and attach image from library to symbol with code


I assigned a class of bgMountain to an image in my library. How do I (programmatically) create a new symbol, and attach that image to the newly created symbol?


Solution

  • [Embed(source="path_to_hero.png")] //or .jpeg
    public class Hero extends Bitmap {
      public function Hero(){
    
      }
    }
    
    public class Main extends Sprite(){
      public function Main():void {
        var hero:Hero = new Hero() ;
        hero.x = 50 ;
        hero.y = 50 ;
        stage.addChild(hero) ;
      }
    }
    

    Here is the tutorial

    Also, using SWF library