I'm already using classes in external .as files, what else is so much better about AS 3.0? I looked on the Adobe website, but their descriptions of the new features were a little over my head..
Printable View
I'm already using classes in external .as files, what else is so much better about AS 3.0? I looked on the Adobe website, but their descriptions of the new features were a little over my head..
Performance for AS execution is about 10x faster, which was not possible with AS2. Former versions of AS used the prototype as identifier and searched along what is called a prototype chain or tree to detect inheritance. In AS3 all inherited properties and methods of an instance are stored in the traits object, which results in the increased performance of the Flash player.
http://livedocs.macromedia.com/labs/...=00000057.html
There are a lot of other changes such as easier use of XML etc., but performance is a big issue.
Will this re-define the way flash is used? lol
Forgive me for being a little ignorant - admittedly, I've not done a lot of looking into this - but how does one convert to the new ActionScript? Do I need to go out and buy a new version of Flash?
I hope that flash 9 is more then just a new verson of AS.
Also for the people that already have had there hands in AS3, is it all that much harder to learn then AS2. I mean is the curve bigger then befor? I really had to take some time to get the hole scope of AS2, in a way I'm still learning it.
Its not that hard
If you have flash 8 you can download the flash 9 preview. Check the links in the resource threads.Quote:
Originally Posted by greenham
If you don't have Flash 8, there is another way of doing it using Eclipse.
If you know AS2, AS3 is much easier to learn.
I just downloaded and installed flash 9. When i ran my project on AS 3.0, as expected, I got a ton of errors.
A ton of these:
**Warning** The linkage identifier 'Boundry' was already assigned to the symbol 'Levels/Worlds/Boundries/World2/Levels/level_1_boundry', and cannot be assigned to the symbol 'Levels/Worlds/Boundries/World2/Levels/level_2_boundry', since linkage identifiers must be unique.
and a ton of these:
**Error** C:\Documents and Settings\XP User\Desktop\Donkey Rocket II\enemies\weapons\Rocket.as : Line 1, Column 22 : [Compiler] Error #1017: The definition of base class MovieClip was not found.
class Rocket extends MovieClip {
ReferenceError: Error #1065: Variable Timeline2_77fcb110f4fb664a9df544dfbd94a6cf is not defined.
ReferenceError: Error #1065: Variable Torpedo is not defined.
ReferenceError: Error #1065: Variable Control is not defined.
...
is this a semi-easy fix..or do i have to rewrite most of my code for AS 3.0?
In Flash 9 the original linkage identifier does not exist any more. Instead a class is associated with the object, since every object is a class. If the object, which should receive linkage id does not have a class associated, Flash will automatically do it. So I first write a class file with only the constructor and otherwise nothing.
When you convert your movie the first thing to do is clean up your stage.
Then you need to decide if you use OOP or not for your project. Generally I prefer OOP, but that is a personal choice.
Then you need to go through your scripts and check all old syntax.
Could you explain that a little better? Where do you tell a movie clip what class it is?Quote:
Originally Posted by cancerinform
When you say clean up your stage...what do i need to clean up?
Quote:
Originally Posted by J-Rad
I'll give this a shot. :)
In Actionscript 2, if you had a movieclip in the Library that you wished to copy to the stage (using attachMovie() ), you would need to give it a "Linkage" identifier, which was Flash's way of determining which symbol in the Library you wanted.
In Actionscript 3, movieclips in the Library are actually classes. Classes are not copied to the stage with attachMovie() – instead, you say,
my_thingie = new thingie();
and in the Library, you give the movieclip you're using a class name (in this case it's "thingy"). So, when your code is executed, Flash will look for a class called "thingie" and will make an instance of that class called "my_thingie".
Classes have many benefits, though most of them apply to Object-Oriented Programming (OOP). However, for people who put code in the Timeline, this new way of attaching objects from the Library to the stage will make more sense when compared to the way one would create a new number, or a new string:
my_string = new String();
-like that.
So besides treating everything as a class, and performance improvements, what else does AS3 offer? Well, the event model has become more unified; in AS2, some events (like enterFrame) would use handlers, like onEnterFrame, while others (like MouseDown) would need listener objects, like Mouse.addListener(this) . In AS3, every event's code looks the same, and uses the same system to work. It's called the DOM3 Event Model.
Also, when objects in AS3 need to be displayed, they no longer use levels. A new movieclip will not automatically be drawn to the screen, which lets you take a load off the renderer. Removing a movieclip from the screen does not automatically delete it, which is sometimes nice (though sometimes troublesome too). And there is no longer a need to worry about overwriting a movieclip on a certain level with another movieclip being placed on that level.
So there're quite a lot of advantages to picking up AS3. Something important to remember, though, is that there is NO RUSH. AS3 is in its infancy, and AS1 and AS2 will work for years to come. It's more important to be knowledgeable in Actionscript than it is to drop what you're doing and pick up the next thing. Stay in your comfort zone, people.
download the example here, check the properties of the movieclips in the library.Quote:
Originally Posted by J-Rad
http://flashas3.flashscript.biz/even..._bubbling.html
That is another thing not possible in AS2 but very useful, event bubbling.
Then the Delegate class is autonatically included in listeners, meaning the "this" word within functions refers to the class and not the listener object.
I'll check it out now... Cheers...
I'm already not liking the proposition. If your saying this.loadMovie("some.swf") is no longer valid.Quote:
Then the Delegate class is autonatically included in listeners, meaning the "this" word within functions refers to the class and not the listener object.
loadMovie doesnt exist in Actionscript 3 but if it did, then this.loadMovie would work exactly as it did in previous versions of actionscript.Quote:
Originally Posted by Frets
Alright I finally decided to make the switch. But I'm having this problem:
**Error** C:\Documents and Settings\XP User\Desktop\Donkey Rocket II - v.9\enemies\Enemy.as : Line 3, Column 21 : [Compiler] Error #1017: The definition of base class MovieClip was not found.
class Enemy extends MovieClip {
What do I have to do to extend the MovieClip class?
EDIT: Fixed the above problem by addingto every class that extended movie clip. How would I import all the packages I needed in ONE spot and allow all my classes access?Code:import flash.display.MovieClip;
EDIT2: I am also getting tons of these errors:
ReferenceError: Error #1065: Variable Bomb is not defined.
ReferenceError: Error #1065: Variable Control is not defined.
ReferenceError: Error #1065: Variable Bullet is not defined.
ReferenceError: Error #1065: Variable Napalm is not defined.
ReferenceError: Error #1065: Variable Torpedo is not defined.
ReferenceError: Error #1065: Variable DepthCharge is not defined.
ReferenceError: Error #1065: Variable Artillery is not defined.
These are all my movie clips which are classes. I'm not sure if this is right, but I went to Linkage -> class and typed in their class name. Shouldn't this make them point to my actionscript files? I have set up my actionscript 3 preferences, so Flash knows where they are...
EDIT 3: I tried to make my Game_Object class public, but I got an error stating that the "public" attribute can only be used inside a package. So how do I implement that?
I sure do have a lot of "Linkage" in my tilemap game :scared:Quote:
Originally Posted by mRNA
with attachMovie you could define all of the properties with one line. Can you do that with classes?
example...
shopMovie.attachMovie("WildPop", "WildPop"+i, i, {_x:60*i, _y:0, CMB:i, CLR:j, STL:k, NUM:whatever, CART:true});
Ok,
I have attached a little example of how one can start. It clarifies some of the points raised here. To put objects on stage you can use a document class. What was former _root is now this.parent.
If the class path is not correct for example, you will get an error like this:
ReferenceError: Error #1065: Variable Square is not defined.
In AS2 it was simple the class soandso could not be loaded.
Of course. And it would be a beauty like thisQuote:
Originally Posted by Ralgoth
Code:var wildpop: WildPop = new WildPop( shopMovie, 60 * i, 0, i, j, k, whatever, true );
I found a nice explanation page of packages here:
http://livedocs.macromedia.com/labs/...=00000030.html
hrm...
okay, with attachMovie I defined which property took each value. With the class, you just kind of listed all of the values, but didn't assign them to the property. Example...
(attachMovie) NUM:whatever, CART:true
(classes) whatever, true
perhaps I just need to study classes a bit more, but how would my movie know what to do with all of those values?
The reason I ask all of this, is that I've been working on a tilemap game that needs to tell each tile exactly where to go, along with difining the characteristics of each creature/sprite/item/etc... I would love to convert the whole thing to Flash 9 if it works as well as everyone is saying, but if this simple task is made to be too complicated then it will have to wait.
If you download the example I posted just change the Square class, although I personally don't like to avoid to put anything into the constructor and recommend to make a separate function.
and change the MyStage classPHP Code:package Setstage
{
import flash.display.MovieClip;
public class Square extends MovieClip
{
public function Square (x:Number, y:Number)
{
this.x = x;
this.y = y;
}
}
}
PHP Code:public function MyStage ()
{
var clip:Square = new Square (100,100);
this.parent.addChild(clip);
//
var clip_2:Square = new Square (300,300);
this.parent.addChild(clip_2);
tField = new TextField();
tField.text = "I am clip_2.";
clip_2.addChild (tField);
}
Okay, this is how it works. When you create a new instance, you pass it some values/references, just like when calling a function. For instance :Quote:
perhaps I just need to study classes a bit more, but how would my movie know what to do with all of those values?
var myMovieClip:MyMovieClip=new MyMovieClip(1,2);
In your class definition, there will be a constructor-function. This constructor is called when the object is created, with the values you pass above. So for instance, this could look like this :
Code:package {
class MyMovieClip extends MovieClip {
private var value1:int;
private var value2:int;
public function MyMovieClip (value1:int,value2:int=0) {
// note that the constructor has the same name as the class!
// also, I gave value2 a default value of 0, so you can instantiate this class with only one parameter
this.value1=value1; // assign the first parameter to the property value1
this.value2=value2; // assign the first parameter to the property value1
}
}
}
Hope this makes sense.
Thanks for the examples. It seems like a lot of work to do something that was so simple in AS2. I haven't downloaded AS3 yet, but probably will this weekend.
One last question...
If I have say, 500 different creatures in my tilemap game and they all behave the same except for the values that I give them upon entering the stage, would they all still need their own class or could all of them share the same class?
As the example I have posted shows you need one class and using this class you create instances of your movieclip.
You made multiple instances of a Square, but should I want to make an instance of a Square, and a Circle, and a Triangle, would one class be able to do all that?
so 3 separate, completely different, movieclips, can all use the same class?
sorry if I'm not understanding completely. I think I'll be spending my weekend learning classes and AS3 :)
In former flash versions you put a square movieclip, a circle movieclip etc in the library and use attachMovie. Here you do the same thing and just make a class for each movieclip. Every object is a class.
That's a lot of classes. The tiles I can put in one movieclip and have it gotoAndStop("whatever_tile"); but with the sprites & creatures, it seems like my script is going to suddenly double in size.
If it performs that much better though, then I suppose it's worth it.
Well in my game right now, for example, I have an Enemy class, and then a bunch of classes that extend the Enemy class. Most of the code for all of these classes is within the Enemy class, and then each different enemy's class contains different variable's and maybe one or two overrided functions.
I recommend that you first download the Flash 9 preview, play around and then come back. :)Quote:
Originally Posted by Ralgoth
Classes aren't a new thing, and creating classes was about the same amount of work in AS2 as it is now in AS3. Sure, you could do without them if you wanted to, but once you know how to use them properly, you'll see that it's actually simpler, easier and cleaner to get things done. You might have to type a bit more and create more files, but you'll be able to find stuff faster, reuse classes, and structure things better.Quote:
Thanks for the examples. It seems like a lot of work to do something that was so simple in AS2.
In the current version of Flash9 (which only an apla), you need a class per library item, you can't use the same class on more than one library item. However, you can make multiple classes that extend the same class so the code only has to be written once.Quote:
If I have say, 500 different creatures in my tilemap game and they all behave the same except for the values that I give them upon entering the stage, would they all still need their own class or could all of them share the same class?
I do hope that in the final version, you can specify an 'extends' property in the linkage settings to use in combination with auto-generated classes. That would be handy.
Working on that now, thanks ;)Quote:
Originally Posted by cancerinform
Thank you too Fall X for your responses. I know classes are in AS2, I just haven't had much need for them until now. I'm sure I'll start using them and then wonder why I hadn't learned earlier.
Ok, great example by the way. Though as i am trying to implement my own class, i am having trouble.
For example:
Frame1 of index.fla
Inside MainDir/AS/UIMng/Index.asCode:stop();
import AS.UIMng.Index;
var objIndex = new Index();
output:Code:package AS.UIMng
{
import flash.display.MovieClip;
public class Index
{
public function Index ()
{
}
}
}
Code:**Error** C:\~~\asv301\AS\UIMng\Index.as: Line 1: Syntax error.
package AS.UIMng
**Error** C:\~~\asv301\AS\UIMng\Index.as: Line 4: Attribute used outside class.
public class Index
**Error** C:\~~\sv301\AS\UIMng\Index.as: Line 10: ActionScript 2.0 class scripts may only define class or interface constructs.
}
Total ActionScript Errors: 3 Reported Errors: 3
I've tried many combo's in the AS file.. wish no luck on the proper syntax.
Any tips? I have attached the two files.
*edit*
Fixed.
Aparently (least i assume) i was overlooking the part of the error that says "ActionScript 2.0". I didn't realize that even though the button is not disabled, the syntax checker does not work.
Here is your working example attached. See the document class window.
Personally, I think it AS3 is that much better. The two main reasons I've started using AS3:
Firstly performance. AS3 is so much faster - particularly with function calls. In AS2 the function calls were really too slow for game code or 3d stuff. The work around for AS2 is to write really large blocks of inline code which unfortunately, are impossible to maintain or debug.
Secondly, AS3 requires a more disciplined way of working, but in return provides better error checking, which means you're more likely to write code that works exactly as expected. One of the problems with Flash is the poor quality of code most ActionScript developers write - too many projects are launched with bugs; most are impossible to maintain; and forget extending a live project, try to add more functionality and something unrelated stops working; yadda, yadda, yadda...
[edit] I forgot to mention the display list - getNextHighestDepth is dead - long live addChild. At last we have robust z ordering! [/edit]
There really isn't anything I don't like about AS3 - ok you do end up writing more classes but the payoff is worth it.
I'm not so keen on everything about Flex 2 though. I still don't like swc components and they are much more important in the Flex environment. Admittedly you can create stuff in minutes that would take weeks without components. But too many of the Adobe supplied components contain bugs, I don't get why the flash player doesn't use OS UI widgets - so much of the work that goes in to component development is just reinventing the wheel.
i hate how I cant get AS 3.0 to work.
I have 5 billion reference errors even though i set up my packages right (i think) as well as changed all my syntax.
**Error** tempInit : Line 1, Column 11 : [Compiler] Error #1093: Syntax error. <- dont know what this is.
ReferenceError: Error #1065: Variable Bomb is not defined. <- one of these for every MC i have.
ReferenceError: Error #1065: Variable Timeline1_ecdeb37ae28365419aa0394c2321a8c is not defined. <- bunch of these that mean nothing to me.
example class "Bomb"Code:package AS.player.weapons.shots{
class Bomb extends Shot {
function Bomb() {
gotoAndStop("fire");
ammo = 10;
damage = 50;
fireRate = 10;
armed = true;
speed = 1;
if(_root.player._xscale < 0){
_rotation *= -1;
_rotation += 180;
}
setXVelocity();
setYVelocity();
}
}
}
i get these errors when I push the 'checkmark' in the ActionScripting window:
**Error** C:\Documents and Settings\XP User\Desktop\Donkey Rocket II - v.9\AS\player\weapons\shots\Bomb.as: Line 1: Syntax error.
package AS.player.weapons.shots{
**Error** C:\Documents and Settings\XP User\Desktop\Donkey Rocket II - v.9\AS\player\weapons\shots\Bomb.as: Line 19: ActionScript 2.0 class scripts may only define class or interface constructs.
}
why does it say its a AS 2.0 script? I changed the publish settings to 3.0...?
this is such a pain in the ass!
Why don't you start with something simpler until you've learnt the new language?
probably what ill end up doing. I just want this project to turn out as good as possible, and the speed increase AS 3.0 gives is definitly worth the work. What I'm doing is not really that complicated. I have a few basic hierarchys for my packages, and not that many sophisticated functions in my files. I'm a computer science major, and I should be able to do these types of things.Quote:
Originally Posted by misuser