Wednesday, December 14, 2011

Still stumped...


This seemed to me like the perfect answer...

http://www.actionscript.org/forums/showthread.php3?t=145584

Since my idea of sending in the base stage didn't work.

With some help from

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/package.html#getDefinitionByName()

I still get nothing... I'm starting to think it might be a good idea just to make 5 different versions for the classes that hold data. But I really wanted to level up with a cool new trick. Anyone got any suggestions.

I did try John's idea of making an object of it. And well the above is just a more complicated version of that neither worked for me.

I also tried compuscribes

this[data][variable] by parsing in this[classname][variablename] that failed also tried from base stage. I don't know... I feel like I'm just missing one key word or something.

Daisy

3 comments:

  1. Have you tried removing the "getQualifiedClassName" bit? It seems to me like it might not be necessary. I'm far from 100% sure, but if you have a string whose value is "otherlib.GameData" then you should be able to pass that to getDefinitionByName and get a new otherlib.GameData instance.

    To me it looks like "getQualifiedClassName" is meant to be called on an *object* so you can get its class name. If you already have the class name as a *string*, then you don't need it.

    Of course, looking at your code, it seems like even if it works you'll end up with a *new* otherlib.GameData object. It'll be completely blank, uninitialized and separate from any *other* GameData objects that might be hanging around. ...UNLESS you do a singleton thing, but you'd need to be calling a class method, right?

    ReplyDelete
  2. Here's a bit of code that will help you turn "dot notation" into values. It might be another piece of the puzzle.


    var argh0:Object = new Object();
    argh0["bleh1"] = new Object();
    argh0["bleh1"]["bleh2"] = new Object();
    argh0["bleh1"]["bleh2"]["bleh3"] = "fneee";

    trace("11b: " + argh0.bleh1.bleh2.bleh3);
    // As we can see, the value of argh0.bleh1.bleh2.bleh3 is "fneee".
    // But how do we get to that value with just strings? Here's how:
    var var_name0:String = "argh0.bleh1.bleh2.bleh3";

    var var_array0:Array = var_name0.split(/\./);
    trace("12: " + var_array0);
    var temp_name:Object;
    var temp_var:Object;
    while ((temp_name = var_array0.shift()) != undefined)
    {
    if (temp_var == undefined)
    temp_var = this[temp_name];
    else
    temp_var = temp_var[temp_name];
    //trace("value: " + temp_var);
    //trace("var: " + temp_name);
    }
    trace("Loop end. Final value: " + temp_var);

    ReplyDelete
  3. Not 100% sure, since I haven't coded AS3 yet, but I think the problem is

    var instance: **CLASS**

    You're trying to instantiate a String, as far as I can tell, so I think it would have to be either
    var instance:String = new Definition()
    or
    var instance:Object = new Definition() (in case you need to be more generic)

    The error message seems to fit this; "" (a string) cannot be converted to a class (an object which describes a class).

    At least, that's how it would work in C#. ^^

    gl fixing this
    Chris132

    ReplyDelete