A Flash Developer Resource Site

Page 2 of 3 FirstFirst 123 LastLast
Results 21 to 40 of 43

Thread: [Disc] I know this isn't the correct forum, but this as3 lark...

  1. #21
    Knows where you live
    Join Date
    Oct 2004
    Posts
    944
    Well the main question is why would an object need a reference to the root. Adding a reference isn't breaking any rules, its the intent behind requiring a reference that is stomping all over encapsulation.

    Just as any program, say, Firefox has no real reason to need access to the doings of Gaim, in most cases there is no real reason for one object to access another object of equal importance. (Windows has a valid reason to access Gaim, while Firefox does not)

    If, say, you need a bullet to tell a space ship that its been hit, your automatic assumption may be to have the bullet access the space ship and tell it to do something, but I have a little motto I like to keep in mind:

    An object should never, ever, order around its superiors or equals

    Here is where design patterns come in, but in said situation, an OOP way of doing that would be to have a coordinator object (Game), a space ship (Ship) and a bullet (Bullet).

    The Game would be a superior of both the Ship and Bullets and hence be related by composition (Game has a Ship and Bullets). Game would pull coordinates from an array of bullets and test for a hit against the ship. If ship is hit, it would tell the ship to do something. If the bullet has hit something it will tell the bullet to play a removing animation/remove it.

    It is perfectly possible for a game to be programmed with no objects having a clue what its parent is. As a matter of fact, I would consider that to be very good design as having no references to parents implies being reusable, encapsulated and having no dependencies. It would be difficult to break Ship by changing Game, whereas in a tightly coupled system, simply re-naming a variable could trickle across half a hundred files.

    Again, this is clearly more complicated, but if you think about it you should be able to spot the advantages.

    OOP requires a very different mindset and if you have a local library, there are lots of books on the subject. Design Patterns are also a good idea to look into.

    Just some random other stuff:
    Composition = Has a. A Bathroom has a sink.
    Inheritance = Is a. A Dove is a Bird.
    Inheritance is often used where Composition is required.
    The greatest pleasure in life is doing what people say you cannot do.
    - Walter Bagehot
    The height of cleverness is to be able to conceal it.
    - Francois de La Rochefoucauld

  2. #22
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    Quote Originally Posted by Squize
    I'd like to use the Flex compiler 'cause it just feels quicker and I've not worked in the Flash IDE ( Code wise anyway ) for over 6 months, and it's as nasty as I remember it, but on the other hand embedding assets using xml tags feels a bit too hard core for me.
    If you don't like mxml but want to use Flex for AS3 check this thread:
    http://board.flashkit.com/board/show...ight=singleton

    The main point with AS3 is that you have more choices, but that means you can also change things to your disadvantage. When you can use a Sprite object instead of MovieClip use the Sprite object. It will use less memory and is not dynamic. Regarding the timeline you need to consider this. If you place objects on the stage and your movie is a child movie you run into problems, because coordinates will change. My strategy is to create a simple document class where I define the main timeline. I make it a public static variable. Then I can reference display objects from any other class using the getChildByName("name"); method, since one cannot reference those objects with their variable names as it was in AS2.
    For other variables like strings, numbers I also use getter/setter or again static variables as long as only one value is required. Static variables use less memory.

    While in the beginning I just write the application to get it going, once it is finished I start cleaning. That was not really necessary in AS2, because there were not many choices. Cleaning means also removing wildcards to import classes, removing multiple objects when it can be accomplished with less.

    Before I create an application I make a plan and mostly follow the Model-view-controller pattern, to split up the classes. These are kind of the schemes I worked out for myself, but don't know it is best practice.
    Like to learn from others how they are doing, since I am not coming from a programming background, but from Flash 5 .
    - The right of the People to create Flash movies shall not be infringed. -

  3. #23
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Location
    Lost forever in a happy crowd...
    Posts
    5,926
    Thought this thread was on it's way out

    Just want to clarify why I want to know about the _root ( Sorry, root *sigh* ) / stage. It's not so I can get different sprites or classes all hitting each other and each others properties directly, it's just so I can simply get access to mc's on the stage during the init stage of each class.

    If I want say a container for the scrolling playfield, then that's going to be on the stage, so I need to know where that is.
    It's not a case of breaking encapsulation, more a case of classes with any sort of display methods at least need to know where to start.

    Mr M, are prototypes back in as3 then ? Man, so much to learn ( All over again ).

    Cheers CIF, although "since one cannot reference those objects with their variable names as it was in AS2" that's poo if I've read it correctly.
    When using mc's in as2 I never just extend movieclip, I just create a var to hold the mc in, and use that, eg

    private var playerSprite:MovieClip;

    Hmmm, yet another change in the way I do things.

    Although great idea about the whole timeline thing, cheers mate.

    Squize.

  4. #24
    Developer
    Join Date
    Apr 2007
    Location
    UK
    Posts
    324
    I always considered you a legend....

  5. #25
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    Quote Originally Posted by Squize
    Mr M, are prototypes back in as3 then ? Man, so much to learn ( All over again ).
    i didn't think they ever left.

    I dont think you can define classes as them anymore, not sure, but you can add properties and methods real easy.

    oh, and i never extend the MovieClip class either, up until AS3. I like now that Adobe got rid of all the silly underscores for properties, i always hated those.
    lather yourself up with soap - soap arcade

  6. #26
    A very senior man mrpauly99's Avatar
    Join Date
    Feb 2002
    Location
    Cool Britania
    Posts
    429
    is it just me or is flash becoming a lot more sensible and a lot less fun?
    Last edited by mrpauly99; 05-30-2007 at 07:52 AM.

  7. #27
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    fun can be encapsulated and support inheritance
    lather yourself up with soap - soap arcade

  8. #28
    Pumpkin Carving 2008 ImprisonedPride's Avatar
    Join Date
    Apr 2006
    Location
    Grand Rapids MI
    Posts
    2,378
    Quote Originally Posted by mrpauly99
    is it just me or is flash becoming a lot more sensible and a lot less fun?
    as3 looks like c++ in it's coding structure and that really (sorry) pisses me the hell off. The reason I loved flash so much was because it was so loose and forgiving and FUN, and now they went and changed it into this? I'm not upgrading to as3, and that's the end of that.
    The 'Boose':
    ASUS Sabertooth P67 TUF
    Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
    8GB G.Skill Ripjaws 1600 DDR3
    ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
    New addition: OCZ Vertex 240GB SATA III SSD
    WEI Score: 7.6

  9. #29
    Heli Attack! iopred's Avatar
    Join Date
    Jun 2003
    Location
    Sydney, Australia
    Posts
    923
    c++?

    Try Java. And its a good thing, a structured language is much better for coding large projects. If you want something small, stick with AS1/2.
    Christopher Rhodes
    squarecircleco.

  10. #30
    Pumpkin Carving 2008 ImprisonedPride's Avatar
    Join Date
    Apr 2006
    Location
    Grand Rapids MI
    Posts
    2,378
    Quote Originally Posted by iopred
    c++?

    Try Java. And its a good thing, a structured language is much better for coding large projects. If you want something small, stick with AS1/2.
    Yeah but Java looks similar in structure to c++ as well.
    The 'Boose':
    ASUS Sabertooth P67 TUF
    Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
    8GB G.Skill Ripjaws 1600 DDR3
    ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
    New addition: OCZ Vertex 240GB SATA III SSD
    WEI Score: 7.6

  11. #31
    Heli Attack! iopred's Avatar
    Join Date
    Jun 2003
    Location
    Sydney, Australia
    Posts
    923
    Well AS1/2 LOOK like C++ also

    But the structure of AS3/Java is completely different to C++.
    Christopher Rhodes
    squarecircleco.

  12. #32
    Senior Member webgeek's Avatar
    Join Date
    Sep 2000
    Posts
    1,356
    I'm with iopred - AS3 feels like a blend of C# (properties, yuk) and Java (almost everything else). And they all use C-syntax.

    Personally, I prefer AS3 to AS1/2 simply because it has less wierd "quirks". For the most part, when I code something in AS3 it works as expected or errors like expected. This is opposed to AS1/2 which simply stop working at some point in the code and don't tell you squat. I do wish the errors included line numbers though. That would help a lot.

    Other then properties, there are only a few things I don't like. I REALLY don't like the lack of method overloading/overriding. Not having it means they created the wierd "default value" arguments. Sadly, this makes for very odd code at times (like copyPixel's alpha stuff - you pass in two nulls and a boolean but the nulls arn't really null, they are defaulted). If they simply had overloading things would be nice and clean.

    No private constructors seems really silly to me too. No idea why they left this out.

  13. #33
    Heli Attack! iopred's Avatar
    Join Date
    Jun 2003
    Location
    Sydney, Australia
    Posts
    923
    Quote Originally Posted by webgeek
    I do wish the errors included line numbers though.
    It'd be nice wouldn't it.

    I also like the: "Class does not implement function from Interface", but doesn't mention which function.
    Christopher Rhodes
    squarecircleco.

  14. #34
    Senior Member webgeek's Avatar
    Join Date
    Sep 2000
    Posts
    1,356
    Oh yeah, forgot about that doozy

  15. #35
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Location
    Lost forever in a happy crowd...
    Posts
    5,926
    Talk about hijacking

    It's actually nice that this has turned into an interesting as3 thread, rather than one bitc'hing about.

    Mr M, I really thought prototypes had been dropped in as2, or if not, considered bad form.

    Going back to one of my original questions, the Main singleton extends Sprite, but would it have to extend MovieClip if there was more than 1 frame ( For example when a preloader goes in there ) ? I would have thought so, and I'm a bit behind on a current project so haven't had chance to check ( Yep, I'm lazy when it comes to learning ).

    Missing line numbers is a pain too. Esp. seeing how I've got my swanky sexy trace routines in as2 with the class and line numbers ( So great when working on multi-swf projects ). Hopefully there'll be a tweaked version of the compiler now it's open source.

    As to the fun, it's still there, it's just that you can't access it without using Event listeners.

    Squize.

    PS. Cortana I'm guessing that comment wasn't aimed at me, and if it was, then it's very tongue in cheek.

  16. #36
    Wait- what now? tidenburg's Avatar
    Join Date
    Dec 2005
    Posts
    1,471
    Im just trying to get the hang of Java. I dont really get the whole classes thing and thats why I wont change over to AS3 for some time. AS1 is soo much more simple but AS3 can let you do much much more at once.

    Infinite blobs just hit 2000 with 24fps.

  17. #37
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Location
    Lost forever in a happy crowd...
    Posts
    5,926
    Infinite bobs should be able to get to a couple of million and still run at 24fps

    ( I think it actually runs slower than the original in as1, but I've got blur and an add blendMode in this one. Surprised how much both those have effected it to be honest, I've probably screwed something up ).

    Squize.

  18. #38
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    You need to extend to MovieClip, if you have hardcopy objects, scripts within the frames or more than one frame. That all requires a timeline.
    - The right of the People to create Flash movies shall not be infringed. -

  19. #39
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Location
    Lost forever in a happy crowd...
    Posts
    5,926
    Thought so, thanks mate for indulging my laziness

    Squize.

  20. #40
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    you can still do up your fla without a Doc class, AS2 style, having code on the timeline still works, just not classy stuff.

    I think this is because a virtual timeline gets created for you

    You using AS3 for a project already Squize? i dont have balls for that yet.
    lather yourself up with soap - soap arcade

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