2 Replies Latest reply on Jul 22, 2011 4:48 PM by Flex harUI

    Easiest way to access the stage from as3 class

    home_aidan Level 1



      Can someone tell if this is the best way to add assets to project?

      Im just using stage to do this or can I use some type of component to "cradle" these assets



      Im look at adding assets to my flashbuilder project from swc file originally created in flash



      So to do this I am using the view component in my mxml.


      I listen for "addedToStage"

      on the event It triggers a function called "iniz" which creates an instance of a as3 class called Displaymap

      and passes in the stage.


      It looks like this...



      <?xml version="1.0" encoding="utf-8"?>
      <s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
                xmlns:s="library://ns.adobe.com/flex/spark" title="Map and Stats" addedToStage="iniz()">
                <!-- Place non-visual elements (e.g., services, value objects) here -->
                     import com.DisplayMap;
                     public var mapDisplay:DisplayMap;
                     public function iniz():void{
                          mapDisplay = new DisplayMap(stage);




      My class...DisplayMap

      Then adds some stuff to the stage using addChild



      package com
           import flash.display.MovieClip;
           import flash.display.Sprite;
           import flash.display.Stage;
           import views.OverallMap;
           public class DisplayMap extends Sprite     {
                public function DisplayMap(_this:Stage){
                     trace("will display Map");
                     var map:MovieClip = new ukMap();