Be a Supporter!

enterFrame alt for 3.0

  • 444 Views
  • 16 Replies
New Topic Respond to this Topic
Max-Vador
Max-Vador
  • Member since: Nov. 12, 2005
  • Offline.
Forum Stats
Member
Level 13
Animator
enterFrame alt for 3.0 2012-11-04 21:10:24 Reply

so with the on.enterFrame command gone in AS 3.0, i was wondering how i would execute this command and get the same effect with my effect.

here is the effect:
http://www.newgrounds.com/dump/item/a06a9d55c5847d7754f74787 589c20ef

the flames on the left use a MC code

onClipEvent (enterFrame) {
	gotoAndPlay(random(28)*0);
}

the slower flames on the left are using a frame command inside the MC

gotoAndPlay(random(28));

how can this be changed to AS 3.0 without losing the individual effects?

thanks for any help :D

egg82
egg82
  • Member since: Jun. 24, 2006
  • Offline.
Forum Stats
Supporter
Level 05
Game Developer
Response to enterFrame alt for 3.0 2012-11-04 21:38:27 Reply

At 11/4/12 09:10 PM, Max-Vador wrote: so with the on.enterFrame command gone in AS 3.0, i was wondering how i would execute this command and get the same effect with my effect.

here we go:
AS2 and AS3 are both event-driven. What does this mean?
it means you attach what's called an "event listener" function to Objects. What this does is listen for what's called an "event" to fire, and then run the function you gave it before.

an example:

stage.nativeWindow.addEventListener(Event.RESIZE, onWindowResize);

function onWindowResize(e:Event):void{
	//resize stage elements
}

that example will not work outside of an AIR application, and that was intentional. Don't just copy/paste, pay attention.

Q: Did you say AS2?
A: Yes, I did. AS2 is actually a lot more like AS3 than AS1. Thing is, AS2 allows AS1 practices such as

onClipEvent(enterFrame)

the difference here is AS3 doesn't allow that, so your programs come out more structured.

Q: Stage?
A: it's pretty much the equivalent to "_root" - which also means you should need to use it VERY RARELY. Don't abuse "this." and "stage.", and don't ever use "parent."

a few notes:
use FlashDevelop to program (it's free)
The Flash IDE was made for animators, and everything about its coding sucks. FlashDevelop was made for programmers, and has no paint bucket or pencil tool.

if you don't understand function, classes, public, private, etc. I suggest you take a look at "AS3, FD, and OOP the Right Way" - located in the link in my signature.


Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P

BBS Signature
Max-Vador
Max-Vador
  • Member since: Nov. 12, 2005
  • Offline.
Forum Stats
Member
Level 13
Animator
Response to enterFrame alt for 3.0 2012-11-04 21:50:05 Reply

thanks again egg

so both 2 and 3.0 have event listeners, but in 3.0 they must be defined, whereas 2.0 they were already defined(but limited to) load, enterFrame, etc?

i'll read up on your tutorials in your sig

MintPaw
MintPaw
  • Member since: Jun. 11, 2006
  • Offline.
Forum Stats
Member
Level 10
Programmer
Response to enterFrame alt for 3.0 2012-11-04 21:56:50 Reply

At 11/4/12 09:50 PM, Max-Vador wrote: thanks again egg

so both 2 and 3.0 have event listeners, but in 3.0 they must be defined, whereas 2.0 they were already defined(but limited to) load, enterFrame, etc?

i'll read up on your tutorials in your sig

Close, in AS1 the event was onClipEvent(enterFrame) in AS2 it's onEnterFrame = function() {} in AS3 you must define event listeners.


If ya have something to say, PM me. I have a lot of time to spare.
Also never PM egg82.

BBS Signature
Max-Vador
Max-Vador
  • Member since: Nov. 12, 2005
  • Offline.
Forum Stats
Member
Level 13
Animator
Response to enterFrame alt for 3.0 2012-11-04 22:01:17 Reply

okay, so 3.0 is closer to C+ in that it has unending variables but they are all user defined

MintPaw
MintPaw
  • Member since: Jun. 11, 2006
  • Offline.
Forum Stats
Member
Level 10
Programmer
Response to enterFrame alt for 3.0 2012-11-04 22:31:46 Reply

At 11/4/12 10:01 PM, Max-Vador wrote: okay, so 3.0 is closer to C+ in that it has unending variables but they are all user defined

Kinda, 2.0 is more like that. In AS2 mode you're allowed to write AS1 code, you'll pretty much have to accept that all AS2 you'll find or write is actually just AS1 from the 90s.


If ya have something to say, PM me. I have a lot of time to spare.
Also never PM egg82.

BBS Signature
Diki
Diki
  • Member since: Jan. 31, 2004
  • Online!
Forum Stats
Moderator
Level 13
Programmer
Response to enterFrame alt for 3.0 2012-11-04 23:24:54 Reply

At 11/4/12 10:01 PM, Max-Vador wrote: okay, so 3.0 is closer to C+ in that it has unending variables but they are all user defined

If that's a typo and you meant C++ then no, AS3 has little in common with C++ other than AS3 being a C-like language. Don't know what you mean by "unending variables" though.

egg82
egg82
  • Member since: Jun. 24, 2006
  • Offline.
Forum Stats
Supporter
Level 05
Game Developer
Response to enterFrame alt for 3.0 2012-11-04 23:52:49 Reply

At 11/4/12 11:24 PM, Diki wrote: If that's a typo and you meant C++ then no, AS3 has little in common with C++ other than AS3 being a C-like language. Don't know what you mean by "unending variables" though.

C-languages and ECMAScript languages are... About as far away as you can get.


Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P

BBS Signature
Diki
Diki
  • Member since: Jan. 31, 2004
  • Online!
Forum Stats
Moderator
Level 13
Programmer
Response to enterFrame alt for 3.0 2012-11-05 00:49:38 Reply

At 11/4/12 11:52 PM, egg82 wrote: C-languages and ECMAScript languages are... About as far away as you can get.

ECMAScript has some influence from C, hence it having near identical syntax, but in terms of functionality they're very different.
And if you want to get faaaaaarrr away from ECMAScript you can always look at Fortran, LISP, Forth, or if you're feeling in the mood for some punishment, COBOL.

But this is getting a tad off-topic. :)

