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

      Hi,

       

      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()">
           <fx:Declarations>
                <!-- Place non-visual elements (e.g., services, value objects) here -->
           </fx:Declarations>
           
           <fx:Script>
                <![CDATA[
                     import com.DisplayMap;
                     public var mapDisplay:DisplayMap;
                     public function iniz():void{
                          mapDisplay = new DisplayMap(stage);
                     }               
                ]]>
           </fx:Script>
           
           <s:navigationContent/> 
      </s:View>
      
       
      

       

       

       

      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();
                     _this.addChild(map);
                     map.x=0;
                     map.y=0;
                     
                }
           }
      }