  | |  | Variable scope in AS2 | Variable scope in AS2 2004-03-11 - By Liam Egan
Back That makes sense to me, try this instead;
private function doSomething() { trace("2 _"+someNumber); trace("2.1 _"+someOtherNumber); var objParent=this; var interval = setInterval(function () { trace("3 _"+ objParent.someNumber); trace("3.1 _"+ objParent.someOtherNumber); clearInterval(interval); }, 100); }
-- --Original Message-- -- From: janis@(protected) [mailto:janis@(protected)] Sent: Friday, March 12, 2004 10:01 AM To: flashcoders@(protected) Subject: [Flashcoders] Variable scope in AS2
Just found IMO veirdnes while working with AS2: class someClass { private var someNumber:Number = 1; public var someOtherNumber:Number = 2; function someClass() { trace("1 _"+someNumber); trace("1.1 _"+someOtherNumber); doSomething(); } private function doSomething() { trace("2 _"+someNumber); trace("2.1 _"+someOtherNumber); var interval = setInterval(function () { trace("3 _"+someNumber); trace("3.1 _"+someOtherNumber); clearInterval(interval); }, 100); } } will return 1 _1 1.1 _2 2 _1 2.1 _2 3 _undefined 3.1 _undefined
Seems that second level functions, intervals(wich are same actually) cannt see class body variables and it doesnt depend on variable type. I havent spend mutch time on AS2 so I can imagine this been misunderstanding bcouse of lack of AS2 expierience ... or this is a way it should be?
Janis
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -- Supported by Fig Leaf Software =-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -- Be sure to check the archives and the wiki: http://chattyfig.figleaf.com/ =-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -- http://chattyfig.figleaf.com/cgi-bin/ezmlm-cgi?1:mss:106693 =-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -- To unsubscribe send a blank e-mail to: Normal Mode: flashcoders-unsubscribe@(protected) Digest Mode: flashcoders-digest-unsubscrive@(protected)
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -- Supported by Fig Leaf Software =-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -- Be sure to check the archives and the wiki: http://chattyfig.figleaf.com/ =-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -- http://chattyfig.figleaf.com/cgi-bin/ezmlm-cgi?1:mss:106695 =-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -- To unsubscribe send a blank e-mail to: Normal Mode: flashcoders-unsubscribe@(protected) Digest Mode: flashcoders-digest-unsubscrive@(protected)
Earn $52 per hosting referral at Lunarpages.
|
|
 |