0

I received from my client a SWC file with hundreds of png images that all have AS Linkage such as image1_1_1, image1_1_2, image1_2_1, image2_1_3 and so on. I have these same linkage names in an XML file that i'm loading. All the images are linked with the BitmapData class as base class.

The problem is that when i try to dynamically create new bitmaps from the xml file and the linkage names by using getDefinitionByName i get the following error:

ReferenceError: Error #1065: Variable image1_1_1 is not defined.

My code for creating the bitmaps is as follows:

var BmDataClass:Class = getDefinitionByName(xmlImage) as Class;
var image:Bitmap = new Bitmap(new BmDataClass());

where xmlImage is the variable in a for each loop, looping through the xml file.

I trace xmlImage so i know it coresponds to the correct name in the SWC file.

Does anyone have any idea why i get this error? Would appreciate any hints or solutions :-)

Poppe76
  • 394
  • 3
  • 14

2 Answers2

0

try this:

var imageName:String = "xxx";
var myClass:Class = getDefinitionByName(imageName) as Class;

var bmp:BitmapData = new myClass(0, 0) as BitmapData;
var img:Bitmap = new Bitmap(bmp);
bitmapdata.com
  • 9,572
  • 5
  • 35
  • 43
0

The answer seems to have been as described in the accepted Answer to this thread

Instantiate a class from a string in ActionScript 3

And also slightly explained on this page

http://producerism.com/blog/flashpunk-dame-and-lua-tutorial-part-6/

under the paragraph titled getDefinitionByName

Which for me sadly messed up a large part of the project. Ah well... new solutions presents themselves every day :-)

Community
  • 1
  • 1
Poppe76
  • 394
  • 3
  • 14