2 Replies Latest reply on Sep 9, 2006 12:14 AM by Daniel Hai

    Displaying Flash 9 Symbols in Flex - Looking for an elegant solution

    Doug Sharp
      I've been trying to find an elegant way to display MovieClip symbols from a Flash 9 swf in a Flex app. I am rewriting my old game ChipWits (google it) and have a bunch of graphics which I need to repeat for walls, floors... All the graphics are in Symbols with auto-generated classes (coffee class for the coffee symbol).

      I have it working in a very inelegant manner by putting named instances of each of the Symbols on the stage. In Flex I call a function in the swf's Document class that moves the symbol to 0,0 and makes it visible in the swf:

      private var mc_Item:MovieClip = null;

      public function showInstanceInSWF(itemName:String):void {
      // If it has the property draw it
      if( this.hasOwnProperty(itemName) ) {
      // Get rid of any old instance in the SWF
      if(this.mc_Item != null) {
      this.mc_Item.visible = false;
      this.mc_Item = null;
      // Point mc_Item to the MovieClip on stage named itemName
      this.mc_Item = this[itemName];
      if(this.mc_Item != null) {
      this.mc_Item.x = 0;
      this.mc_Item.y = 0;
      this.mc_Item.alpha = 100; // They are alpha=0 in Flash
      this.mc_Item.visible = true;

      This means that for every piece of floor, wall, etc. onstage I need to load another SWF.

      What I'd like to do is something like:

      public function returnSymbolFromClass( className:String ):MovieClip {
      var mc:Object = null;
      try {
      var ClassReference:Class = getDefinitionByName(className) as Class;
      mc = new ClassReference();
      catch(e:ReferenceError) {
      return MovieClip(mc);

      and then to take the MovieClip and addChild it in my app outside the loaded SWF.

      This has me pulling my hair out. I am breaking my swf's up so there is one symbol in each, but again this is very kludgy.

      Any help will be grovellingly appreciated.
        • 1. Re: Displaying Flash 9 Symbols in Flex - Looking for an elegant solution
          Hi, You can try this:

          package {
          import flash.display.MovieClip;
          import mx.core.SpriteAsset;
          import mx.core.MovieClipAsset;

          public class GameSymbols extends MovieClip {

          [Embed(source='gameSymbols.swf', symbol='Coffee')]
          private var CoffeeClass:Class;
          //CoffeeClass represents the embedded symbol.

          public function GameSymbols() {
          //Flex defines CoffeClass as a reference to a subclass of
          //SpriteAsset class - for single-frame SWF files or
          //MovieClipAsset class - for multiframe SWF files.

          var myCoffee:SpriteAsset = new CoffeeClass() as SpriteAsset;
          //var myCoffee:MovieClipAsset = new CoffeeClass() as MovieClipAsset;

          //You can manipulate the embedded Symbol by using the methods
          //and properties of the SpriteAsset or MovieClipAsset class.
          myCoffee.setActualSize(50, 50);
          myCoffee.x = 10;
          myCoffee.y = 10;
          myCoffee.alpha = 100;
          myCoffee.visible = true;


          • 2. Re: Displaying Flash 9 Symbols in Flex - Looking for an elegant solution
            Daniel Hai
            If you know the names of the classes use loader and:

            var someclass:Class = loader.contentLoaderInfo.applicationDomain.getDefinition('SymbolName') as Class;