Tuesday, November 29, 2011

Floating working...

Got the listener issue from yesterday fixed finally after another misstep. So started working on the tiers. IE if you choose town then you can choose a location in town. Some how that is orphaning images again. My wall is slowly getting a deeper hole. Assuming I can get that fixed there is sill more to do the most difficult part or revolutionary is how to parse in variables by name (changing a string to a variable... Not really sure how to do that) or create a const variable sheet to be loaded and then referenced by xml. Why because I need to know what items the characters have in there inventory, what time of day it is, stuff that influences the options for the float. Tons more work a little time.

if anyone knows a way to change a parsed in string to reference an existing variable. I would be interested.



  1. Reference a variable by a string? The obvious way to do that is to put all your variables in an associative array.

    var variables:Object = new Object();
    variables["this_is_a_string"] = 69105;

    I know it's possible to get a *class* with a string specifying its classname, but I'm not sure about any specific variable. I'll have to research that one a bit more...

  2. Okay, I figured it out:

    var my_number:int = 13;
    trace("Number value: " + my_number);
    var name_of_var:String = "my_number";
    trace("Value of name_of_var: " + name_of_var);
    trace("Final try at number value: " + this[name_of_var]);

    So the proper syntax is "this[var]". I just stuck this in a Flash file and compiled it, and it worked. Of course, it was in global scope, but it should PROBABLY work in an object too. (In fact, I figured it was more likely to work in an object than in global scope!) Anyway, it's worth a shot.

  3. Yes and no. That will work, provided the variable exists within the scope of "this". If it's a local or global variable, that's probably good enough. If it's a property of something else, like a static class, however, you'd access it by using something like ClassName["variableName"].

    Flash treats dot notation and bracket notation as more or less equivalent, so ClassName.propertyName is basically the same as typing ClassName[propertyName]. The only difference is that the value within the brackets is evaluated before it's used to look up a value, so if propertyName is a string (for the sake of argument, less assume it contains "myVariable"), it will look for a property with the same name as that string (in this case, the one named "myVariable").

    I hope that made some kind of sense.