Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > General > Gaming and Game Development

Reply
 
Thread Tools Rate Thread Display Modes
Old 04-21-2012, 07:18 PM   #1
TJRobertson86
Registered User
 
Join Date: Apr 2012
Posts: 37
Default [AS3] Setting up public variables and functions

EDIT: I forgot to mention this is in Actionscript 3

I'm creating a simple game, and it's my first time writing code in classes instead of the main timeline.

My question: if I add a public variable to a movieclip class (Player), am I able to reference that variable from the main document class? Or should I be putting all of my public variables and public functions on the document class?

Right now, when I add public variables or functions to one of my movieclip classes, the document class doesn't seem to be able to find it.

Let me know if I need to clarify the issue more.

Any help would be very appreciated.

Thank you
TJ

Last edited by TJRobertson86; 04-21-2012 at 11:35 PM.
TJRobertson86 is offline   Reply With Quote
Old 04-22-2012, 03:32 AM   #2
rrh
throw a trace() in there
 
Join Date: Dec 2006
Posts: 1,972
Default

Maybe you're confusing the class itself with instances of that class.

Code:
public class Foo {
  public function fooFighter() {

  }
  public static function fooMobile() {

  }
}


... meanwhile, in the document class ...

var f:Foo = new Foo(); //f is now an instance of a class named Foo

f.fooFighter(); //this works
Foo.fooFighter(); //this doesn't
Foo.fooMobile(); //this does
What you put in what function depends on what the function needs to do.
rrh is offline   Reply With Quote
Old 04-22-2012, 08:40 PM   #3
TJRobertson86
Registered User
 
Join Date: Apr 2012
Posts: 37
Default

thanks rrh! that makes a lot of sense
TJRobertson86 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 10:41 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2013, 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.