Forum Topic: As 3.0!

(686 views • 33 replies)

This topic is 2 pages long. [ 1 | 2 ]

<< < > >>
None

JD77

Reply To Post Reply & Quote

Posted at: 7/7/06 10:21 AM

JD77 NEUTRAL LEVEL 17

Sign-Up: 03/30/05

Posts: 1,062

Well as most of you know, flash 9 got released. So i went and tried it out, It isnt that different from AS2!. And it lags a fuck less. Here are some samples! of it's leet ness!.

AS 2.0 (warning it lags! :P)

AS 3.0!

The purpouse of this test is to show people that AS3.0 aint that hard, if you knew AS 2.0, And to show off flash player 9!

*User Page under construction*

BBS Signature

None

Shazamboobam

Reply To Post Reply & Quote

Posted at: 7/7/06 10:26 AM

Shazamboobam EVIL LEVEL 07

Sign-Up: 05/21/06

Posts: 42

thats koo thx 4 showin us a preveiw


None

TrueDarkness

Reply To Post Reply & Quote

Posted at: 7/7/06 10:26 AM

TrueDarkness EVIL LEVEL 27

Sign-Up: 08/31/04

Posts: 4,718

Just because you posted 2 examples doesn't mean that you scripted them. You say that it isn't hard at all, yet half of the best scripters here in the flash forum can't figure out how to make something move. Just seems odd, could you post a script please? I'm curious to see how it works


None

GuyWithHisComp

Reply To Post Reply & Quote

Posted at: 7/7/06 10:28 AM

GuyWithHisComp LIGHT LEVEL 24

Sign-Up: 11/10/05

Posts: 4,027

Whoa, what a difference! Cool.

BBS Signature

None

JD77

Reply To Post Reply & Quote

Posted at: 7/7/06 10:30 AM

JD77 NEUTRAL LEVEL 17

Sign-Up: 03/30/05

Posts: 1,062

Well I havent worked with MC's but i tried Bdata and it seemed neearly the same. here are the codes for you to compare.
------------------------------------------
-
AS 3.0
-----------------------------------------
import flash.display.*
import flash.geom.*;

var B:BitmapData = new BitmapData(550,400,true,0xFFFFFFFF);
var B2:Bitmap = new Bitmap(B);
var PTA:Array = new Array();
var RET:Rectangle = new Rectangle(0,0,550,400);
var i:uint
var DIST:uint
var XDIF:Number
var YDIF:Number
addChild(B2);
for (i = 0; i<=10000; i++)
{
PTA.push([Math.random()*550, Math.random()*400, 0, 1]);
}
function OEF(lol:Event):void {
for (i = 0; i<PTA.length; ++i) {
PTA[i][1] += PTA[i][3];
PTA[i][0] += PTA[i][2];
B.setPixel(PTA[i][0], PTA[i][1], 0x00000000);
if (PTA[i][1]>=400) {
PTA[i][1] = 0;
PTA[i][0] = Math.random()*550;
}
if (PTA[i][0]>550) {
PTA[i][0] = 0;
}
if (PTA[i][0]<0) {
PTA[i][0] = 550;
}
XDIF = PTA[i][0]-mouseX;
YDIF = PTA[i][1]-mouseY;
DIST = Math.sqrt(YDIF*YDIF+XDIF*XDIF);
if (DIST<=100) {
PTA[i][2] += .05/(DIST/XDIF);
PTA[i][3] += .05/(DIST/YDIF);
} else {
PTA[i][3] -= (PTA[i][3]-1)/10;
PTA[i][2] -= (PTA[i][2])/20;
}
}
B.colorTransform(RET, new ColorTransform(1, 1, 1, 1, 20, 20, 20, 0));
}
addEventListener(Event.ENTER_FRAME,OEF);

