TwelvestoneFlash

AS2 targeting a function within a class


Sign in

  • Waiting for Godot ( 730 k posts )
    Just conversation.
  • Thunder Dome ( 23 k posts )
    Photoshop Tennis and Collabs.
  • Photography ( 5.1 k posts )
    For all you shutterbugs, sh...
  • Flash ( 18 k posts )
    ActionScripting to tweens, ...
  • Front End ( 5.9 k posts )
    general front end design an...
  • Back End ( 9.7 k posts )
    serverside scripting, progr...
  • Projects and Theory ( 12 k posts )
    This forum is for discussio...
  • FAQ ( 269 posts )
    All those nagging questions...
  • Design ( 17 k posts )
    graphics & all aspects of g...
  • Purgatory ( 3.6 k posts )
    12stone Jail, feel free to ...
WingNut
 
2008-09-18

as2

hey, from outside a class, how do you control a function inside that class?

i want to do something like:

doFunction();

and inside the class MyFancyClassName is the function

public function doFunction() { doTotallyAwesomeStuff(); }

where is that function available? on the root?

Arsis
 
2008-09-19

classInstance.function()

WingNut
 
2008-09-19

so according to my above example, would that be:

MyFancyClassName.doFunction();

when i try that, i get this error:

There is no method with the name 'doFunction'.

please excuse my asking what i'm sure are somewhat idiotic questions, i'm not the best actionscripter and just barely venturing into classes.

thanks for the help

scudsucker
 
2008-09-19

As Arsis pointed out - you need to address an instance of the class.

var fancyPants:MyFancyClassName=new MyFancyClassName(); fancyPants.doFunction();

WingNut
 
2008-09-20

thanks guys

persist
 
2008-09-21

You can do this:

MyFancyClassName.doFunction();

without making a new instance of the class when the class is written as:

class MyFancyClassName { function MyFancyClassName() { } static function get doFunction():Void { trace("ok"); } }

WingNut
 
2008-09-21

good to know, thanks.

good to see you around.

Sorry, you must be a member to post to a conversation. Either log in or sign up to get involved.
TwelvestoneFlash

AS2 targeting a function within a class