Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 08-31-2005, 08:43 AM   #1
hbd
B> 77's Adamsky
 
hbd's Avatar
 
Join Date: May 2005
Posts: 59
Default calling methods from "enterFrame" event in a class

Hi, I start using AS2 and class recently.

I have a problem with scope inside the class.
How do I call the function in the same class from within an "enterFrame" event of a MC? This was easy on a framescript, but so complicated inside the class.

ActionScript Code:
class chrControl extends MovieClip{ private static var speed =10 private var path:MovieClip pulic function chrControl(mc:MovieClip){ path = mc } //path is a _root timeline //chr is a MC on a _root public function walk():Void { path.chr.gotoAndPlay("walk") path.onEnterFrame = function() { this.chr._x += speed //I want to call this function checkPosition() if (this.chr._x>this._xmouse) { //I want to call this function chrStop() }}} private function checkPosition(){trace("check")} private function chrStop(){trace("stop")} }

above method call neither checkPosition() nor chrStop() . Should I use delegate class?
any help would be appreciated.

Last edited by hbd; 08-31-2005 at 10:47 AM.
hbd is offline   Reply With Quote
Old 08-31-2005, 10:41 AM   #2
senocular
six eyes
 
senocular's Avatar
 
Join Date: Jan 2003
Location: San Francisco, CA (USA)
Posts: 7,875
Send a message via ICQ to senocular Send a message via AIM to senocular Send a message via MSN to senocular Send a message via Yahoo to senocular
Default

yes, use Delegate
__________________
(6)
senocular is offline   Reply With Quote
Old 08-31-2005, 11:53 AM   #3
hbd
B> 77's Adamsky
 
hbd's Avatar
 
Join Date: May 2005
Posts: 59
Default

thx.
I'm trying to understand "delegate" but I have no idea how to apply it in this case. Is there a good tutrial about this? I checked several sites, but couldn't find the one that explain enterFrame event.

ActionScript Code:
import mx.utils.Delegate; class chrControl extends MovieClip { private static var speed = 10; private var path:MovieClip; function chrControl(mc:MovieClip) { path = mc; } //path is a _root timeline //chr is a MC on a _root public function walk():Void { path.chr.gotoAndPlay("walk"); path.addEventListener("enterFrame", Delegate.create(this, checkPosition)); path.addEventListener("enterFrame", Delegate.create(this, chrStop)); path.onEnterFrame = function() { this.chr._x += speed; //I want to call this function checkPosition(); if (this.chr._x>this._xmouse) { //I want to call this function chrStop(); }}} private function checkPosition(eventObj:Object) {trace("check")} public function chrStop(eventObj:Object) { trace("stop"); path.chr.gotoAndPlay("stop"); delete (path.onEnterFrame); }}
hbd is offline   Reply With Quote
Old 08-31-2005, 12:25 PM   #4
senocular
six eyes
 
senocular's Avatar
 
Join Date: Jan 2003
Location: San Francisco, CA (USA)
Posts: 7,875
Send a message via ICQ to senocular Send a message via AIM to senocular Send a message via MSN to senocular Send a message via Yahoo to senocular
Default

not sure why you are using addEventListener - that really doesnt apply.

Maybe this can help:
http://www.kirupa.com/web/xml/XMLspecificIssues3.htm

same concept, different context. Delegate is given as an example
__________________
(6)
senocular is offline   Reply With Quote
Old 08-31-2005, 01:10 PM   #5
hbd
B> 77's Adamsky
 
hbd's Avatar
 
Join Date: May 2005
Posts: 59
Default

thx for the link. it's working now.

ActionScript Code:
import mx.utils.Delegate; class chrControl extends MovieClip {     private static var speed = 10;     private var path:MovieClip;     function chrControl(mc:MovieClip) {         path = mc;     }     //path is a _root timeline     //chr is a MC on a _root     public function walk():Void {         path.chr.gotoAndPlay("walk");         path.checkPosition = Delegate.create(this, checkPosition);         path.chrStop = Delegate.create(this, chrStop);         path.onEnterFrame = function() {             this.chr._x += speed;             //I want to call this function             checkPosition();             if (this.chr._x>this._xmouse) {                 //I want to call this function                 chrStop();             }         };     }     private function checkPosition() {         trace("check");     }     public function chrStop() {         trace("stop");         path.chr.gotoAndPlay("stop");         delete (path.onEnterFrame);     } }
hbd is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:46 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.