Thanks Everyone

On Sun, Dec 20, 2009 at 3:23 AM, Glen Pike <[email protected]>wrote:

> Hi Omar,
>
>   I have the same thing - I am coding in Flash Develop with hand-rolled
> button classes and other classes.  I was a little concerned at first with
> the public / private thing, but I am learning to live with it...
>
>   I think the lesson/trick here is to work in the way you feel comfortable
> - Flash's IDE forces you to declare author-time instances public, but you
> can still use encapsulation as you see fit - having accessors and methods
> manipulate the public "on-stage" assets.  For me, I have created a custom
> class template in FD that clearly separates my "IDE" variables from my other
> class variables using comments.
>   IMHO, If you understand the rules, then I guess it's okay to break them
> sometimes.
>
>   The test is - can you return to your work in 6 months time and understand
> what you did, (maybe you don't have to)?  If so, then your coding is
> probably okay; cutting a few corners may wind up the purists, but the most
> important thing is that you are getting your work done in a way that's clear
> to you and possibly other people if they have to maintain your code :)
>
>   Hope this helps and best wishes for the season.
>
>   Glen
>
>
> Omar Fouad wrote:
>
>> Hi all,
>>
>> I've been working with ActionScript 3.0 since 2006 and I used some
>> technique
>> in the last two years. I believed that this way is the best for splitting
>> code from design, but today I asked myself whether this approach is REALLY
>> professional or not.
>> What I do is a create a pure ActionScript project in Flex Builder 3, and I
>> create a FLA file with, which has in its library a bunch of assets that I
>> use as components or models, such as buttons, list items, image containers
>> with masks and so on - then I give each of the "component" a linkage name.
>>
>> For example, If I need to create a button I just create a MovieClip (or
>> Sprite) in my library that represents this simple button designed the way
>> it
>> should be, this MovieClip contains a TextField named "label" and it is
>> dynamic. It also contains a MovieClip named "background", which is the bg
>> of
>> the button behind the label. Finally I give this button a linkage
>> Identifier
>> "BasicButton".
>>
>> After that I publish the FLA and I create a Class that represents this
>> button:
>>
>>
>> package {
>>
>>    import flash.display.Sprite;
>>
>>    [Embed(source='Lib.swf', symbol='BasicButton')]
>>    public class BasicButton extends Sprite{ // and not MovieClip because
>> it
>> is based on one frame only
>>
>>                // I declare the variables inside of it. They have to be
>> public.
>>                public var label                :TextField;
>>                public var background      :Sprite;
>>
>> public function BasicButton(labelString:String) {
>>
>> label.text = labelString;
>>  this.buttonMode = true;
>> this.addEventListener(MouseEvent.ROLL_OVER, onOver);
>>                        this.addEventListener(MouseEvent.ROLL_OUT, onOut);
>> }
>>
>>                private function onOver(e:MouseEvent):void {
>>                        //changes the background color on roll over
>>                }
>>                private function onOut(e:MouseEvent):void {
>>                       //resets the background color on roll out
>>                }
>>
>> }
>> }
>>
>> Of course I can create an abstract button class that has all the roll over
>> and roll out instructions in it, and just make BasicButton an extension of
>> it, but whatever this is just an example.
>>
>> In the Main class:
>>
>> package {
>>
>>    import flash.display.Sprite;
>>
>>    public class Main extends Sprite{
>>
>>        private var myButton:BasicButton;
>>
>>        public function Main() {
>>             myButton = new BasicButton("Click Me");
>>             myButton.addEventListener(MouseEvent.CLICK, onClick);
>>             addChild(myButton);
>>        }
>>        public function onClick(e:MouseEvent) {
>>            trace("button clicked");
>>
>>        }
>>
>>
>> }
>>
>> This works and all of course. And I can also embed the button inside of
>> Main
>> and give it a variable of type Class, but in this cases I needed to have
>> it
>> in a different Class to be able to give it more functions.
>> This gives me flexibility when I need to make design tweaks to this button
>> (or all the other assets), but I've found a problem, which is that I
>> cannot
>> make things encapsulated since the variables "label" and "background"
>> inside
>> of BasicButton HAVE to be public (if I declare them as private it won't
>> compile). So in a way getters and setters have no use for such instances.
>>
>> How can I maintain encapsulation in this case? Or it's just this a good
>> way
>> to create flash content?
>>
>> Thank you
>>
>> Cordially.
>>
>>
>>
>>
>
> --
>
> Glen Pike
> 01326 218440
> www.glenpike.co.uk <http://www.glenpike.co.uk>
>
>
> _______________________________________________
> Flashcoders mailing list
> [email protected]
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>



-- 
Omar M. Fouad - Adobe™ Flash© Platform Developer
http://.omarfouad.net
Cellular: (+20) 1011.88.534 / (+20) 1444.37.175


This e-mail and any attachment is for authorised use by the intended
recipient(s) only. It may contain proprietary material, confidential
information and/or be subject to legal privilege. It should not be copied,
disclosed to, retained or used by, any other party. If you are not an
intended recipient then please promptly delete this e-mail and any
attachment and all copies and inform the sender. Thank you.
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to