You'd run into the same issue with setInterval.

When you specify a function reference like this there is no scope for that 
function, so the private var is not within the scope of the function.

Use the alternative call for setTimeout:

var delay = _global.setTimeout(this, 'delayedFunc', 1000 );

Or use Delegate:

var delay = _global.setTimeout( Delegate.create(this, delayedFunc), 
1000 );

In both cases you are providing the scope for which the function will 
have.


Derek Vadneau

----- Original Message ----- 
From: eric e. dolecki
To: Flashcoders mailing list
Sent: Thursday, June 07, 2007 1:17 PM
Subject: SPAM-LOW: [Flashcoders] Private var not accessible?


I have a simple class and I can't access a private var after using
setTimeout... I typed this up to show whats happening:

class foo extends MovieClip
{
private var nTime:Number = 0.75;
private var delay:Number;

function foo()
{
// stuff
};

public function doSomething():Void
{
trace( nTime ); // works fine [0.75]
var delay = _global.setTimeout( delayedFunc, 1000 );
};

private function delayedFunc():Void
{
trace( nTime ); //undefined ?
};
}

?? I could use setInterval and kill it after the first fire, but 
setTimeout
is nicer. This is AS2 obviously.

- eric


_______________________________________________
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

Reply via email to