Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411695 Posts in 69399 Topics- by 58454 Members - Latest Member: roeyskatt

May 18, 2024, 09:10:48 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)AS3 emergency! Help! (Not emergency anymore)
Pages: [1]
Print
Author Topic: AS3 emergency! Help! (Not emergency anymore)  (Read 1260 times)
rogerlevy
Guest
« on: April 09, 2009, 12:18:20 PM »

Guys, I am in a crunch time and I need some serious help because this is due Monday EOB.  I hope someone can help me out.

I have an multidimensional static array containing data about the game's missions.  In one of the columns, I want to store the class of the background used in each mission.  I can do this, but, when it comes time to instantiate it, it seems impossible to do!  Has anyone ever  done instantiation of unknown classes?  Is this even possible?  The constructors' parameters  for the various backgrounds are uniform - no parameters. 

I hope that I can get a quick response.  I need to get this resolved like 20 minutes ago.  If this isn't possible then I'm open to reasonable alternatives that wouldn't add too much complication.

I will love you guys forever if you can help me...

EDIT:

NEVERMIND. I am just going to use a dumb case statement for now. This is not what I wanted because it fragments the information but I don't have time to fuss with this anymore.

Anyway, topic's still open for discussion.
« Last Edit: April 09, 2009, 12:21:22 PM by rogerlevy » Logged
Ivan
Owl Country
Level 10
*


alright, let's see what we can see


View Profile
« Reply #1 on: April 09, 2009, 12:38:14 PM »

There's a Class class in AS3 that you can use to instantiate arbitrary-named classes. And there's a getDefinition method in ApplicationDomain that you can use to get it by string.

So you can do something like this, (where appDomain is your ApplicationDomain):

Quote
var dynClass:Class = appDomain.getDefinition("MyMovieClipSublass") as Class;
var myMovieClip:MovieClip =  new dynClass() as MovieClip;
Logged

http://polycode.org/ - Free, cross-platform, open-source engine.
BorisTheBrave
Level 10
*****


View Profile WWW
« Reply #2 on: April 10, 2009, 04:59:24 AM »

There's a massive gotcha here, though I'm not sure if it applies to ApplicationDomains as well as flash.utils.getDefinitionByName. It's that it can only load classes that have actually been compiled (obviously), and classes with no references won't be.
So you need to have some block of code somewhere with
Code:
MyClass1;
MyClass2;
//etc.
This is possibly what your original problem was, and why the case statement fixed it?
Logged
grapefrukt
Level 1
*



View Profile WWW
« Reply #3 on: April 14, 2009, 03:30:27 AM »

If you store the class in the array in one place as such:
Code:
var levelArray:Array = new Array()
levelArray.push(MyLevelClass);
The class will be included in your swf since it is mentioned in the code. If you reference it using a string it wont be, so make sure it's a reference to the class.

To instantiate from this later you do like so:
Code:
var levelClass:Class = levelArray[index];
var levelInstance:MyLevelSuperClass = new levelClass();

Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic