PDA

View Full Version : String class reference oddness..


Stimpson
08-05-2004, 10:29 AM
Hey people :).

Does anyone know why this does work:

var easeClass=mx.transitions.easing["Elastic"];
trace(easeClass); // traces '[type Function]'

As supposed to this:

var classID:String="Elastic";
var easeClass=mx.transitions.easing[classID];
trace(easeClass); // traces 'undefined'

And to make it more weird, this makes it work again:

import mx.transitions.easing.*;

trace(Elastic); // traces '[type Function]'

var classID:String="Elastic";
var easeClass=mx.transitions.easing[classID];
trace(easeClass); // traces '[type Function]'

I'm puzzled :confused:

pavanathreya12
08-05-2004, 10:39 AM
really its so confused anyone lets find it with Jesse i will PM him

senocular
08-05-2004, 10:57 AM
Flash optimizes your movie by only compiling/including classes that you use - not every class your movie potentially has access to. Flash knows how to do this by searching through your actionscript and finding the paths of the classes you use. When a path to a class is found, its included into your swf and available for use.

So, because of this, with your non-working example, what you are effectively doing is tricking Flash by not letting it be able to tell which easing class you intend to use by placing a variable (which could be anything) in place of the actual class name. Flash doesnt know whats to be used so doesnt include anything.

Stimpson
08-05-2004, 11:03 AM
Hmm... thx senocular, good explenation :).

You know a way around this perhaps? I need to supply the class name to a method, as a string, and then reference it (through mx.transitions.easing)... without supplying the actual class itself to the method to use.

Stimpson
08-05-2004, 11:12 AM
Ok, I'll just call all the needed classes at init():

Back;
Elastic;
Strong;

etc....

That will make the string classId reckognizable in the method, feels odd going about it this way though.

senocular
08-05-2004, 11:17 AM
yeah its just one of those things :-/

Stimpson
08-05-2004, 11:19 AM
Hmmm..... yeah... :rolleyes:. Ah well, it works :).