> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:flashcoders-
> [EMAIL PROTECTED] On Behalf Of Steven Sacks | BLITZ
> Sent: Wednesday, November 08, 2006 10:24 AM
> To: Flashcoders mailing list
> Subject: RE: [Flashcoders] EventDispatcher and onEnterFrame....
problems
>
> Inside an onEnterFrame function you have to use "this" when referring
to
> things in the class (if the class extends MovieClip, which I hope it
> does because only MovieClips can have onEnterFrame as far as I know).
>
>
> class MyClass
> {
> var foo:Boolean;
>
> function MyClass()
> {
> this.onEnterFrame = function()
> {
> this.foo = !this.foo;
> this.traceFoo();
> }
> }
> function traceFoo()
> {
> trace(foo);
> }
> }
But you could just write it this way:
class MyClass extends MovieClip {
private var foo:Boolean = false;
public function MyClass() {
}
public function traceFoo() {
trace(foo);
}
private function onEnterFrame():Void {
foo = !foo;
traceFoo();
}
}
Or even like this:
class MyClass extends MovieClip {
private var foo:Boolean = false;
public function MyClass() {
onEnterFrame = toggleAndTraceFoo;
}
public function traceFoo() {
trace(foo);
}
private function toggleAndTraceFoo():Void {
foo = !foo;
traceFoo();
}
}
(Me, I prefer to use an event dispatcher that sends "enterFrame" events,
but I'll admit that that's often overkill.)
―
Mike Keesey
_______________________________________________
[email protected]
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