----------------------------------------
AS 2.0
-----------------------------------------
import flash.display.BitmapData;
import flash.geom.ColorTransform;
var B:BitmapData = new BitmapData(550, 400, true, 0xFFFFFFFF);
_root.attachBitmap(B, this.getNextHighestDepth());
var PTA:Array = new Array();
for (var i = 0; i<=10000; i++) {
PTA.push([random(550), random(400), 0, 1]);
}
var YSPEED:Number = 1;
var XSPEED:Number = 1;
onEnterFrame = function () {
for (var i = 0; i<PTA.length; i++) {
PTA[i][1] += PTA[i][3];
PTA[i][0] += PTA[i][2];
B.setPixel(PTA[i][0], PTA[i][1], 0x000000);
if (PTA[i][1]>=400) {
PTA[i][1] = 0;
PTA[i][0] = random(550);
}
if (PTA[i][0]>550) {
PTA[i][0] = 0;
}
if (PTA[i][0]<0) {
PTA[i][0] = 550;
}
XDIF = PTA[i][0]-_xmouse;
YDIF = PTA[i][1]-_ymouse;
DIST = Math.sqrt(YDIF*YDIF+XDIF*XDIF);
if (Math.abs(DIST)<=100) {
PTA[i][2] += .05/(DIST/XDIF);
PTA[i][3] += .05/(DIST/YDIF);
} else {
PTA[i][3] -= (PTA[i][3]-1)/10;
PTA[i][2] -= (PTA[i][2])/20;
}
}
B.colorTransform(B.rectangle, new ColorTransform(1, 1, 1, 1, 20, 20, 20, 0));
};

*User Page under construction*

BBS Signature

None

TrueDarkness

Reply To Post Reply & Quote

Posted at: 7/7/06 10:30 AM

TrueDarkness EVIL LEVEL 27

Sign-Up: 08/31/04

Posts: 4,718

OHHHH nevermind, you didn't say that you did script them... did you? =p
I'm not saying anything bad about you, I'm just annoyed that I can't figure out shit in AS 3 >_<
Meanwhile everyone else has all these awesome things worked out. Blegh


None

Paranoia

Reply To Post Reply & Quote

Posted at: 7/7/06 10:35 AM

Paranoia DARK LEVEL 31

Sign-Up: 04/22/05

Posts: 9,119

I'm in the same boat, TD :P I wish the documentation for Flash 9 was a bit more... existant.

A rate of change in sanity with respect to time.

BBS Signature

None

TrueDarkness

Reply To Post Reply & Quote

Posted at: 7/7/06 10:37 AM

TrueDarkness EVIL LEVEL 27

Sign-Up: 08/31/04

Posts: 4,718

At 7/7/06 10:35 AM, _Paranoia_ wrote: I'm in the same boat, TD :P I wish the documentation for Flash 9 was a bit more... existant.

Yeah, I'm just going to wait for some AS3 tuts on NG to open up. Sure I can find some tutorials on google about it, but those are too complicated. Some beginnner tuts here on NG will probably be easier to understand, but who knows when theyll make an AS3 main and what not =/


None

GameSQUID

Reply To Post Reply & Quote

Posted at: 7/7/06 10:45 AM

GameSQUID NEUTRAL LEVEL 02

Sign-Up: 07/13/05

Posts: 95

First off, bitmapdata probably isn't a whole lot faster than in previous versions of flash. In fact, the rendering engine as a whole is roughly the same speed-wise, with the exception that you can use Sprite instead of MovieClip, which should be a bit faster (so if you want to show bitmapdata, add it to a sprite now).
The big difference is the language itself. With the new VM, the speed has increased to about 10 times what was possible in AS2.

As for the documentation, it does exist, and it can be found here : http://livedocs.macr../as3preview/langref/

Note that it's a reference, not a guide that teaches you how to program. There's some AS3/F9 tutorials on Flashkit somewhere though, in the games section.


None

JD77

Reply To Post Reply & Quote

Posted at: 7/7/06 02:54 PM

JD77 NEUTRAL LEVEL 17

Sign-Up: 03/30/05

Posts: 1,062

Woah thanks for the link, lol i thought there wasnt a reference cause thehelp thing intergrated on flash 9 isnt working lol.

And a tip, declare all the VAR! first time i used it there wasnt a big dif with speeds, the problem was that i wasnt declaring all of them, that's why you see that the for loop"i" was decleared firts. I allways strict data typed, but i never felt the difference. On flash 9 YOU WILL lol.

*User Page under construction*

BBS Signature

None

flashmenow-kthx

Reply To Post Reply & Quote

Posted at: 7/7/06 03:01 PM

flashmenow-kthx NEUTRAL LEVEL 05

Sign-Up: 04/17/06

Posts: 491

is it worth it to change to flash 9? i was thinking about it but i hear some of the scripting functions dont exist in AS3, and you can't put script on MC's or something like that. it all has to be on the frame. is it truly better for everything? if so, i'd change, but im very used to MC's having their own script. yes, everything on the frame would make it much easier and less confusing for us to try and write something, but every single action piled into one frame...its good? or am i wrong about some of this?


None

JD77

Reply To Post Reply & Quote

Posted at: 7/7/06 03:38 PM

