RE: Re[2]: [Flashcoders] Identifier expected
>>You are not right, it is totally acceptable and correct, I >>think you are mixing something up :) I understand what you're saying, but in context of what he's trying to do (inline object declaration), explain the compiler error on this code: function createData():Void { this._data = new Object(); this._data["a"] = {"t1":0, "t2":0}; trace(this._data.a.t1) } createData(); So instead, this is ugly, but works: function createData():Void { this._data = new Object(); this._data["a"] = new Object(); this._data["a"].t1 = 0 this._data["a"].t2 = 0 trace(this._data.a.t1) } createData(); Jason Merrill Bank of America Learning & Organizational Effectiveness >>-Original Message- >>From: [EMAIL PROTECTED] >>[mailto:[EMAIL PROTECTED] On Behalf >>Of Rákos Attila >>Sent: Friday, February 09, 2007 2:31 PM >>To: Flashcoders mailing list >>Subject: Re[2]: [Flashcoders] Identifier expected >> >> >>MJ> That's because you're still not refrencing an object that exists: >>MJ> >this._data["a"] = new Object(); >>MJ> >>MJ> You're saying, Hey, _data, make your "a" property an object. But >>MJ> Flash is saying, hold on cowboy, I don't see any property >>of _data called "a". >> >>You are not right, it is totally acceptable and correct, I >>think you are mixing something up :) >> >> Attila >> >>___ >>Flashcoders@chattyfig.figleaf.com >>To change your subscription options or search the archive: >>http://chattyfig.figleaf.com/mailman/listinfo/flashcoders >> >>Brought to you by Fig Leaf Software >>Premier Authorized Adobe Consulting and Training >>http://www.figleaf.com http://training.figleaf.com >> ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
RE: Re[2]: [Flashcoders] Identifier expected
Stop using new Object() and use {}; :) I'm not experiencing the same issue you're having Jason. Not sure why. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
RE: Re[2]: [Flashcoders] Identifier expected
I didn't even notice that in the script before - should have been obvious. Sorry for the noise. Jason Merrill Bank of America Learning & Organizational Effectiveness >>-Original Message- >>From: [EMAIL PROTECTED] >>[mailto:[EMAIL PROTECTED] On Behalf >>Of Rákos Attila >>Sent: Friday, February 09, 2007 3:13 PM >>To: Flashcoders mailing list >>Subject: Re[2]: [Flashcoders] Identifier expected >> >> >>MJ> OK, I see, so then curious why this script returns >>compiler errors: >>MJ> >>MJ> function createData():Void { >>MJ> this._data = new Object(); >>MJ> this._data["a"] = new Object(); >>MJ> this._data["a"] = {"t1":0, "t2":0}; } >> >>Because when using the object initializer operator, you >>cannot use strings as identifiers (similarly to variable declaration). >>In the above script the this._data["a"] = new Object(); line >>is simply not necessary, and the right syntax of the last one is: >> >>this._data["a"] = {t1:0, t2:0}; >> >>or even better: >> >>this._data.a = {t1:0, t2:0}; >> >> Attila >> >>___ >>Flashcoders@chattyfig.figleaf.com >>To change your subscription options or search the archive: >>http://chattyfig.figleaf.com/mailman/listinfo/flashcoders >> >>Brought to you by Fig Leaf Software >>Premier Authorized Adobe Consulting and Training >>http://www.figleaf.com http://training.figleaf.com >> ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: Re[2]: [Flashcoders] Identifier expected
It's nothing to do with the 'a', it's the 't1' and such in quotes that's the issue. >>MJ> function createData():Void { >>MJ> this._data = new Object(); >>MJ> this._data["a"] = new Object(); >>MJ> this._data["a"] = {"t1":0, "t2":0}; } // The quotes in this line are wrong Won't compile. This will: >>MJ> function createData():Void { >>MJ> this._data = new Object(); >>MJ> this._data["a"] = new Object(); // Note this line is totally pointless >>MJ> this._data["a"] = {t1:0, t2:0}; } // This line is now correct Incidentally, the third line is completely redundant. This is correct: >>MJ> function createData():Void { >>MJ> this._data = new Object(); >>MJ> this._data["a"] = {t1:0, t2:0}; } Because new Object() and {} are synonymous. var data:Object=new Object(); data['a']={t1:0,t2:0}; is exactly equal to: var data:Object=new Object(); data['a']=new Object(); data['a']['t1']=0; data['a']['t2']=0; which is also equal to: var data:Object={a:{t1:0,t2:0}}; or, because Object is dynamic var data:Object=new Object(); data.a=new Object(); data.a.t1=0; data.a.'t2=0; To recap - the error was putting quotes in the key names. HTH, Ian ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: Re[2]: [Flashcoders] Identifier expected
var data:Object=new Object(); data.a=new Object(); data.a.t1=0; data.a.'t2=0; Whoops - a stupid stray quote in the last line. Should of course have been: data.a.t2=0; Ian ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com