Dynamically retrieve a class from my flash library

I have several bitmaps in my flash library that I exported for ActionScript. Now, depending on the resulting Flashvars, I want to download the corresponding library bitmap.

How to load a dynamic bitmap class?

+3
source share
5 answers

Basically, to attach a bitmap from a library, you will do the following:

import flash.display.BitmapData;
import flash.display.Bitmap;

var bmp:BitmapData = new ClassNameOfTheBitmap(0, 0);
var img = new Bitmap(bmp);

addChild(img);

But since you do not know the name of the class, you will have to dynamically create the class as follows:

import flash.display.BitmapData;
import flash.display.Bitmap;

var classNameFromFlashvars:String = "xxx";
var cls:Class = getDefinitionByName(classNameFromFlashvars) as Class;

var bmp:BitmapData = new cls(0, 0) as BitmapData;
var img = new Bitmap(bmp);

addChild(img);

In this case, the class name in the image binding properties will be xxx.

+4
source

Loader ApplicationDomain. examples. swf - , :

loader.contentLoaderInfo.applicationDomain.getDefinition(className)  as  Class;

: :)

+3

. , " ", , , , . , swf . , , .

, . , - ?

+2

ex. MyClass

    public class MyClass extends MovieClip
    {
       private var testImg:Bitmap = new Bitmap();

       public function MyClass()
       {}

       public function set testImg(value:String):void
       {
          var cls:Class = getDefinitionByName('team_' + value) as Class;

          var bmp:BitmapData = new cls(0, 0);

          testImg = new Bitmap(bmp);

          addChild(testImg);
       }
    }

, , team_4534.

Does MyClass really detect all library assets? Do I need to somehow import them or say that they exist?

0
source

okey, so I found a very ugly way not to get errorError error: Error # 1065: team_xxx variable not defined '

I created a function in flex with all the various classes from .swc:

    private function logos():void
    {
        team_25502;
        team_25504;
        team_25508;
        team_25509;
        team_25511;
        team_25514;
        team_25517;
        team_25521;
        team_25530;
        team_25591;
        team_66036;
        team_66230;
        team_85230;
        team_89483;
        team_89484;
    }

If someone has a better idea, and I'm sure someone will do it, then please write a comment.

0
source

Source: https://habr.com/ru/post/1705390/


All Articles