Skip to main content
July 26, 2007
Question

AS 3.0 Class question...

  • July 26, 2007
  • 14 replies
  • 700 views
I've created a class in flash. I don't want to make the document class this class because then I need to import the other classes into this class that I'm using in my movie. I use a dummy clip to bring the class into my movie.

On a button's function located in the fla, how do I call a function that is in that class? Or am I doing something wrong?

I have a class called "TestClass" and a function in it called init(); I just want to call init() from my main fla timeline, why doesn't this work?

init();
or
TestClass.init();
???

Thanks,
This topic has been closed for replies.

14 replies

Inspiring
July 27, 2007
>>(if TestClass is the class name, TestClass.init(); will work if init() is
>>a public static method.)

I see what you meant, right... <g>

--
Dave -
Head Developer
http://www.blurredistinction.com
Adobe Community Expert
http://www.adobe.com/communities/experts/


kglad
Community Expert
Community Expert
July 27, 2007
(if TestClass is the class name, TestClass.init(); will work if init() is a public static method.)
Inspiring
July 26, 2007
@ Patrick:

"This is a very effective memory management technique and can
be used for almost all methods (most, after all, don't need to be copied
to perform the same functions). "

> I thought the idea with instances is that the actual functions are not copied to the instances, but each instance's method call references a single definition of the method at the prototype level... is this correct or not - perhaps I don't understand things as well as I thought? - it wouldn't be the first time, lol
{I do understand that even if my original assumption were true, maintaining each reference to the prototype occupies memory.}



Inspiring
July 26, 2007
Honestly, with a name like C-Rock, how could we resist?!

C-Rock wrote:
> okay, thanks for your help guys.

--
http://www.baynewmedia.com
Faster, easier, better...ActionScript development taken to new heights.
Download the BNMAPI today. You'll wonder how you ever did without it!
Available for ActionScript 2.0/3.0.
July 26, 2007
okay, thanks for your help guys.
Inspiring
July 26, 2007
"Static" means that one copy is ever held in memory, and this is done in
the prototype class, not in any instance. That means that you don't need
to create an instance of the class in order to use the method or
property. This is a very effective memory management technique and can
be used for almost all methods (most, after all, don't need to be copied
to perform the same functions). There is an entire type of programming
called the Singleton pattern which advocates the use of static methods
and properties.

Patrick

GWD wrote:
> "what are "static" functions all about? if i make my class functions static
> can i just make regular calls to them?"
>
> The way I like to think about static methods is like comparing to something
> like the Math class.
>
> You don't make instances of the Math class (e.g. you don't do var myMath:Math
> = new Math() ) - you just use Math.something().
>
> Of course you can have a class with both static methods or properties - or
> constants - and instance-based properties and methods. I can't think of an
> example off-hand - but there are plenty of component classes where the class
> has static properties as constants. E.g. FLVPlayback.BUFFERING
>
> I hope that makes some sense. Once you get to the "aha!" moment with OOP you
> start doing almost everything away from the timeline - because it just seems to
> make sense.
>
>
>

--
http://www.baynewmedia.com
Faster, easier, better...ActionScript development taken to new heights.
Download the BNMAPI today. You'll wonder how you ever did without it!
Available for ActionScript 2.0/3.0.
Inspiring
July 26, 2007


"what are "static" functions all about? if i make my class functions static can i just make regular calls to them?"

The way I like to think about static methods is like comparing to something like the Math class.

You don't make instances of the Math class (e.g. you don't do var myMath:Math = new Math() ) - you just use Math.something().

Of course you can have a class with both static methods or properties - or constants - and instance-based properties and methods. I can't think of an example off-hand - but there are plenty of component classes where the class has static properties as constants. E.g. FLVPlayback.BUFFERING

I hope that makes some sense. Once you get to the "aha!" moment with OOP you start doing almost everything away from the timeline - because it just seems to make sense.

July 26, 2007
looks like i just need to learn a little more about call functions in a class.

i've always just made all my functions inside my main fla on a functions layer in the second frame.

i was trying to go to the next level in programming by using other classes and such and as 3.0.

i just don't understand how to make a simple call to a class function and how to have that function interact with the stage.

i can't even get a class function to write to a text box on the stage..... grrrr....

what are "static" functions all about? if i make my class functions static can i just make regular calls to them?

as 3.0 is harder but better i'm sure! grrr again....
Inspiring
July 26, 2007
Actually I was trying (and failed miserably) to give illustrative examples of both per instance and static methods.

Inspiring
July 26, 2007
>>that will work if TestClass is a public class in your swf's path and
>>init() is a public static method of TestClass.

Hate when I do that... I just wanted to clarify here - init would not have
to be static, since the class got instantiated with new. So it'd be an
instance method.

--
Dave -
Head Developer
http://www.blurredistinction.com
Adobe Community Expert
http://www.adobe.com/communities/experts/