JD77 NEUTRAL LEVEL 17

Sign-Up: 03/30/05

Posts: 1,062

Lag my friend. The main reason for AS 3.0 is to reduce lag! If you dont know much AS 2.0 id recomend u stick with it, since AS 3.0 is not complete, it's still a alpha.

*User Page under construction*

BBS Signature

None

GameSQUID

Reply To Post Reply & Quote

Posted at: 7/7/06 03:49 PM

GameSQUID NEUTRAL LEVEL 02

Sign-Up: 07/13/05

Posts: 95

At 7/7/06 03:01 PM, flashmenow_kthx wrote: is it worth it to change to flash 9? i was thinking about it but i hear some of the scripting functions dont exist in AS3, and you can't put script on MC's or something like that. it all has to be on the frame. is it truly better for everything? if so, i'd change, but im very used to MC's having their own script. yes, everything on the frame would make it much easier and less confusing for us to try and write something, but every single action piled into one frame...its good? or am i wrong about some of this?

Every single action piled into one frame? What the hell are you talking about? AS3 is the best structured incarnation of the language to date, with packages and namespaces to help you organize your classes. Don't put code in your frames, unless it's a gotoAndPlay to loop something.

But yeah, ActionScript 3.0 does not support actions on button or MovieClip instances. The only situation I can think of where this could be a problem is for simple navigation and menu work, where you don't want to write classes for small things, but hey, I can live with that.

At 7/7/06 03:38 PM, JD77 wrote: Lag my friend. The main reason for AS 3.0 is to reduce lag! If you dont know much AS 2.0 id recomend u stick with it, since AS 3.0 is not complete, it's still a alpha.

If AS3 is still in alpha, why did they release Flash Player 9 and Flex Builder 2? I might be wrong, but to me that indicates that AS3 is pretty much finished.


None

flashmenow-kthx

Reply To Post Reply & Quote

Posted at: 7/7/06 09:09 PM

flashmenow-kthx NEUTRAL LEVEL 05

Sign-Up: 04/17/06

Posts: 491

Every single action piled into one frame? What the hell are you talking about? AS3 is the best structured incarnation of the language to date, with packages and namespaces to help you organize your classes. Don't put code in your frames, unless it's a gotoAndPlay to loop something.

chill brother, did i not say i could be wrong about some of this? i dont even have it, and i simply asked if it was worth it to change to flash 9. and i when i said every action put into a frame, i mainly meant that no movie clips had their own script. it would be piled up if you were making a game. i wouldnt care if all i did was make movies and i only used gotoAndPlay to loop, as you say.


None

hashbrown

Reply To Post Reply & Quote

Posted at: 7/8/06 01:42 AM

hashbrown LIGHT LEVEL 16

Sign-Up: 07/07/05

Posts: 3,036

so your telling me as 3 will let me have a shitload of particle effects that would be lagalicious on as 2 and let me make my games bootiful. if yes teach me as3 if no teach me as 2


None

Nick

Reply To Post Reply & Quote

Posted at: 7/8/06 07:29 AM

Nick FAB LEVEL 22

Sign-Up: 08/22/05

Posts: 1,966

At 7/8/06 01:42 AM, -hashbrown- wrote: so your telling me as 3 will let me have a shitload of particle effects that would be lagalicious on as 2 and let me make my games bootiful.

Yes.


None

Kinsman

Reply To Post Reply & Quote

Posted at: 7/8/06 09:37 AM

Kinsman NEUTRAL LEVEL 14

Sign-Up: 07/15/00

Posts: 134

At 7/7/06 03:49 PM, GameSQUID wrote:
But yeah, ActionScript 3.0 does not support actions on button or MovieClip instances. The only situation I can think of where this could be a problem is for simple navigation and menu work, where you don't want to write classes for small things, but hey, I can live with that.

I find the best way to handle simple buttons in AS3 is to:

1. Use a main Document Class to put your timeline code in. (Make sure you declare the Document Class as 'dynamic', so that the timeline can add and remove clips for you.)
2. When your timeline reaches a menu frame, put something simple in the timeline like

initMenu();

3. Explain 'initMenu()' in your main Document Class with something like this:

public function initMenu()
{
MovieClip mc = getChildByName("mybutton");
mc.addEventListener("click",clickedMenuBut
ton);
}

public function clickMenuButton()
{
gotoAndPlay("FirstScene");
}

BBS Signature

None

Paranoia

Reply To Post Reply & Quote

Posted at: 7/8/06 09:42 AM

