Click to See Complete Forum and Search --> : Is AS 3.0 that much better?
J-Rad
08-18-2006, 09:13 PM
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..
cancerinform
08-18-2006, 09:33 PM
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/as3preview/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000057.html
There are a lot of other changes such as easier use of XML etc., but performance is a big issue.
aden_1
08-18-2006, 11:59 PM
Will this re-define the way flash is used? lol
greenham
08-19-2006, 01:18 AM
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?
joshchernoff
08-19-2006, 04:14 AM
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.
Incrue
08-19-2006, 07:10 AM
Its not that hard
cancerinform
08-19-2006, 09:15 AM
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?
If you have flash 8 you can download the flash 9 preview. Check the links in the resource threads.
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.
J-Rad
08-20-2006, 02:45 AM
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?
cancerinform
08-20-2006, 10:53 AM
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.
J-Rad
08-20-2006, 03:47 PM
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?
When you say clean up your stage...what do i need to clean up?
Could you explain that a little better? Where do you tell a movie clip what class it is?
When you say clean up your stage...what do i need to clean up?
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.
cancerinform
08-21-2006, 06:06 AM
Could you explain that a little better? Where do you tell a movie clip what class it is?
When you say clean up your stage...what do i need to clean up?
download the example here, check the properties of the movieclips in the library.
http://flashas3.flashscript.biz/eventbubble/event_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.
aden_1
08-21-2006, 09:42 AM
I'll check it out now... Cheers...
Frets
08-21-2006, 04:57 PM
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'm already not liking the proposition. If your saying this.loadMovie("some.swf") is no longer valid.
FlashGuru
08-21-2006, 05:41 PM
I'm already not liking the proposition. If your saying this.loadMovie("some.swf") is no longer valid.
loadMovie doesnt exist in Actionscript 3 but if it did, then this.loadMovie would work exactly as it did in previous versions of actionscript.
J-Rad
08-29-2006, 05:04 PM
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 adding import flash.display.MovieClip; to every class that extended movie clip. How would I import all the packages I needed in ONE spot and allow all my classes access?
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?
Ralgoth
08-29-2006, 10:14 PM
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();
I sure do have a lot of "Linkage" in my tilemap game :scared:
Ralgoth
08-29-2006, 10:30 PM
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});
cancerinform
08-30-2006, 12:23 AM
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.
joa__
08-30-2006, 01:55 AM
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});
Of course. And it would be a beauty like this
var wildpop: WildPop = new WildPop( shopMovie, 60 * i, 0, i, j, k, whatever, true );
J-Rad
08-30-2006, 03:42 AM
I found a nice explanation page of packages here:
http://livedocs.macromedia.com/labs/as3preview/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000030.html
Ralgoth
08-31-2006, 09:09 AM
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?
Ralgoth
08-31-2006, 09:15 AM
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.
cancerinform
08-31-2006, 09:23 AM
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.
package Setstage
{
import flash.display.MovieClip;
public class Square extends MovieClip
{
public function Square (x:Number, y:Number)
{
this.x = x;
this.y = y;
}
}
}
and change the MyStage class
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);
}
Fall_X
08-31-2006, 09:38 AM
perhaps I just need to study classes a bit more, but how would my movie know what to do with all of those values?
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 :
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 :
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.
Ralgoth
08-31-2006, 09:51 AM
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?
cancerinform
08-31-2006, 10:08 AM
As the example I have posted shows you need one class and using this class you create instances of your movieclip.
Ralgoth
08-31-2006, 10:51 AM
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 :)
cancerinform
08-31-2006, 11:55 AM
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.
Ralgoth
08-31-2006, 12:05 PM
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.
J-Rad
08-31-2006, 12:24 PM
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.
cancerinform
08-31-2006, 12:27 PM
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.
I recommend that you first download the Flash 9 preview, play around and then come back. :)
Fall_X
08-31-2006, 04:13 PM
Thanks for the examples. It seems like a lot of work to do something that was so simple in AS2.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.
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?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.
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.
Ralgoth
09-03-2006, 05:52 PM
I recommend that you first download the Flash 9 preview, play around and then come back. :)
Working on that now, thanks ;)
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.
Zeusbwr
09-04-2006, 06:33 PM
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
stop();
import AS.UIMng.Index;
var objIndex = new Index();
Inside MainDir/AS/UIMng/Index.as
package AS.UIMng
{
import flash.display.MovieClip;
public class Index
{
public function Index ()
{
}
}
}
output:
**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.
cancerinform
09-05-2006, 03:35 AM
Here is your working example attached. See the document class window.
misuser
09-05-2006, 04:51 AM
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...
I forgot to mention the display list - getNextHighestDepth is dead - long live addChild. At last we have robust z ordering!
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.
J-Rad
09-05-2006, 05:00 PM
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.
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();
}
}
}
example class "Bomb"
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!
misuser
09-05-2006, 06:29 PM
Why don't you start with something simpler until you've learnt the new language?
J-Rad
09-05-2006, 07:08 PM
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.
Zeusbwr
09-06-2006, 01:18 AM
Well this may not be correct, but check out the other thread in this forum about the syntax checker. Aparently, it does not work. If you compile your code you can see the real debugging, but just by using check syntax it will check it by using 2.0 standards (least thats my guess).
To my experience, i finally have (after 1 day) a working couple classes for a basic site, which compile fine. But if i use check syntax (or even auto formatting) it gives me tons of errors, all of which have "2.0" in them somewhere.
J-Rad
09-06-2006, 02:06 AM
Well this may not be correct, but check out the other thread in this forum about the syntax checker. Aparently, it does not work. If you compile your code you can see the real debugging, but just by using check syntax it will check it by using 2.0 standards (least thats my guess).
To my experience, i finally have (after 1 day) a working couple classes for a basic site, which compile fine. But if i use check syntax (or even auto formatting) it gives me tons of errors, all of which have "2.0" in them somewhere.
thats relieving, thanks.
cancerinform
09-06-2006, 02:22 AM
Couple of important things:
1. properties like _x, _rotation are now written without the underscore: x, rotation.
2. _root is now root but read only. To refer to the stage you cannot use _root any more. If you extend Sprite or MovieClip you can use this.parent.
OTHERWISE FOR EVERYBODY: please stick to the main topic of this thread and if you have specific questions start a new thread.
Thanks :)
misuser
09-06-2006, 04:41 AM
Actually that is one thing I don't like about AS3 - It does seem pretty difficult to get to the the root now. .parent or .stage are only defined AFTER your sprite or movieClip have been added to the display list. In Flex you can use mx.core.Application.application, I think in Flash 9 there's some sort of equivalent using the Document object?
I can see why Macdobe might have tightened this up - too many flash projects end with scripts littered through the fla, all setting and changing properties on the root, so the root basically becomes an alternative global scope - nasty!
AS3 seems to go the too far the other way (as far as I can see).
IMHO the class that provides access to the display list should be globally available (perhaps read-only), but it really should have the same class identifier for both Flex and Flash projects.
misuser
09-06-2006, 04:50 AM
...In fact what I'd like to see is the Stage class implemented as a singleton so you could get the stage like this:
flash.display.Stage.instance
It is a natural singleton (like the highlander, "there can be only one") so why not?
Fall_X
09-06-2006, 05:42 AM
Here's an idea : you can create a class with static stage and root properties. In your document class, you set these to reference the actual stage and root. Then you can access the stage and root from everywhere you want by using these static properties. Should work.
joa__
09-06-2006, 07:09 AM
I never ran into the problems you address here but let's have a look. You are talking about the parent and stage object before a DisplayObject has been added to the display list. How can this be defined before you added the Object to the list or after you removed it. If there is no parent, how do you want to know about it? And why do you want to access it if it does not exist?
The stage singleton is a good idea but in fact you have to agree that there are also parts that do not belong to the stage which would gain access to it. So talking about the design of AS3 it would be just against what Adobe is currently trying to force the users. Clean code. If you really need the global access to the stage, then you may follow the idea of FallX.
public static class Global {
public static var stage: Stage;
public static function init( s: Stage, ... ): void {
stage = s;
}
}
But I have to say that I really like the clean order. Maybe you can post an example where no other solution exists?
joshstrike
09-06-2006, 07:24 AM
download the example here, check the properties of the movieclips in the library.
http://flashas3.flashscript.biz/eventbubble/event_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.
So that's, just, completely terrifying to me. I'm on OSX and still haven't gotten a copy of AS3 going, but I thought I'd be able to convert code. Forget it.
All my classes are full of constructs like
this.target_mc[button[x]].outerObj = this;
this.target_mc[button[x]].onPress = function() {
this.outerObj(class function)
}
Even though it's a memory drain, it works... I'm scared to death of converting. I'm halfway through a 6 month commercial DB project with a Flash front-end (using AMFPHP) and I could really use the speed boost when rendering two-page-long auto-generated forms with comboBoxes inside those Godawful scrollPanes (I have to swap their depths back before deleting them)...I guess I'll just start from scratch with v2.0 next year when AS3 is stable and the components are out, 'cause it sounds like there's no sound way to get this code across as it stands...sheesh.
misuser
09-06-2006, 08:12 AM
@joa__
This is just off the top of my head...
Suppose for example you wanted to check the width of the stage from inside a control object (i.e. one that never gets added to the display list)? Sounds like the sort of thing that happens from time-to-time. As far as I understand it, the current situation is, for Flex projects you could use mx.core.Application.application.width but would have to use something different for Flash projects. This means I couldn't use such a control object in a swc that is designed for both Flash and Flex. Am I wrong (kind of hope so)?
Another example might be a singleton class that spawns display objects as children of the root - maybe they always appear on top of, or behind everything else. The beauty of a singleton is that is doesn't need to (and in fact can't) be bound a single location within the program.
Also I'm not keen on the Global class route - it would have to be manually initialised by the root document / application which just feels wrong and not at all modular.
misuser
09-06-2006, 08:35 AM
I just had a look at the way Macdobe do it in the mx.control.Alert component - just the kind of thing that causes a problem. They do it like this:
parent = Sprite(Application.application);
Which is fine for Flex but would that work in flash 9?
misuser
09-06-2006, 08:51 AM
@joshstrike
By "this.outerObj(class function)" I'm guessing you mean "this.outerObj.method()"? You want to call a method on a movieclip, not pass a function to its constructor, right?
I can't see why that wouldn't work in AS3.
btw, in both AS2 or AS3, you could just use variable scope to store the back reference for you:
var outerObject:MovieClip = this;
this.target_mc[button[x]].onPress = function() {
outerObj.method();
}
The variable outerObject and the function onPress share the same scope because they're created in the same scope.
Fall_X
09-06-2006, 11:42 AM
This means I couldn't use such a control object in a swc that is designed for both Flash and Flex.I haven't worked with flex yet (only flash 9), but I believe that once a clip has been compiled, the differences between flex and flash won't matter. But I guess we'll have to wait and see until F9 is fully released.
I guess I'll just start from scratch with v2.0 next year when AS3 is stableAS3 is already stable and released.
Maybe you can post an example where no other solution exists?The absense of Key.isDown() is an example that comes to mind. I wanted to mimic it, which was pretty easy, except that it requires a reference to the stage to add keyboard listeners to it. So my Key-class will not work until you give it a reference to the stage, which is no big deal, but it would be handy if I could reference it directly.
misuser
09-06-2006, 12:22 PM
...I believe that once a clip has been compiled, the differences between flex and flash won't matter.
Not sure if this contravenes the rules of the forum, but I've got 10 uk pounds that says the differences will matter, if you're interested...
Fall_X
09-06-2006, 12:58 PM
I would take you on but I'm in a tight spot financially at the moment, so I'd better not make it any worse (even if it's just 10ukp) :)
It just seems to me that both flex and flash will compile to the same bytecode, so the results should be interchangeable. Off course, I could be completely wrong here :)
senocular
09-06-2006, 01:04 PM
Not sure if this contravenes the rules of the forum, but I've got 10 uk pounds that says the differences will matter, if you're interested...
Both Flash 9 and Flex 2 use the same compiler to create the same bytecode in a resulting SWF that runs in AVM2 in the Flash 9 Player. The only difference in Flex SWFs is that they rely heavily on the mx framework - a collection of AS3 classes that work together to make Flex apps function. You can get this framework for free by downloading the Flex 2 SDK. You could then even create Flex apps in Flash 9 but you just wouldn't have the luxuries the Flex 2 IDE provides.
misuser
09-06-2006, 01:36 PM
...and unfortunatley the only convientent way of getting the at the root (Application.application) is part of the mx framework not the core AS3 classes, so it might not make it into Flash 9 :-(
joa__
09-06-2006, 01:49 PM
There is a difference between an Application and the Stage. While your Application may contain sub-applications but the stage is not able to hold any other sub-stages.
senocular
09-06-2006, 02:07 PM
You can recreate Application.application in about 5 lines of code using a document class called Application for Flash 9. The document class inherntly has stage access as well.
misuser
09-06-2006, 02:13 PM
Yeah true - i was thinking Application.application seems the obvious place to access the stage from (for objects not already on the display list). Admittedly, I'd still need to write a custom stage getter method on the main appliactions class and, now I think about it, that's just as ugly as the global class thing fall_x suggested.
For now I'll just cross my fingers that I never have to code such a thing.
joa__
09-06-2006, 08:15 PM
Cross your fingers that you never design your code to require such a construct. Better, eh? :)
cancerinform
09-07-2006, 10:26 AM
Check the attached example how to access the stage, it took about 5 lines ;) The document class can always be used for the Root class, because any other class can also be accessed without the document class.
cancerinform
09-10-2006, 04:49 PM
Ok,
although the present class Root allows to place objects on stage, it does not allow to do anything with them, because the reference object belongs to the class Stage. To circumvent this, we have to change the script and reference to a MovieClip object. In the modified class the reference is to a Movieclip and it now allows properties and methods (gotoAndStop(), for example) of the MovieClip class.
package
{
import flash.display.MovieClip;
import flash.display.Sprite;
public class Root extends MovieClip
{
public static var _root:Sprite;
public function Root ()
{
_root = this;
}
}
}
meandmybadself
12-03-2006, 02:28 AM
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?
For the ReferenceError, make sure you have Torpedo and Control classes to public. They're internal, not public by default.
aden_1
12-17-2006, 12:15 AM
Great example mod. While I think AS3 is going to take some (lots) of time to really become a standard that everyone can use to it's full potential, it will certianly shorten development time and increase the flexability of flash - to say the least ;)
BradFn
12-19-2006, 09:12 AM
i have this problem too.
===========================
Card games is my nature,
Can you tell me the game for me?
Reveal your future, www.tarotcard-psychic.com (http://tarot reading
www.tarotcard-psychic.com (http://www.tarotcard-psychic.com/)
BradFn
12-19-2006, 04:42 PM
What do you think about google technologies? do you think they're going to add support fot new features?
========================
video applications,
there're people who say
they can see visions
with tarot reading
www.tarotcard-psychic.com
i would like to stream that :)
baikin
12-21-2006, 02:41 AM
I think yes, it is that much better. I was scared at first,
thinking that all the work I had done would be scrapped, etc.
The thing is... all that code still works. Now I can play. All the
the little time savers that AS1 and AS2 allow, also allow for the
possibility of SILENT run-time errors. Errors aren't a thing that many
flash coders are used to using because AS 1 & 2 don't really scold
you for making them. Errors are a tool. You can even manually throw
them to let you respond to unexpected user interaction. It's better
to know before you publish, right?
Also, I have to stick up for Flex. Focusing on code and treating Flash
produced swf's as images == less headache; It's a lot different,
though. Like if VB.Net was cool .
Givertree
07-14-2009, 03:05 AM
I used the older one b4 and i think its a little bit easier
flashkit.com
Copyright WebMediaBrands Inc., All Rights Reserved.