Out of curiosity, has anyone on the list actually used private classes for anything other than enforcing singleton creation?

If you have, please tell us and say why it was the best solution.


On 27/05/2013 06:50, Cor wrote:
I think they can be usefull to create objects with a lot of its own
functionality.
In fact the same as you use a public classes: create objects, and you can
polymorphism the objects to your needs.
I also think this will keep your code more readable and clean.
HTH
Cor

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Karl
DeSaulniers
Sent: maandag 27 mei 2013 1:22
To: Flash Coders List
Subject: Re: [Flashcoders] AS3 finally..

Thanks Ktu. That actually makes sense. I was not looking for a reason
necessarily to use a private class, but more so, saw this example and had
the though "this must be a private class" and wanted to verify for my own
understanding. Which you have provided. I see and understand what you mean
by it is not the most necessary thing to create a private namespace class
and that I will more then likely be able to accomplish what i need through
regular classes and never need to set a private class up. Thank you for the
clarification.

Well. Finished Perkins, on to Moock.
Actually getting excited... LoL

Thanks again,

Best,
Karl

Sent from losPhone

On May 26, 2013, at 10:40 AM, ktu <[email protected]> wrote:

yes. this is an example of a private class. but as someone earlier
mentioned, you shouldn't ever _need_ to use them. and it would be more
appropriate not to use them in production code. using the internal
namespace gives you some restriction, and you could even use your own
namespace for restriction but that's quite uncommon as well.

for reference..
- you cannot add a namespace to this 'private' class and should result
in a compile error if you do. (ex. public class CustomClient)
therefore, it must always be defined as 'class ClassName' with no
namespace.
- any classes that you need within this 'private' class must be
imported outside the package package com {
   // code
}
import flash.display.Sprite
class MySprite {
   // code
}
- and if some outside object gets a reference to it, you should be
able to access public functions and properties so long as you do not
try to cast the object as anything other than Object.

in my experience, i have yet to feel the need for a pseudo 'private'
class.
the internal namespace serves me well most and in a few occasions a
custom namespace was required.

good luck :)


On Sun, May 26, 2013 at 6:58 AM, Karl DeSaulniers
<[email protected]>wrote:
Ok, I am understanding things a little better I believe. Quick
question to solidify some knowledge. In reference to my question
about a private class, is the class CustomClient at the bottom an
example of a private class? It was mentioned that even if you don't
have the word private there and don't put public, flash automatically
will interpret it as a private class. It is inside the class file but
outside the package for the main class (which was also mentioned), it
does not have public on it so you can't call it outside this file. This
is what a private class is, correct?
package {
    import flash.display.Sprite;
    import flash.events.NetStatusEvent;
    import flash.events.SecurityErrorEvent;
    import flash.media.Video;
    import flash.net.NetConnection;
    import flash.net.NetStream;
    import flash.events.Event;

    public class NetConnectionExample extends Sprite {
        private var videoURL:String = "
http://www.helpexamples.com/flash/video/cuepoints.flv";;
        private var connection:NetConnection;
        private var stream:NetStream;
        private var video:Video = new Video();

        public function NetConnectionExample() {
            connection = new NetConnection();
            connection.addEventListener(NetStatusEvent.NET_STATUS,
netStatusHandler);
connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR,
securityErrorHandler);
            connection.connect(null);
        }

        private function netStatusHandler(event:NetStatusEvent):void {
            switch (event.info.code) {
                case "NetConnection.Connect.Success":
                    connectStream();
                    break;
                case "NetStream.Play.StreamNotFound":
                    trace("Stream not found: " + videoURL);
                    break;
            }
        }

        private function
securityErrorHandler(event:SecurityErrorEvent):void {
            trace("securityErrorHandler: " + event);
        }

        private function connectStream():void {
            addChild(video);
            var stream:NetStream = new NetStream(connection);
            stream.addEventListener(NetStatusEvent.NET_STATUS,
netStatusHandler);
            stream.client = new CustomClient();
            video.attachNetStream(stream);
            stream.play(videoURL);
        }
    }
}

class CustomClient {
    public function onMetaData(info:Object):void {
        trace("metadata: duration=" + info.duration + " width=" +
info.width + " height=" + info.height + " framerate=" + info.framerate);
    }
    public function onCuePoint(info:Object):void {
        trace("cuepoint: time=" + info.time + " name=" + info.name + "
type=" + info.type);
    }
}

Best,

Karl DeSaulniers
Design Drumm
http://designdrumm.com
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


--
Ktu;

The information contained in this message may or may not be privileged
and/or confidential. If you are NOT the intended recipient,
congratulations, you got mail!
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


-----
No virus found in this message.
Checked by AVG - www.avg.com
Version: 2013.0.3343 / Virus Database: 3184/6360 - Release Date: 05/26/13

_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to