Paranoia DARK LEVEL 31

Sign-Up: 04/22/05

Posts: 9,119

At 7/8/06 09:37 AM, Kinsman wrote: public function initMenu()
{
MovieClip mc = getChildByName("mybutton");
mc.addEventListener("click",clickedMenuBut
ton);
}

public function clickMenuButton()
{
gotoAndPlay("FirstScene");
}

Gah, looks complicated. I'm definately going to wait a bit for some good documentation to come out for it.

A rate of change in sanity with respect to time.

BBS Signature

None

Blaze

Reply To Post Reply & Quote

Posted at: 7/8/06 09:49 AM

Blaze LIGHT LEVEL 22

Sign-Up: 08/04/05

Posts: 6,957

At 7/8/06 09:37 AM, Kinsman wrote: public function initMenu()
{
MovieClip mc = getChildByName("mybutton");
mc.addEventListener("click",clickedMenuBut
ton);
}

public function clickMenuButton()
{
gotoAndPlay("FirstScene");
}

And thats just for ONE button. God. I cant imagine more buttons. Duplicating is going to be a total bitch and all that. Why couldnt they stay with the simple on Release crap. T_T


None

Paranoia

Reply To Post Reply & Quote

Posted at: 7/8/06 09:56 AM

Paranoia DARK LEVEL 31

Sign-Up: 04/22/05

Posts: 9,119

At 7/8/06 09:49 AM, Darkfire_Blaze wrote: And thats just for ONE button. God. I cant imagine more buttons. Duplicating is going to be a total bitch and all that. Why couldnt they stay with the simple on Release crap. T_T

It's not effeicient enough >.< All those old, pitifully simple options have gone the way of the random() function.

A rate of change in sanity with respect to time.

BBS Signature

None

TrueDarkness

Reply To Post Reply & Quote

Posted at: 7/8/06 10:19 AM

TrueDarkness EVIL LEVEL 27

Sign-Up: 08/31/04

Posts: 4,718

At 7/8/06 09:37 AM, Kinsman wrote: I find the best way to handle simple buttons in AS3 is to:

Now try and remember that in AS2 it would be more or less:

Button_MC.onRelease=function(){
_root.gotoAndPlay("FirstScene")
}

So yeah... bug difference don't ya think?


None

liaaaam

Reply To Post Reply & Quote

Posted at: 7/8/06 10:23 AM

liaaaam NEUTRAL LEVEL 21

Sign-Up: 12/11/04

Posts: 12,766

At 7/8/06 10:19 AM, True_Darkness wrote: So yeah... bug difference don't ya think?

Well I'd do the button like this:

import flash.events.*;
mc.addEventListener(MouseEvent.MOUSE_DOWN, onClickEvent);
function onClickEvent(me:MouseEvent):void {
if(me.target == mc) {
trace("OMGCLICK");
}
}


None

Re2deemer

Reply To Post Reply & Quote

Posted at: 7/8/06 10:25 AM

Re2deemer LIGHT LEVEL 10

Sign-Up: 11/03/05

Posts: 792

hmmm...Are there any book about AS 3.0???


None

Kinsman

Reply To Post Reply & Quote

Posted at: 7/8/06 10:26 AM

Kinsman NEUTRAL LEVEL 14

Sign-Up: 07/15/00

Posts: 134

At 7/8/06 10:19 AM, True_Darkness wrote:
So yeah... big difference don't ya think?

My work has lots of Java programming, so long-winded code isn't any big deal for me.

I won't champion it - there's advantages and disadvantages. Sure, the AS2 method is simpler and more to the point for 90% of Newgrounds work, but the AS3 method allows for more flexibility - for example, you can invent your own kinds of events, and signal and receive them like regular ones.

AS3 was designed to match Flash's goal of making the platform a 'serious' one, so that web programmers would consider Flash instead of either Java or AJAX. I'll bet when Blaze comes out, you'll be able to add events to buttons or clips directly, and the code will be written for you behind the scenes.

BBS Signature

None

TrueDarkness

Reply To Post Reply & Quote

Posted at: 7/8/06 10:32 AM

TrueDarkness EVIL LEVEL 27

Sign-Up: 08/31/04

Posts: 4,718

At 7/8/06 10:26 AM, Kinsman wrote: AS3 was designed to match Flash's goal of making the platform a 'serious' one, so that web programmers would consider Flash instead of either Java or AJAX. I'll bet when Blaze comes out, you'll be able to add events to buttons or clips directly, and the code will be written for you behind the scenes.