milchreis
milchreis
  • Member since: Jan. 11, 2008
  • Offline.
Forum Stats
Member
Level 26
Programmer
Response to enterFrame alt for 3.0 2012-11-05 03:27:10 Reply

onEnterframe is available since As1, too.

The thing that makes it "As2" is it being a member of certain classes.

on() and onClipEvent() only work on one type of object each.
Additionally, they cannot be removed at runtime.

The event methods like onMouseDown are possibly defined by multiple classes. So you can treat them the same way.
Nesting does not work, with them. (button in button)

Some things still needed listeners.

These are 4 ways to handle events and they are not always interchangeable.

---

In As3 there's EventDispatcher, which a lot of classes extend.
It dispatches events.

Kind of a simplification I'd say.

Max-Vador
Max-Vador
  • Member since: Nov. 12, 2005
  • Offline.
Forum Stats
Member
Level 13
Animator
Response to enterFrame alt for 3.0 2012-11-05 15:53:44 Reply

so i took suggestions, i did some reading, and i got it working O_o

surprised myself too

this.addEventListener(Event.ENTER_FRAME, main);
function main(event:Event)
{
	flame.gotoAndPlay((int)(Math.random()*28));
}

thanks for all the help.
i'll probably stick to AS 1/2.0 for some of these simple frame actions, but i'm starting to get 3.0

milchreis
milchreis
  • Member since: Jan. 11, 2008
  • Offline.
Forum Stats
Member
Level 26
Programmer
Response to enterFrame alt for 3.0 2012-11-05 16:16:11 Reply

At 11/5/12 03:53 PM, Max-Vador wrote: this.addEventListener(Event.ENTER_FRAME, main);

As scope does not change the way it does in As1/2, you can omit "this." in most scenarios, including this one.

((int)(Math.random()*28));

There are 2 ways to do a cast in As3:

type(expression)
expression as type

As you can see, the braces around the type can be omitted.

You should be able to pass the Number without a cast and get the same result.

Max-Vador
Max-Vador
  • Member since: Nov. 12, 2005
  • Offline.
Forum Stats
Member
Level 13
Animator
Response to enterFrame alt for 3.0 2012-11-05 16:31:38 Reply

okay thanks.

never was good at cleaning up after myself

egg82
egg82
  • Member since: Jun. 24, 2006
  • Offline.
Forum Stats
Supporter
Level 05
Game Developer
Response to enterFrame alt for 3.0 2012-11-05 16:55:51 Reply

At 11/5/12 04:16 PM, milchreis wrote: type(expression)
expression as type

http://gskinner.com/talks/quick/#46


Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P

BBS Signature
milchreis
milchreis
  • Member since: Jan. 11, 2008
  • Offline.
Forum Stats
Member
Level 26
Programmer
Response to enterFrame alt for 3.0 2012-11-05 17:15:28 Reply

At 11/5/12 04:55 PM, egg82 wrote:
At 11/5/12 04:16 PM, milchreis wrote: type(expression)
expression as type
http://gskinner.com/talks/quick/#46

That's off topic.

egg82
egg82
  • Member since: Jun. 24, 2006
  • Offline.
Forum Stats
Supporter
Level 05
Game Developer
Response to enterFrame alt for 3.0 2012-11-05 17:21:47 Reply

At 11/5/12 05:15 PM, milchreis wrote: That's off topic.

I suppose, but my point was you should probably try to use type(expression)

function main(event:Event)

datatype variables, and give functions a return value. If you were using FlashDevelop (free coding IDE) it would yell at you.

also, I generally do e:Event, but that's just personal reference. I don't like carpel tunnel.


Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P

BBS Signature
Max-Vador
Max-Vador
  • Member since: Nov. 12, 2005
  • Offline.
Forum Stats
Member
Level 13
Animator
Response to enterFrame alt for 3.0 2012-11-05 18:47:50 Reply

understandable

i'm still learning so whatever you throw at me is a good thing

i read your tutorials egg, very helpful, especially on the if, else structure