dcsimg
A Flash Developer Resource Site

Page 2 of 4 FirstFirst 1234 LastLast
Results 21 to 40 of 68

Thread: Is AS 3.0 that much better?

  1. #21
    Senior Member J-Rad's Avatar
    Join Date
    Jun 2006
    Posts
    124
    I found a nice explanation page of packages here:

    http://livedocs.macromedia.com/labs/...=00000030.html

  2. #22
    newb of many sorts Ralgoth's Avatar
    Join Date
    Apr 2002
    Posts
    466
    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?

  3. #23
    newb of many sorts Ralgoth's Avatar
    Join Date
    Apr 2002
    Posts
    466
    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.

  4. #24
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    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.
    PHP Code:
    package Setstage
    {
        
    import flash.display.MovieClip;
        public class 
    Square extends MovieClip
        
    {
            public function 
    Square (x:Numbery:Number)
            {
                
    this.x;
                
    this.y;
            }
        }

    and change the MyStage class
    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);
            } 
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  5. #25
    crossconscious
    Join Date
    Sep 2005
    Location
    Belgium
    Posts
    1,188
    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 :

    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.

  6. #26
    newb of many sorts Ralgoth's Avatar
    Join Date
    Apr 2002
    Posts
    466
    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?
    Search first, asked questions later.

  7. #27
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    As the example I have posted shows you need one class and using this class you create instances of your movieclip.
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  8. #28
    newb of many sorts Ralgoth's Avatar
    Join Date
    Apr 2002
    Posts
    466
    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
    Search first, asked questions later.

  9. #29
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    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.
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  10. #30
    newb of many sorts Ralgoth's Avatar
    Join Date
    Apr 2002
    Posts
    466
    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.
    Search first, asked questions later.

  11. #31
    Senior Member J-Rad's Avatar
    Join Date
    Jun 2006
    Posts
    124
    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.

  12. #32
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    Quote Originally Posted by Ralgoth
    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.
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  13. #33
    crossconscious
    Join Date
    Sep 2005
    Location
    Belgium
    Posts
    1,188
    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.

  14. #34
    newb of many sorts Ralgoth's Avatar
    Join Date
    Apr 2002
    Posts
    466
    Quote Originally Posted by cancerinform
    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.
    Search first, asked questions later.

  15. #35
    Senior Member
    Join Date
    Aug 2001
    Posts
    227
    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
    Code:
    stop();
    import AS.UIMng.Index;
    var objIndex = new Index();
    Inside MainDir/AS/UIMng/Index.as
    Code:
    package AS.UIMng
    {
    	import flash.display.MovieClip;
    	public class Index
    	{
    		public function Index ()
    		{
    		}
    	}
    }
    output:
    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.
    Attached Files Attached Files
    Last edited by Zeusbwr; 09-04-2006 at 09:45 PM.

  16. #36
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    Here is your working example attached. See the document class window.
    Attached Files Attached Files
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  17. #37
    Member
    Join Date
    Sep 2006
    Posts
    43

    Cow Icon I vote for AS3

    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.
    Last edited by misuser; 09-05-2006 at 03:55 AM.

  18. #38
    Senior Member J-Rad's Avatar
    Join Date
    Jun 2006
    Posts
    124
    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.

    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();
    	}
    }
    }
    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!
    Last edited by J-Rad; 09-05-2006 at 04:03 PM.

  19. #39
    Member
    Join Date
    Sep 2006
    Posts
    43
    Why don't you start with something simpler until you've learnt the new language?

  20. #40
    Senior Member J-Rad's Avatar
    Join Date
    Jun 2006
    Posts
    124
    Quote Originally Posted by misuser
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center