Be a Supporter!

AS3 dynamic imports?

  • 404 Views
  • 11 Replies
New Topic Respond to this Topic
Fickludd
Fickludd
  • Member since: Feb. 28, 2004
  • Offline.
Forum Stats
Member
Level 15
Blank Slate
AS3 dynamic imports? 2009-09-14 10:56:32 Reply

Ok, this is a sort of advanced topic and I'm not even sure it can be done.

What I'm loosely doing is a testing program in flash, sort of like JUnit. The idea is that the user specifies a class name (ie. 'flash.display.Sprite') that extends my 'TestBase' class. This is tested by using assert type functions specified in 'TestBase'. The problem is that I need to import the class to be tested dynamically, and I don't know how to do it. Erhm...

Ideas?

GustTheASGuy
GustTheASGuy
  • Member since: Nov. 2, 2005
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to AS3 dynamic imports? 2009-09-14 11:13:03 Reply

flash.utils.getDefinitionByName

Import isn't the right word. The keyword doesn't even cause inclusion of the class in AS.


BBS Signature
Fickludd
Fickludd
  • Member since: Feb. 28, 2004
  • Offline.
Forum Stats
Member
Level 15
Blank Slate
Response to AS3 dynamic imports? 2009-09-14 11:42:54 Reply

Weell,

I'm using getDefinitionByName() right now and it works fine for loading for example flash.display.Sprite, but it won't work on my own classes unless they are in the compilation root folder. That is unless I import them manually at compile time. Which I could do, but would rather not since I would have to make separate testing files for ever project.

Could you load .as files with a Loader and parse them in some way?

GustTheASGuy
GustTheASGuy
  • Member since: Nov. 2, 2005
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to AS3 dynamic imports? 2009-09-14 12:08:26 Reply

Right, but you do want to compile them, right? Then you have to include them.

You can have an includes class, an empty one that just imports and lists the classes in its body,


BBS Signature
Fickludd
Fickludd
  • Member since: Feb. 28, 2004
  • Offline.
Forum Stats
Member
Level 15
Blank Slate
Response to AS3 dynamic imports? 2009-09-14 15:36:47 Reply

Blerk, seems like making an itsy testing tool in flash aint gonna work very smoothly.

Lol, I've been coding in python all summer - these kind of thing work out really nice in python. Although it's a hopeless language in many other ways.

Tree-SkyLark-BCE
Tree-SkyLark-BCE
  • Member since: Aug. 6, 2005
  • Offline.
Forum Stats
Member
Level 35
Programmer
Response to AS3 dynamic imports? 2009-09-14 16:04:24 Reply

I am not sure whether this will help or not, but you could take a look at FlexUnit and see if/how they implement what you want.

http://opensource.adobe.com/wiki/display /flexunit/FlexUnit


BBS Signature
West-End-Pro
West-End-Pro
  • Member since: Feb. 15, 2006
  • Offline.
Forum Stats
Member
Level 24
Blank Slate
Response to AS3 dynamic imports? 2009-09-14 16:22:46 Reply

flash.utils.getQualifiedClassName

I have a feeling this is the sort of thing that you're looking for, but I'm really not sure. No harm in trying it :)

henke37
henke37
  • Member since: Sep. 10, 2004
  • Offline.
Forum Stats
Member
Level 30
Blank Slate
Response to AS3 dynamic imports? 2009-09-15 03:05:41 Reply

This sounds like a standard preloading issue in an unusual shape. You got classes and you want them loaded, but you have no author time instances of them. Set them to export by force, problem solved.


Each time someone abuses hittest, God kills a kitten. Please, learn real collision testing.

Fickludd
Fickludd
  • Member since: Feb. 28, 2004
  • Offline.
Forum Stats
Member
Level 15
Blank Slate
Response to AS3 dynamic imports? 2009-09-15 03:26:45 Reply

At 9/14/09 04:04 PM, Tree-SkyLark-BCE wrote: http://opensource.adobe.com/wiki/display /flexunit/FlexUnit

Lol, FlexUnit actually seems to provide exactly what I need. Have to check it out when I get home but it should contain all solutions.

At 9/15/09 03:05 AM, henke37 wrote: This sounds like a standard preloading issue in an unusual shape. You got classes and you want them loaded, but you have no author time instances of them. Set them to export by force, problem solved.

I'm not sure what you mean... I know how to export classes without having instances, but don't want to export stuff - that's clumsy. The point is to get something JUnit-like that can be used for all my projects. Therefore I don't want to recompile the program for every project.

Ideal use case:

- run program

- specify .as file
If specified class extends TestBase: runs tests and display results. Repeat.

- be happy

hesselbom
hesselbom
  • Member since: Jul. 19, 2008
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to AS3 dynamic imports? 2009-09-15 04:17:55 Reply

At 9/15/09 03:26 AM, Fickludd wrote: Ideal use case:

Personally, I usually just opt for skipping to the last step. :)

mongoid
mongoid
  • Member since: Jan. 3, 2002
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to AS3 dynamic imports? 2009-09-15 04:30:40 Reply

Don't forget, in the publish settings you can set alternate source paths for as files, so the files you want to use shouldn't be limited to the same folder as the FLA.

henke37
henke37
  • Member since: Sep. 10, 2004
  • Offline.
Forum Stats
Member
Level 30
Blank Slate
Response to AS3 dynamic imports? 2009-09-15 08:55:27 Reply

Actionscript can not be run without being compiled into bytecode PERIOD.


Each time someone abuses hittest, God kills a kitten. Please, learn real collision testing.