Yeah definately. I know that was the purpose, and I'm sure it's great for people who know C++ and Java and what not, but for those who know AS2 very well, AS3 is a big step from AS2. To me at least.

Hey liam, I tried using your code and it works well. There's one thing in that code that I like, and that's matching the MovieClip symbol name "mc" to the instance name. I've never seen that before and it's really cool. I took it out though to make it shorter. So so far I have this:

import flash.events.*;
mc.addEventListener(MouseEvent.MOUSE_DOWN, onClickEvent);
function onClickEvent(me:MouseEvent):void {
trace("OMGCLICK");
}

and I'm sure that with shorter variable names you could make it even shorter. I also noticed that if you take out the import flash.events.*, it works the same.

A. can you tell me what .* means?
B. can you tell me why you need sometimes import flash.events/display/geom/matrix

I shortened the code to
mc.addEventListener(MouseEvent.MOUSE_DOWN, clicky);
function clicky(me:MouseEvent):void {
trace("OMGCLICK")
};

and it works fine.


None

Kinsman

Reply To Post Reply & Quote

Posted at: 7/8/06 10:32 AM

Kinsman NEUTRAL LEVEL 14

Sign-Up: 07/15/00

Posts: 134

Another advantage to the Document Class is that your code is in one place. If you're writing a complex game, you can get lost when you've set a scene and you know that there's snippets of code in twenty different places around the stage.

Here, you can arrive at your complex frame, see 'initLevel()' in your timeline, then visit the function in your Document Class. Part of initLevel() contains all the event triggers you've set up, so you read the function names of those, and visit them in your Document Class. More code to write, but it's tidier in the end.

BBS Signature

None

liaaaam

Reply To Post Reply & Quote

Posted at: 7/8/06 10:32 AM

liaaaam NEUTRAL LEVEL 21

Sign-Up: 12/11/04

Posts: 12,766

At 7/8/06 10:26 AM, Kinsman wrote: I'll bet when Blaze comes out, you'll be able to add events to buttons or clips directly, and the code will be written for you behind the scenes.

Hmm, I doubt it. I wouldn't be surprised if you could click a clip/button and select "Add ActionScript" then write something for it, then Flash places the code on the timeline..


None

liaaaam

Reply To Post Reply & Quote

Posted at: 7/8/06 10:37 AM

liaaaam NEUTRAL LEVEL 21

Sign-Up: 12/11/04

Posts: 12,766

At 7/8/06 10:32 AM, True_Darkness wrote: A. can you tell me what .* means?

It imports all of the classes in that package (in this case the flash.events package, so it imports flash.events.MouseEvents, flash.events.Events, etc).

B. can you tell me why you need sometimes import flash.events/display/geom/matrix

You need to import the classes before you use them. That means that each flash doesn't need to have all the classes preimported, and saves on filesize (less classes) and performance (..less classes).

Here's a shorter version btw:
import flash.events.*;
mc.addEventListener(MouseEvent.MOUSE_DOWN, function (me:MouseEvent):void {
trace("OMGCLICK");
});


None

TrueDarkness

Reply To Post Reply & Quote

Posted at: 7/8/06 10:38 AM

TrueDarkness EVIL LEVEL 27

Sign-Up: 08/31/04

Posts: 4,718

Also I tried editing the button code to make a key script, but I'm not sure what I'm doing and if I'm doing it right (obviously not because it's not working):


import flash.events.*
mc.addEventListener(KeyboardEvent.KEY_DOWN
, onKeyEvent);
function onKeyEvent(me:KeyboardEvent):void {
if(Keyboard.KEY_DOWN(Keyboard.LEFT)){
x-=5
}
}


None

liaaaam

Reply To Post Reply & Quote

Posted at: 7/8/06 10:42 AM

liaaaam NEUTRAL LEVEL 21

Sign-Up: 12/11/04

Posts: 12,766

At 7/8/06 10:38 AM, True_Darkness wrote: Also I tried editing the button code to make a key script, but I'm not sure what I'm doing and if I'm doing it right (obviously not because it's not working):

This should work..:

import flash.events.*
mc.addEventListener(KeyboardEvent.KEY_DOWN
, onKeyEvent);
function onKeyEvent(ke:KeyboardEvent):void {
if(ke.keyCode==Keyboard.LEFT){
x-=5
}
}


All times are Eastern Standard Time (GMT -5) | Current Time: 08:18 AM

<< Back

This topic is 2 pages long. [ 1 | 2 ]

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!