Action Script 3 functions
- Started
- Last post
- 13 Responses
- CyBrain
I'm new to Actionscript 3 after years of AS2, which is like a blind man on the freeway thinking he might be able to see.
I'm trying to call a function. from a .as file and I'm stumped.
Here's my .as file script: package {
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;
public class Counter {
public function Counter() {
// NO CLUE WHAT TO PUT HERE BUT MAKE THE NEXT FUNCTION WORK.
}
private function countNow():void {
trace("included");
}
}
}and I want to call a function countNow() on the main timeline on a frame.
import Counter; is on frame 1 and my .as file is named Counter.as
Help? Thanks in advance.
- Hurley0
they really screwed you guys over with this action script 2 vs 3 didnt they
- They've threatened my career. I'm years behind what my AS2 skills were.CyBrain
- True, AS3 has been a real challenge, I felt comfortable in 95% of AS2, now struggling. need a month of studythreadpost
- Hurley, are you an AS3 developer? if so, and you're good+fast, I might could hire u for some help, email me.threadpost
- KarlFreeman0
It depends if this .as is your base class for the main file or your importing this in to your base class?
if its your base class then something like this would work?
package {
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;
public class Counter {
public function Counter() {
this.addEventListener(Event.ADDE... stageInit);
}
private function stageInit(event:Event) : void {
//add some sort of user interaction to call CountNow
}
private function countNow():void {
trace("included");
}
}
}
- KarlFreeman0
** re edit...
package {
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;
public class Counter extends Sprite {
public function Counter() {
this.addEventListener(Event.ADDE... stageInit);
}
private function stageInit(event:Event) : void {
//add some sort of user interaction to call CountNow
}
private function countNow():void {
trace("included");
}
}
}
- Pupsipu0
to call countNow() from a different file, it has to be
public function countNow(),
and you have to say in that other file
import Counter;
var cnt:Counter = new Counter()
cnt.countNow()if you want to run countNow() from inside that Counter class, you say
public function Counter() {
// NO CLUE
countNow() //and keep countNow private.
}it's not really AS3 vs AS2, it's OOP vs Procedural. People were doing the same crazy shit in AS2 with prototypes and classes and it was a big mess to make things OOP.
- dijitaq0
this is how you do it:
Counter(root).countNow();
- vaxorcist0
Java programmers I know love AS3, whereas most of the AS2 designer/programmers I know hate AS3....
Is there a "meta-language" or "framework" that's well supported that makes it possible to do a few often-done things in AS3 without replicating all the grunt-work? I'm thinking of something like RubyOnRails or Django?
- I know there are people out there who love AS3 but I'm guessing that' about 2% of the people who use Flash.CyBrain
- threadpost0
I dont hate AS3, everyone I've spoken to including most of my Flash friends who consider themselves designers first and foremost, say that once you really "get" AS3, it's a huge advantage. Like I mentioned in my comment to Hurley above, I just haven't had the luxury of taking on that learning curve. So then, if there are any good AS3 developers looking for some freelance, email me. I've been getting a lot of projects I had to pass on recently b/c of the learning curve hurdle.
- Pupsipu0
Flex, Craighorn, PureMVC, GAIA
- kumori040
I didn't believe the hype at first, either. Did AS2 for three years, had to learn AS3 for a project at work. But now I prefer AS3, and sometimes can't remember how to develop in AS2.
- I can see my myself seeing it that way in months or probably years, but I can hardly put a button script together now.CyBrain
- heavyt0
that is a method, not a function. A private one, too.
- tommyo0
3 months ago, hated AS3.
Today, love AS3.AS3 I <3 YOU.
- threadpost0
Any AS3 peeps with a week or two on their hands that want some work, email me please. Could lead to lots more too.