Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 06-23-2012, 12:48 PM   #1
smks
Registered User
 
Join Date: Dec 2011
Posts: 20
Default Accessing movieclip using this? classes

Hello I have hard coded a game using the timeline. I want to transition to using document and separate classes. i have made a player class and added private functions that is keyUpFunction and keyDown to move the player. And added movePlayer function in document class.

I have exported a movieclip for actionscript linked to player class that has seperate frames for animation:

frame 1 label "stand"
frame 2 label "walkLeft"
frame 3 label "walkRight"

in my function on keypress Keyboard.RIGHT I want it to goToAndStop("walkRight")

I do not know how to reference it when it is not added to stage (no instance is chosen) if ya understand?

i tried this.gotoandstop('walkRight') but it does not work? so if i was to add 2 childs of the player on stage I cannot use dot notation to reference both to work?

if i was to use player1.gotoAndStop('walkRight') it would work?

thanks
smks is offline   Reply With Quote
Old 06-24-2012, 01:21 AM   #2
CodeVisual
Registered User
 
Join Date: Jun 2012
Location: USA
Posts: 27
Send a message via Yahoo to CodeVisual
Default

If I understand correctly, you have your player functionality inside a "player" class? So your trouble is referencing your player class when it is not added to the stage?

Code:
var player:Player = new Player();
player.gotoAndStop("stand");
To access the timeline from inside the player class, this.gotoAndStop() should work, can you paste your code?
CodeVisual is offline   Reply With Quote
Old 06-24-2012, 11:28 AM   #3
smks
Registered User
 
Join Date: Dec 2011
Posts: 20
Default

I get confused with where I add the instance is it in document class? because if it is then how is this referenced in the keyup and keydown functions that are in player class if i wanted to put movePlayer function into player class?

This is not syntactically correct just used to understand problem

document class
Code:
var player:Player = new Player();
player.gotoAndStop("stand");

function movePlayer () {
if (walkingLeft) 
{player.x -= playerSpeed;}
if (walkingRight) += playerSpeed;
etc...
}
Player Class

Code:
if (leftArrow) {
walkingLeft = true;

etc....
else if(rightArrow)
walkingRight = true;
}
smks is offline   Reply With Quote
Old 06-24-2012, 05:13 PM   #4
CodeVisual
Registered User
 
Join Date: Jun 2012
Location: USA
Posts: 27
Send a message via Yahoo to CodeVisual
Default

Yes, you add the instance of your class inside the document class. I believe the best way to do this is to not have any "moving" logic inside your player class. Add the Event Listeners inside the document class, and then simply move the player with it's MovieClip attributes (Because your player class derives from MovieClip).
CodeVisual is offline   Reply With Quote
Old 06-25-2012, 01:16 PM   #5
smks
Registered User
 
Join Date: Dec 2011
Posts: 20
Default

Thank you. v appreciated
smks 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 On
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.