actionscript 3 - Assigning Data to a Shared Object using a Variable's content as the identifier -


i have been musing on problem past few days, , whilst can find other people have had issues kind of revolve around use of dynamic variable names, none of solutions quite work trying do.

i have been using shared object (for purposed name sfsavedata) create local save file. same system has been used quite happily across several projects, code isn't overly portable. each project, have change class file incorporate each of settings/data stored. have brainwave - rather manually changing class creates/updates local save file, put necessary changes in xml file, , have class loops through xml , creates necessary data within shared object.

i have sussed out xml side of things, problem getting results correctly reference shared object. here's have working properly:

for completeness, extract xml file, @ moment working working 1 entry in file (no point in adding in more data until it's working)

<datafield label = "datafield">     <datatitle label = "datatitle">locationarray</datatitle>     <datatype label = "datatype">array</datalabel>     <datacontent label = "datacontent">[true, true, true, true, true]</datacontent> </datafield> 

notes: datapass custom event allows passing of data event. in instance passes variable containing xml content. data accessible via variable event.datpass. transferring correctly.

this in class file (savedatahandler) , file contains shared object ingamesettings. savedatahandler created instance. ingamesettings public class filled public static vars (including sfsavedata:sharedobject). , worth, folder structure /data/savedatahandler , /setting/ingamesettings.

function processsavexml(event:datapass):void {     var outputstring;     each (var datafield.xml in event.datpass) {         outputstring = (ingamesettings.sfsavedata.data." + datafield.datatitle);         /*         * goes wrong ;)         * access outputstring's content variable name, use "this".         * realise causes outputstring relate savedatahandler         * class rather ingamesettings class - part of problem         */         this[outputstring] = datafield.datacontent;         ingamesettings.sfsavedata.flush();     } // each loop }  // function processsavexml 

now if manually type in 1 of variable names - instance

ingamesettings.sfsavedata.locationarray = datafield.datacontent 

instead of

this[outputstring] = datafield.datacontent 

it works fine. problem don't know how content of outputstring used identifier variable on different class. error message:

referenceerror: error #1056: cannot create property ingamesettings.sfsavedata.data.locationarray on data.savedatahandler.

so, if can point me in right direction, i'd appreciative. i've lost lot of hair week because of this, want working neaten nasty hack in code of hard coded savedatahandler class.

function processsavexml(event:datapass):void { var outputstring; each (var datafield.xml in event.datpass) {     outputstring = datafield.datatitle;      ingamesettings.sfsavedata.data[outputstring] = datafield.datacontent;     // trick here. need refer "data" of so, , add     // what's in brackets make dynamic property.     ingamesettings.sfsavedata.flush(); } // each loop }  // function processsavexml 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -