[AS3] Losing my religion: subclassing vs composition

I've been so far a devout disciple of compositing a graphic instance into a class in all cases, rather than make my class extends MovieClip. It is true that I was a piker at AS2 and only now that I am cranking on AS3 I consider myself worthy to call myself a beginner OOP programmer. But I bought all the reasons, and if I were still making AS2 apps, I could stay in this camp.

But lately my devotion has been shaken, and now I am seriously considering extending (and then subclassing from) MovieClip or Sprite when any class that has a visual component. Whereas before I would always compose in a MC instance, almost never do inherits everything except my own superclass my class and implement interfaces, polymorphism, now I think I will extend well that still implement interfaces for the usual reasons. Still, I also plan to be a follower of the composition of all other ways - I like composition over inheritance. As I lay not MC for classes that have no graphical components, such as components of the logic of the game. (I make games and other interactive entertainment applications, for distribution in the browser).

Can I please be informed by coders better than me as to the wisdom or folly of my change in attitude?

Here are a few reasons why my mind is changing; Please feel free to refute or support one of these:

-Changes between AS2 and AS3 make the downside of subclassing MC/Sprite lower before. I'll leave a lot more informed people come up with good examples, but seems to be the explicit nature of the addition of an object to the display list - the General hit being an MC is small (nonexistent?) if it is not on the list.

-Colin Moock, in his seminal book "Essential ActionScript 2" advocates composition - see his large MVC example in which his view class, although almost entirely Visual in function, did not extend MC but rather composite MC. However, in all also impressive AS3 Moock book, all of his examples now seem to use the extension. I really admire Moock then gives me a new perspective.

-All the best practices from Adobe and the examples use extension, that almost all the code samples, I see in other useful forums. I'm not blindly run with the crowd, but I think that I would get better feedback on my code of my peers so I follow suit.

-All the AS3 Flash components seem to use the extension, and indeed, AS3 itself is strongly focused on the legacy rather than based on the composition, for understandable reasons.

I am probably missing a lot and bad indicating a large part of what is there, but I hope you get the idea.

Yet again I ask my peers better: now, what are the arguments for and against extending MC or Sprite for a visually represented classes in AS3? Any comments would be very appreciated.

For all those who followed this saga breathtaking, Colin Moock generously responded via his blog when I wrote for him. What a guy!

Find the answer here:
http://www.Moock.org/blog/archives/000248.html

Tags: Adobe Animate

Similar Questions

  • Support for the creation of menus in which is the center of the screen using AS3, with MovieClip that contains buttons

    Hello beautiful ActionScript Guru-

    I'm new on learn AS3 and have run obstacle after roadblock to getting what, in my view, should be a simple thing to work. I'm trying to create a menu on many levels using a MovieClip that contains simple buttons. I'm facing 2 problems while posting what I've built.

    1. my Menu.as (code below), says it takes "5000: the class 'Menu' must subclass"flash.display.SimpleButton"because it is linked to a symbol in the library of this type.» That's fine, except when I don't change the code to reflect the change the error message wants to difficulty, my beautiful menu driven with options turns into an absolutely useless image, with no opportunity to serve a menu at all. I have read other forums that I have what Miss me is to create a MovieClip that contains buttons, but I think that's exactly what I did. I'm not sure how to fix this error.

    2. when I compile my main class (ConsStartMenu.as) did not finish the compilation error 1119: line 29 and 46, claiming that my link to my subclass (Menu.as) called a potentially indefinite property Menu through a reference with static type ConsStartMenu. After searching on Google and the forums navigation for long hours, I do have absolutely no idea what means this error, or what he wants me to difficulty. I think that this is also the reason why my sizing and centering code does not work. It's as if he can't quite find my Menu.as. Maybe a quick glance at my code will shed some light on this?

    Thank you very much in advance for your help.

    -connor

    errors.png

    ConsStartMenu.as-

    package {}

    import flash.display.MovieClip;

    import stuff from the lib of valve

    Import ValveLib.Globals;

    Import ValveLib.ResizeManager;

    SerializableAttribute public class ConsStartMenu extends MovieClip {}

    These three variables are required by the engine

    public var gameAPI:Object;

    public var globals: Object;

    public var elementName:String;

    public void ConsStartMenu(): void {}

    }

    This function is called when the user interface is loaded

    public void onLoaded(): void {}

    make this visible user interface

    Visible = true;

    Let customer across the user interface

    Globals.instance.resizeManager.AddListener (this);

    trace ("Cons Start Menu loaded!");

    This. Menu.Setup (this.gameAPI, this.globals);

    }

    public void onResize(re:ResizeManager): * {}

    var scaleRatioY:Number = re. ScreenHeight/900;

    If (re. ScreenHeight > 900) {}

    scaleRatioY = 1;

    }

    This. Menu.screenResize (re. ScreenWidth, re. ScreenHeight, scaleRatioY);

    }

    }

    }

    Menu.As-

    package {}

    import flash.display.MovieClip;

    import flash.events.MouseEvent;

    Import fl.transitions.Tween;

    Fl.transitions.easing import. *;

    to import flash.display.SimpleButton;

    SerializableAttribute public class Menu extends MovieClip {}

    var gameAPI:Object;

    globals var: Object;

    public void Menu() {}

    }

    public void Setup (api: Object, globals: Object) {}

    define our variables

    api = this.gameAPI;

    Globals = This.Globals;

    }

    public void screenResize (stageX:int, stageY: int, scaleRatio:Number) {}

    'this', the position being this module, in the center of the screen

    This.x = stageX/2;

    This.y = stageY/2;

    Save the original scale of this movieClip

    If (this ["originalXScale"] is nothing)

    {

    This ["originalXScale"] =-this.scaleX;

    This ["originalYScale"] = this.scaleY;

    }

    This module/movieClip to scale the scaleRatio

    this.scaleX = this.originalXScale * scaleRatio;

    this.scaleY = this.originalYScale * scaleRatio;

    }

    }

    }

    you are missing a fundamental knowledge of classes and how they work.

    the bottom line: you cannot reference Menu unless it's a static class.

    You must create an instance of your class of Menu:

    menu: Menu of var = new Menu();

    and then you can add to your addChild (menu) for the use of ConsStartMenu, or maybe that you don't have.  I can't.

    is ConsStartMenu your document class?

  • The absence of H264 is getting really annoying. SOUL is massively not reliable to me, and first load compositions AE takes forever.

    So for some reason any tech Adobe decided to remove the H264, although it is an industry standard for Vimeo, Youtube, stream delivery as Extreme Reach and local BluRay companies controlling companies such as Replicopy.

    I'm about two steps from dumping that whole program, because the lack of reliability of my work on end of Adobe's embarrassing for me. It takes me 3 - 4 times to return something for a customer view / approve him. Why 3 or 4 times? Because the SOUL definitely likes to remove audio, insert frame weird solarized, or just lock-up seeds and say it will take another 35 + hours to make a 90 minute video that taken after 12 hours to render the CS6.

    I won't have to make a file DNxHD for friends/customers to look at. Not practical when it is 18 x compression H264 Youtube size. 109 GB and 6 GB.

    I'm losing my patience here, and I'm out of ideas. I found no reliable way to make more leave After effects. The more reliable, but it is still a shot-in-the-dark, that's when I load up in the queue of rendering a file DNxHD or GoPro Cineform then then transcode with SOUL, that is a silly and useless workaround. I just converted a DNxHD 109 GB file into a file H264 of SOUL with glitches at random, once again. Other lost 90 minutes. I have no idea of f ' n what to do next, I'm out of ideas. Try again the GoPro? Make an another DNxHD and transcode to H264 and cross just my fingers that work 14 hours of rendering?

    In short, the question:

    Windows 7 computer, CS6 ran without any problems.

    Try to make the short clips for customer approval as well as compositions of 90 minutes of EI through SOUL (running in who just got dumped audio problems, executives spilled/solarized and the program just lock up).

    What do guys do? You guys how would export a documentary of 90 min for a master BR? They do not take GoPro or DNxHD. They take H264. All the world run into problems I described here? Y at - it a patch/solution? Is there another intermediate codec that isn't incredibly huge?

    Here is where I am:

    -Export of EI by SOUL directly to H264-> error City (sometimes missing audio parasites, randomly, or the program just locks up completely)

    --Exporter export of EI as DNxHD, then transcode to H264-> city of error. The random glitches. This makes 12 times today by changing the settings every time, never getting to work.

    -Export of EI as GoProCineform, then transcode to H264-> WORKED!

    Now, if this isn't some stroke of luck, all my customer previews must be made twice (via an intermediate codec that is MASSIVE, almost 30 x more big issues than H264) due to infinitely wise Adobe decision to drop the H264, which I'm sure makes sense for someone somewhere and was not a capricious bet made by two drunken programmers.

    Thanks guys for the input. I'll doublecheck different hard drives (on different connections as well) just for safety.

  • MapQuest AS3 API

    Hey everybody,

    I am a new student of as3, my first steps forward in an application map tourism.

    I use the MapQuest API for as3, this is the first time I use a api and so far I made the map of AS3 Basic of here.

    At the moment I am using the 'MouseWheel ZoomControl"from the link I left above but I have no idea how to get the exact code, because it looks like xml and I work with AS3 in Flash Pro CC.

    Can someone help me?

    It is a work of college and I'm losing my mind so far

    Thank you so much everyone, what about the best.

    use:


    package {}

    import flash.display.Sprite;

    import flash.display.StageScaleMode;

    import com.mapquest.tilemap. *.

    com.mapquest.tilemap.controls.inputdevice import. *;

    com.mapquest.tilemap.controls.shadymeadow import. *;

    SerializableAttribute public class AS3Map extends Sprite {}

    var zs:ZoomSettings;

    var map: TileMap

    public void AS3Map (): void {}

    Put scale

    this.stage.scaleMode = StageScaleMode.NO_SCALE;

    Create a new TileMap object, passing your key to the platform

    map = new TileMap ("Fmjtd % 7Cluurn96rnl % 2Cra % 3Do5-9w80lr");

    set the size of the map

    Map.Size = new Size (stage.stageWidth, stage.stageHeight),

    Add the sprite map

    addChild (map);

    addMapCenterF();

    addControlsF();

    }

    private function addMapCenterF (): void {}

    define the center of the map

    map.setCenter (new LatLng(38.895,-77.036697), 8);

    }

    private function addControlsF (): void {}

    Add a control to the card

    map.addControl (new SMLargeZoomControl());

    make an object zoomSettings

    This.ZS = new ZoomSettings();

    This.ZS.Animate = true;

    this.zs.easeFunction = mx.effects.easing.Linear.easeInOut;

    Add the mousewheelzoomcontrol to the map

    map.addControl (new MouseWheelZoomControl());

    }

    }

    }

  • insert html in a composition in muse

    Hi, I am trying to insert html into a publication in Muse.  I would like to have a clickable button trigger, and then a sort of superposition opens with an interactive calculator inside.  I have the HTML for the calculator, the problem is no matter how I try to insert into the Muse, the calculator either disappears for some reason (as well as the trigger), or the calculator stays on the page all the time, losing all clickable effect.

    Can someone tell me the best way to do it?

    Hello

    The Composition of which you are trying to use? White, Star News, Lightbox display, presentation or Tooltip?

    Also make sure to drag and drop the HTML window inserted above the target (border of the target is enabled once you move on), I hope that it will work.

    I even created using the composition of the balloon and its working very well. Please take a look at the link.

    Home

    If it does not work please share the calculator code HTML that you insert so that I can do some testing at my end.

    Concerning

    Vivek

  • Contact in Flash (AS3/PHP) forms

    Hello

    I created a form in flash (CS5) using AS3 and Php.

    The trial run has worked quite well, but now I added the form to my animation flash (original), he has a number of errors coming...

    Thing is that I just spent the last 2 hours trying to get this form of work and have no success what so ever.

    If anyone knows what the following compiler errors mean and how can I solve this problem?

    Scene 11152: there is a conflict with definition inherited in public in the namespace flash.display:DisplayObject.name.
    ComponentShim (compiled Clip), line 15000: the class 'fl.controls.TextArea' must subclass 'flash.display.MovieClip' because it is linked to a symbol in the library of this type.
    ComponentShim (compiled Clip), line 15000: the class 'fl.controls.TextInput' must subclass 'flash.display.MovieClip' because it is linked to a symbol in the library of this type.
    ComponentShim (compiled Clip), line 15000: the class 'fl.controls.UIScrollBar' must subclass 'flash.display.MovieClip' because it is linked to a symbol in the library of this type.
    ComponentShim (compiled Clip), line 15000: the class 'fl.controls.Button' must subclass 'flash.display.MovieClip' because it is linked to a symbol in the library of this type.

    Yes, of course I'm a newbie and still dealing with flash so any help would be amazing!

    Thank you in advance,

    Jos

    Add these items to the library of your hand (IE, loading) fla.

  • external .swf DURATION link AS3 png

    Flash allows you to compress the .png files as Photoshop can compress .jpg files better than any other tool high hand.

    I have the 77 .png files 1.8 .megs on my c: drive after I imported the and adjustment of the compression of files under the ' file > publication settings "to 75% for jpg and published the .swf with all the .png on the stage of the file size is 350 k which is 20% of the size of the original PNG file downloaded files with 77 separate application.

    I can create links in the shared .swf and test the animation with the code in the .swf shared to add holders of movieclip for each .png to the scene, but when I load the .swf shared in the main .swf Flash acts like he can't create the classes based on the link I have setup or there is no linkage of MovieClip.

    I tried a test to have the .swf shared with the png and movieclips bound to add to the assets of their own stadium and it works very well, but this means that a lot of my code and logic is included in the shared .swf that designers need to add png to. It's unfortunate AS3 sucks but I'm about done with the project if I knew that a battle AS3 would be I would have stayed with AS2 my next project will be AS2 no matter not at all. In any case I have set identifier 'class' link for each .png with a support of movieclip for each image. The 20% of the size for PNG and a single application against 77 separate application it's worth the extra effort to import the images, creating a movieclip with linkage holder but the main .swf which loads the .swf that is shared with all assets and links may not see or create assets as the shared .swf can when I test.

    We have the main .swf GET a handful of related assets .png and place them in the main .swf to load assets in different parts of the main .swf. It's cute that the shared .swf can add its own stadium-related assets but not too helpful. Also the way we deploy we can't roll a new version/Release to update the png but we can download a new .swf on the Active Server, so the png should be in a separate .swf. I can get the MovieClip shared add assets related to its own stadium during the test and when my problem loading is the main .swf which loads the shared .swf cannot create instances of the classes that are exported for the duration of sharing using binding.

    If possible I would like to know how the hell you get a handle on assets linked in a responsible external .swf. Preferably without creating my own crazy prototyped mega libraries of .as files consisting of outer class. Just a way of holding png MovieClips that have a connection and is configured for sharing the length of reference. It shouldn't really be that hard it's a simple task in AS2. I'm not a coding contest or some wild class to do the job that I want a few lines of code to create an instance of a class, then the reference to the Assembly/MovieClip holding the .png to addChild in a clip target.

    I solved it that I'm loading 77 assets incorporated into an external .swf that compresses the 77 PNG images without losing quality, it works very well.

  • The subclass Sprite display

    Hello

    I can't get my display subclass Sprite.
    What should I do to get the subclass on the stage. I add two other Sprites (s1.addChild (s2)) but on

    S1:spriteSubClass = new spriteSubClass();
    S1. AddChild (S2); S2 = 'blue Rect' Sprite
    root.addChild (s1);

    Nothing appears, by the way in which the width and height are not availible (= 0)

    the only way is to draw a graphic within the subclass (beginFill... drawRect... endFill)
    Then it will be displayed, but with a good size (according to the order of drawRect).
    There are some good examples for this case somewere?
    What can I do to get it posted without any drawings just after the addition of some clips or Sprites...
    I hope there is an easy way to do this without any patchwork.

    Thanks for all answers

    OK, Sry, I discovered it.

    I'm using AS3.

    My misstake Mayor was that I tried to change the .width and .heigth of the subclass of MovieClip.
    This won't work if I draw something forward. It is enough just to add children.

    This behaivior is very strange because it should be a read-only Variable in this case.

    Thank you much for the help.

  • How to connect a Hi-8 video composite RCA camcorder to a mac mini to 2015

    How can I connect a Hi 8 RCA composite analog video camcorder for my mac mini to 2015?

    Something like should work for the resolution of your camcorder.

    https://www.Amazon.com/Elgato-video-capture-analog-iPhone/DP/B0029U2YSA

    http://www.Quill.com/STARTech-s-video-composite-to-USB-video-capture-cable-TWAIN - mac-support-black/cbs/51295724.html?hid...

    You can get more expensive Thunderbolt capture devices

  • Can I restore without losing data?

    I don't have my Iphone saved on my computer. I need to get out of a boot loop, but I can't update. Is it possible to restore without losing any of my photos, music, etc.?

    You have a backup of iCloud? Or do you mean that you have no backup at all? Has not created a backup before attempting to update the device? Apple recommend a backup before doing any type of update iOS.

    Without a backup, you will lose data. You can recover from your last backup.

  • Music composition... (Froud)

    Hello.. I received an invoice today on the composition of music for £49.99... But I only did this membership! Who did it?

    It is unlikely that Apple, he is more likely to be a phishing e-mail trying to get your account details and payment (Apple's music seems to be one of the current favorites for these emails).

    Phishing and similar e-mail: Phishing and other suspicious emails

    The phishing emails: identifying fraudulent "phishing" email - Apple Support

    ITunes real e-mails: identification of legitimate on the iTunes Store - Apple Support emails

    View the purchase history of your account: view the history of your purchases from the iTunes Store - Apple Support (on an iOS device you can see the last 90 days buy via http://reportaproblem.apple.com)

    If it is a phishing e-mail you send to Apple: [email protected] and then delete him.

  • After losing in keynote, my presentation has disappeared

    I have the BONE 10.11.6 with a MacBook Pro (17-inch, mid 2010) with 2.66 GHz Intel Core i7 and 8 GB 1067 MHz DDR3; my speech is version 6.6.2 (2571). After losing, I can't find the presentation more. I made several stops, but do not change the file name. So are 4 days of hard work really gone forever?

    Try going here for help.

    OS X El Capitan: If you can't find a file

    Hope this helps, good luck to you.

  • How to recover a password administrator forgotten without losing data.

    I forgot my admin password on my desktop, a way to reset my password without losing all the data/files?

    Thank you.

    Here are the instructions of change or reset the password of a user account from OS X - Apple support

  • How can I edit HTML source in the composition?

    I often compose emails that contain bulleted or numbered lists multi-level, images and other elements inserted. Sometimes, Thunderbird fails to go down to the correct list between paragraphs or breaks, or it crashes or removes the part of my message when inserting an image. I found workarounds, but it would be helpful to me if I could see the HTML code and manually change in composition, as I can with the received messages (view > Message Source). I have not yet found a way to do this.
    Otherwise, I could compose the message in Dreamweaver and copy it into my e-mail, but I could create some tags that are not supported by Thunderbird.
    Please suggest how I can edit the HTML code before sending my message.
    Thank you
    -Richard

    A quick way is to select the body of the message (Ctrl-A to select all), then insert/HTML. Alternatively, use an add-on like EditHtml. As you suggest, copy html to an external editor is likely to cause problems.

  • How to change the RSS feed without losing subscribers

    I am currently using blubrry to download my podcasts. I'm not the host through them, but rather on my own site and using my feed to send to iTunes (http://racingdudes.com/feed/podcast/). However, I spent to SoundCloud to start my hosting podcasts. I added my last three episodes of the podcast on SoundCloud and they integrated into my website. However, how can I change the RSS feed of my original stream to my new SoundCloud feed without losing all my subscribers and sides?

    My first thought was to connect to iTunes Connect and my current RSS is such a list, swap out for my new. Which will work? Is it that simple? It seems that I read many ways outdated, complicated to do this process just make sure, if this is the newest, easiest way?

    Appreciate your help. Thank you!

    In order to keep your subscribers, you must either add the "itunes: new-feed-url' to the original feed, or launch a redirect 301 on your server: ideally both." These will change to the new food store and also your subscribers will be transparently redirected - they won't even notice. The complete method is explained in detail here: http://wilmut.uk/move

    If you are unable to change the power supply and also cannot implement a 301 redirect, then using Podcasts Connect will redirect the store but not subscribers redirect. In this case, the only option is to include an announcement in the last podcast on old food (you could do a special episode) announcing the change and ask people to re-subscribe from the shop page.

Maybe you are looking for