Re: [Flashcoders] Newbie AS3 question

2005-10-31 Thread Robert Tweed

Cedric Muller wrote:

in the end, using 'this' or leaving it does make a difference, doesn't it ?
I cannot decompile to test my sayings, but 'this' adds more bytecode to 
the file ??


I'm pretty sure it's just compiled into the same bytecode either way. 
There are a number of ways to test that, although I don't have time to 
try any of them just now. A decompiler probably won't tell you anything, 
because the decompilers job is by definition, to reconstruct the source 
code, not show you the bytecode.


- Robert
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Newbie AS3 question

2005-10-31 Thread Ian Thomas
Unless someone has coded a very odd compiler*, for most compilers of most
languages including 'this' won't make any difference to the compiled
bytecode.

Ian

*But then, it _is_ Macromedia. You never know. ;-)

On 10/31/05, Cedric Muller [EMAIL PROTECTED] wrote:

 in the end, using 'this' or leaving it does make a difference, doesn't
 it ?
 I cannot decompile to test my sayings, but 'this' adds more bytecode to
 the file ??

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Newbie AS3 question

2005-10-31 Thread Cedric Muller
so, people not using 'this' assume something not really achievable in 
terms of 'technology' ?

;)

I cannot decompile to test my sayings, but 'this' adds more bytecode 
to the file ??


   No, if you leave it off, it is added at compile time. Like I said, 
you can't call methods that aren't members of an object; all functions 
must be members of some object. AS1/2 allows you to *pretend* like 
you're calling a method that doesn't belong to an object, but only by 
assuming that it is a member of the current timeline (which is an 
object). Similarly, a method call in a class without an object 
specified will assume that it is of the current scope (this), and add 
that object reference during compilation (or, technically, just 
before). The bytecode is exactly the same, except in the (admittedly 
rare) case where there is a name conflict with a method in a 
superceding scope, in which case the object reference inserted by the 
precompiler will point to a different (and probably wrong) object.


ryanm
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders




___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Newbie AS3 question

2005-10-31 Thread Cedric Muller

correction/confirmation:
'this' keyword is added everywhere it is needed during compile time.


Cedric Muller wrote:
in the end, using 'this' or leaving it does make a difference, 
doesn't it ?
I cannot decompile to test my sayings, but 'this' adds more bytecode 
to the file ??


I'm pretty sure it's just compiled into the same bytecode either way. 
There are a number of ways to test that, although I don't have time to 
try any of them just now. A decompiler probably won't tell you 
anything, because the decompilers job is by definition, to reconstruct 
the source code, not show you the bytecode.


- Robert


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Newbie AS3 question

2005-10-31 Thread Robert Tweed

Ian Thomas wrote:
 Unless someone has coded a very odd compiler*, ...
 *But then, it _is_ Macromedia. You never know. ;-)

Yes, it _is_ Macromedia :-) For a very odd compiler, look no further 
than Lingo.


- Robert
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Newbie AS3 question

2005-10-31 Thread Andreas Rønning

ryanm wrote:

I cannot decompile to test my sayings, but 'this' adds more bytecode 
to the file ??


   No, if you leave it off, it is added at compile time. Like I said, 
you can't call methods that aren't members of an object; all functions 
must be members of some object. AS1/2 allows you to *pretend* like 
you're calling a method that doesn't belong to an object, but only by 
assuming that it is a member of the current timeline (which is an 
object). Similarly, a method call in a class without an object 
specified will assume that it is of the current scope (this), and add 
that object reference during compilation (or, technically, just 
before). The bytecode is exactly the same, except in the (admittedly 
rare) case where there is a name conflict with a method in a 
superceding scope, in which case the object reference inserted by the 
precompiler will point to a different (and probably wrong) object.


ryanm
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Two things:

1. Personally, in the end, i think the concept of readability is a 
matter of taste. Omitting this because it clutters the code is a 
strange notion to me, because to a lot of people it actually humanizes 
the code somewhat. If you're going to ask me about code clutter, i'd 
point you to classes such as Robert Penner's tween functions, which have 
about as nondescriptive variable names as i can imagine and do little to 
educate you. They supply the functionality, and that is that: Cue 
reference to how the quintessential software developer often denies 
himself the role of the teacher by force of habit. I'm the guy that 
types long variable names so i can pass the class on to the next man 
without figuring 15 minutes of tutoring into the idea, and this happens 
when you're the one scripter guy in an office full of designers. To 
pertain to self-imposed rules of truncated code because you have some 
idea as to what reads better TO YOU and what other people SHOULD strive 
for is arrogance, not craftsmanship.
To me, clutter is obfuscated script that makes no sense on first glance, 
and that takes you several reads through to catch the functionality and 
scope. A few thises here and there in addition to commentary is not a 
matter of bad form insofar as it helps the next man make sense of your 
work. You may be engineers on the lowest level, but to a certain extent 
you are also educators and authors, which is an element to programming 
too many ignore. What good does your script do if all it becomes is an 
interchangable cog in the system which only you can make sense enough of 
to alter or customize?


Of course this has less to do with spamming this and more with general 
programming form, but i think this as a descriptor is a good symbolic 
measure of how too much is sometimes just enough.


2. What the hell is going on with this here

class ParseXML{
   private var xmlDoc:XML;
   private function handleXML(){
   trace(this);
   }
   function ParseXML(url:String){
   xmlDoc = new XML();
   xmlDoc.ignoreWhite = true;
   xmlDoc.onLoad = handleXML;
   xmlDoc.load(url);
   }
}

trace this in this case traces out the xml doc. Is this because onLoad 
= handleXML declares the scope of handleXML as being the xmlDoc?
Sometimes the onLoad = functionReference; syntax weirds me out. I tend 
to go for the onLoad = function(){ more specific functionality here } method


- Andreas
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Newbie AS3 question

2005-10-31 Thread Cedric Muller




this is logical: you assign handleXML function to 'xmlDoc.onLoad' 
handler which means that 'handleXML' belongs to xmlDoc from now on ...


In such cases, I do the following:

class ParseXML{
   private var xmlDoc:XML;

   private function handleXML(){
   trace(owner);
   }
   function ParseXML(url:String){
   var owner = this;
   xmlDoc = new XML();
   xmlDoc.ignoreWhite = true;
   xmlDoc.onLoad = handleXML;
   xmlDoc.load(url);
   }
}


2. What the hell is going on with this here

class ParseXML{
   private var xmlDoc:XML;
   private function handleXML(){
   trace(this);
   }
   function ParseXML(url:String){
   xmlDoc = new XML();
   xmlDoc.ignoreWhite = true;
   xmlDoc.onLoad = handleXML;
   xmlDoc.load(url);
   }
}

trace this in this case traces out the xml doc. Is this because 
onLoad = handleXML declares the scope of handleXML as being the 
xmlDoc?
Sometimes the onLoad = functionReference; syntax weirds me out. I tend 
to go for the onLoad = function(){ more specific functionality here } 
method


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Newbie AS3 question

2005-10-31 Thread Andreas Rønning
Why? haha, sorry, but to me it looks like you just added var owner = 
this just to avoid putting trace(this) for no reason other than avoiding 
to use this.
What's the specific reason you did that? I'm guessing you're smarter 
than me :)


- Andreas

Cedric Muller wrote:





this is logical: you assign handleXML function to 'xmlDoc.onLoad' 
handler which means that 'handleXML' belongs to xmlDoc from now on ...


In such cases, I do the following:

class ParseXML{
   private var xmlDoc:XML;

   private function handleXML(){
   trace(owner);
   }
   function ParseXML(url:String){
   var owner = this;
   xmlDoc = new XML();
   xmlDoc.ignoreWhite = true;
   xmlDoc.onLoad = handleXML;
   xmlDoc.load(url);
   }
}


2. What the hell is going on with this here

class ParseXML{
   private var xmlDoc:XML;
   private function handleXML(){
   trace(this);
   }
   function ParseXML(url:String){
   xmlDoc = new XML();
   xmlDoc.ignoreWhite = true;
   xmlDoc.onLoad = handleXML;
   xmlDoc.load(url);
   }
}

trace this in this case traces out the xml doc. Is this because 
onLoad = handleXML declares the scope of handleXML as being the xmlDoc?
Sometimes the onLoad = functionReference; syntax weirds me out. I 
tend to go for the onLoad = function(){ more specific functionality 
here } method



___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders



___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Newbie AS3 question

2005-10-31 Thread Robert Tweed

Andreas Rønning wrote:

2. What the hell is going on with this here

class ParseXML{
   private var xmlDoc:XML;
   private function handleXML(){
   trace(this);
   }
   function ParseXML(url:String){
   xmlDoc = new XML();
   xmlDoc.ignoreWhite = true;
   xmlDoc.onLoad = handleXML;
   xmlDoc.load(url);
   }
}


I'd write that like this:

class ParseXML {
private var _xmlDoc : XML;
function ParseXML( url : String ) {
_xmlDoc = new XML();
_xmlDoc.ignoreWhite = true;
_xmlDoc.onLoad = function () {
trace( this );
};
_xmlDoc.load( url );
}
}

Clearer? The original version isn't defining a method for the class, 
it's defining a function and assigning it to a variable. In the spirit 
of calling a spade a spade, it's better to define an anonymous function 
where it's actually used.


- Robert
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Newbie AS3 question

2005-10-31 Thread Cedric Muller
I am not smarter than you, oh no! Delegate's smarter than us, and AS3 
is King!! (problem solved in the future)


I am simply declaring a variable in the class which refers to the class 
itself. This frees me from the scope trap (using this with 'onLoad') :


public function handleXML () {
trace(owner);
}

public function parseXML (url:String) {
xmlDoc = new XML();
xmlDoc.onLoad =handleXML;
xmlDoc.load(url);
}

public function init(url:String) {
var owner = this;
this.parseXML(url);
}

by doing this, I guarantee myself that this variable will be available 
to every object of the class. Its scope is the class.
Now, when you assign handleXML to xmlDoc.onLoad, you mainly transfer 
the method's owner (from the class to the xmlDoc object). By using 
'owner', I can target back my class without any problem...


I may be off tracks ;)

Cedric

Why? haha, sorry, but to me it looks like you just added var owner = 
this just to avoid putting trace(this) for no reason other than 
avoiding to use this.
What's the specific reason you did that? I'm guessing you're smarter 
than me :)


- Andreas

Cedric Muller wrote:





this is logical: you assign handleXML function to 'xmlDoc.onLoad' 
handler which means that 'handleXML' belongs to xmlDoc from now on 
...


In such cases, I do the following:

class ParseXML{
   private var xmlDoc:XML;

   private function handleXML(){
   trace(owner);
   }
   function ParseXML(url:String){
   var owner = this;
   xmlDoc = new XML();
   xmlDoc.ignoreWhite = true;
   xmlDoc.onLoad = handleXML;
   xmlDoc.load(url);
   }
}


2. What the hell is going on with this here

class ParseXML{
   private var xmlDoc:XML;
   private function handleXML(){
   trace(this);
   }
   function ParseXML(url:String){
   xmlDoc = new XML();
   xmlDoc.ignoreWhite = true;
   xmlDoc.onLoad = handleXML;
   xmlDoc.load(url);
   }
}

trace this in this case traces out the xml doc. Is this because 
onLoad = handleXML declares the scope of handleXML as being the 
xmlDoc?
Sometimes the onLoad = functionReference; syntax weirds me out. I 
tend to go for the onLoad = function(){ more specific functionality 
here } method



___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders



___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders




___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Newbie AS3 question

2005-10-31 Thread Andreas Rønning

Morten Barklund Shockwaved wrote:


Andreas Rønning wrote:

class ParseXML{private var xmlDoc:XML;private function 
handleXML(){trace(this);}function 
ParseXML(url:String){xmlDoc = new XML();
xmlDoc.ignoreWhite = true;xmlDoc.onLoad = handleXML;
xmlDoc.load(url);} } 



It is amazing how we can turn back to this first-grade example of 
understanding scoping in ActionScript almost daily.


But I'll go with the flow and return the most common answer (that I 
also personally use):


class ParseXML{
   private var xmlDoc:XML;
   private function handleXML(){
   trace(this);
   }
   function ParseXML(url:String):Void {
   xmlDoc = new XML();
   xmlDoc.ignoreWhite = true;
   xmlDoc.onLoad = mx.utils.Delegate.create(this, handleXML);
   xmlDoc.load(url);
   }
   private function toString():String {
   return i am not the xmlDoc;
   }
}

The issue is, that you have to make the xmlDoc call the 
handleXML-function with containing class as the activating scope. That 
can only be done via either hacking the XML-class or creating a 
special function, that will make the proper invocation of the proper 
function in the proper scope!


:)

*Yawn* here we go again, another new guy trying to understand this 
OBVIOUS concept that we've been through so many times already. I can't 
believe he's bothering us with this again!
Thank you for the completely unnecessary derogatory tone. Obviously it 
goes without saying that you HAD to exhibit the most common of 
scandinavian traits: When the opportunity arises, belittle, then 
enlighten, because such an opportunity to come out on top cannot be 
missed under any circumstances, and emphasizing the apparent difference 
in experience between the master and pupil  is first order . It is 
amazing how we can turn back to this first-grade example of lacking 
social skills almost daily.


Avoid the acute angle. There is no need whatsoever to adapt a belittling 
tone, and it rings particularly harsh on a pure text medium, which no 
amount of smiley action is going to alleviate.


- Andreas
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Newbie AS3 question

2005-10-31 Thread Ian Thomas
On 10/31/05, Morten Barklund Shockwaved [EMAIL PROTECTED]
wrote:


 It is amazing how we can turn back to this first-grade example of
 understanding scoping in ActionScript almost daily.


True - but this highlights a flaw in the language rather than a flaw in the
questioner... if the same non-obvious question always comes up. :-)

Which, I assume, is why MM have addressed it in AS3.

So until AS3 becomes the standard, unfortunately we're going to have to keep
answering the question. Or pointing them at the FAQ. And there is one on
OSFlash, I know, but it isn't immediately obvious to people joining this
list. I wonder whether a link to a FAQ could become part of the mailing list
signature..?

Ian
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Newbie AS3 question

2005-10-31 Thread Morten Barklund Shockwaved

Andreas Rønning wrote:

[snip]


*Yawn* here we go again, another new guy trying to understand this 
OBVIOUS concept that we've been through so many times already. I

can't believe he's bothering us with this again!

[snip]


Sorry, I was in a bad mood due to other circumstances, had just 
explained the very same thing in some other fora, and it's another 
monday morning... :)


(though I truely fail to see, how that is a scandinavian trademark?)

I just saw your posting:


2. What the hell is going on with this here

class ParseXML{
private var xmlDoc:XML;
private function handleXML(){
trace(this);
}
function ParseXML(url:String){
xmlDoc = new XML();
xmlDoc.ignoreWhite = true;
xmlDoc.onLoad = handleXML;
xmlDoc.load(url);
}
}

trace this in this case traces out the xml doc. Is this because onLoad 
= handleXML declares the scope of handleXML as being the xmlDoc?
Sometimes the onLoad = functionReference; syntax weirds me out. I tend 
to go for the onLoad = function(){ more specific functionality here } method


And wanted to reply with an explanation - and the archives doesn't 
really give the mails their true position in the hierarchy with this 
many replies to replies and thus I really cannot see, if you've been 
given a proper answer.


Maybe I've misinterpreted your question from the above posting as 
stating a common question and not really asking it - are you? If so, 
disregard the below. Otherwise, consider the below my view of how things 
are actually interpreted. :)


this-references are dynamically evaluated. It is what i personally 
refer to as the activating scope and can as such be anything, that is 
pushed in to the function as the activating scope. The defining scope on 
the other hand cannot be changed.


Thus I can create a function that trace's this - no matter what this is:

var my_function:Function = function () { trace(this is +this); }

I can then apply it to - say - a movieclip:

my_movieclip.some_function = my_function;
my_movieclip.some_function();

I can also invoke it runtime with the movieclip pushed in as the 
activating scope:


my_function.call(my_movieclip); // or .apply() - which ever suits you

The XML-class will internally call the onLoad-function as (pseudo-code):

private function __dataArrived():Void {
// parse stuff, set status, do other stuff
this.onLoad(this.status == 0);
}

Thus it will call the onLoad-function with the XML-object itself as the 
activating scope.


Some suggest it been worked around using a local property of the 
surrounding object as:


class Test {
private var owner:Test;
private var xml:XML;
public function Test() {
owner = this;
xml = new XML();
xml.ignoreWhite = true;
xml.onLoad = handleXML;
xml[owner] = local property of xml;
}
private function handleXML(success:Boolean):Void {
trace(I am Test: +(this instanceof Test));
trace(I am XML: +(this instanceof XML));
trace(owner is Test: +(owner instanceof Test));
trace(owner is XML: +(owner instanceof XML));
trace(What is owner then: +owner);
}
public function load(some_url:String):Void {
xml.load(some_url);
}
private function toString():String {
return some Test-instance;
}
}

But that will not work (as owner will be repaced with this.owner and 
will then point to the XML-instance-property and thus be a string).


Maybe someone suggests it being worked around using a static property 
(changing private var owner:Test to private static var owner:Test). 
Then it _will_ work (as owner is replaced with Test.owner when 
compiled), but then you can only have one instance simultanously - which 
may or may not be useful. At least not very pretty.


The defining scope can never be changed as explained. That is why the 
otherwise very used approach of:


class Test {
private var xml:XML;
public function Test() {
xml = new XML();
xml.ignoreWhite = true;
var owner:Test = this;
var callback:Function = handleXML;
xml[owner] = local property of xml;
xml[callback] = something not a function;
xml.onLoad = function() {
callback.apply(owner, arguments);
};
}
private function handleXML(success:Boolean):Void {
trace(I am Test: +(this instanceof Test));
trace(I am XML: +(this instanceof XML));
}
public function load(some_url:String):Void {
xml.load(some_url);
}
}

Now it works - and now callback and owner is read from the defining 
scope - and will always be the same. That is, we can copy this 
function to any object, invoke it using 

Re: [Flashcoders] Newbie AS3 question

2005-10-31 Thread Jon Bradley
Ok.  Since I was the 'ass' that started this junk by asking why this 
was needed, maybe I can be the 'ass' that will end it.


This thread started with Andreas asking about addChild.  Fair enough.

I asked about a specific example that used this on a method which was 
a member of the same class and was invoked by using this.member.  I was 
curious why that was there, nothing more, as I haven't explored AS3 too 
much.


Is it too hard to just answer the question at hand without providing 
more information than is really necessary and making some of us think 
we're being patronized?


Can we move on to some more high-level stuff already?

cheers,

Jon

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Newbie AS3 question

2005-10-30 Thread Cedric Muller
in the end, using 'this' or leaving it does make a difference, doesn't 
it ?
I cannot decompile to test my sayings, but 'this' adds more bytecode to 
the file ??



I'm the opposite end of the spectrum.  This:

class Box extends UIObject
{
function doStuff()
{
move(x + 10, y + 10);
setSize(width + 100, height + 100);
visible = !visible;
}
}

looks more readable to me than:

class Box extends UIObject
{
function doStuff()
{
this.move(this.x + 10, this.y + 10);
this.setSize(this.width + 100, this.height + 100);
this.visible = !this.visible;
}
}

To each their own.  I can see it justified in extending intrinsic 
classes,
as the first parameter to setInterval, and the first parameter in 
Delegate.


AS3 and Flex both hammer the point that this really has little use 
other

than confirming for those programmers who are not familiar with
ActionScript.  Same goes for the Singleton.method vs.
Singleton.getInstance().method argument; the latter is for those 
programmers

who don't know ActionScript well.

If you do it every day, there is no point.

- Original Message -
From: Muzak [EMAIL PROTECTED]
To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com
Sent: Friday, October 28, 2005 5:37 PM
Subject: Re: [Flashcoders] Newbie AS3 question


Well, to me it's the other way around.
Code that doesn't use proper references looks messy to me.

Whe I'm lazy or in a hurry, I do skip them, but I usually find myself 
adding

them afterwards anyway.

So, I'm with ryanm on this one ;-)

regards,
Muzak

- Original Message -
From: Martin Wood [EMAIL PROTECTED]
To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com
Sent: Friday, October 28, 2005 11:03 PM
Subject: Re: [Flashcoders] Newbie AS3 question





ryanm wrote:

What I don't get is why it needs this.addChild instead of just
addChild. I've been sick of the keyword this for a long time
and have since avoided it in AS2.

Any reason that it needs to be back in for AS3?


   Maybe because it's one of the most useful scope references ever
invented?

   The fundamental concept that you seem to miss is that addChild 
is

meaningless by itself, it is a method of an object (in
proper OOP development), and if you just say addChild, who is 
adding

the child?


the context is the current class. Occasionally 'this' is useful if you
happen to name a method parameter or local variable the
same as a member variable and need to distinguish the two.

But, I dont agree that its bad form to leave it out, nor is it any 
more

difficult to maintain.

in my opinion putting 'this' in everywhere to me just makes things 
harder

to read.

thanks,

Martin



___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders




___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Newbie AS3 question

2005-10-29 Thread JesterXL
As the coffee kicks in, that also looks like Composition, not Singleton. 
Like, you have a Singleton class instantiating instances and returning them 
of other classes from within itself.

- Original Message - 
From: JesterXL [EMAIL PROTECTED]
To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com
Sent: Saturday, October 29, 2005 10:19 AM
Subject: Re: [Flashcoders] Newbie AS3 question


It does a little.  Why can't can't you just extend the base
CurrencyFormatter class and do the same thing for the formatValue function?
Rather than return the correct one for getInstance(), just utilize the
particular format class you want?

Like, do:

var val = UKCurrencyFormatter.getFormat();

and:

var val = USCurrencyFormatter.getFormat();

?

- Original Message - 
From: Spike [EMAIL PROTECTED]
To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com
Sent: Friday, October 28, 2005 10:31 PM
Subject: Re: [Flashcoders] Newbie AS3 question


Sure,

Here's a slightly more complete implementation of that last example:


public class CurrencyFormatter {

private static formatter:CurrencyFormatter;

public function getInstance():CurrencyFormatter {
// use ExternalInterface or IP lookup or whatever to determine locale
if (locale == UK) {
formatter = new UKCurrencyFormatter();
} else {
formatter = new USCurrencyFormatter();
}
return formatter;
}

class USCurrencyFormatter extends CurrencyFormatter {

public formatValue(val:Number) {
// very simplistic formatting
return $ + String(val);
}
}

class UKCurrencyFormatter extends CurrencyFormatter {

public formatValue(val:Number) {
// very simplistic formatting
return £ + String(val);
}
}

}

Let me know if that explains it a bit better.

Spike


On 10/29/05, JesterXL [EMAIL PROTECTED] wrote:

 Can you elaborate? Why wouldn't the static class work in that case?

 - Original Message -
 From: Spike [EMAIL PROTECTED]
 To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com
 Sent: Friday, October 28, 2005 9:54 PM
 Subject: Re: [Flashcoders] Newbie AS3 question


 ok,

 That's just a static class.

 Like I said, there's a subtle but important difference between singleton
 and
 a static class.

 Here's another example.

 You have a requirement to provide a currency formatter.

 One way to do this is to create a singleton that returns a different
 currency formatter depending on which locale you are in.

 So in the class you would have something like this (Omitting method
 declarations for simplicty):

 public class CurrencyFormatter {

 class USCurrencyFormatter extends CurrencyFormatter {

 }


 class UKCurrencyFormatter extends CurrencyFormatter {

 }
 }

 Now if I call CurrencyFormatter.getInstance() it gives me the correct
 formatter for my locale.

 With your static class approach you have to check in every method what the
 locale is and handle it accordingly. That's fine for one or two locales,
 but
 if you want to handle 20, it gets pretty ugly.

 You can solve the problem in other ways of course, but it does demonstrate
 the difference between static classes and the singleton pattern. The
 singleton pattern offers you a lot more possibilities.

 Spike

 On 10/29/05, JesterXL [EMAIL PROTECTED] wrote:
 
  To clarify:
 
 
  class ServerConnection
  {
  private static var url;
  private static var port;
  private static var socket;
 
  public static function connect(p_url, p_port)
  {
  url = p_url;
  port = p_port;
  socket = new Socket();
  socket.connect(url, port);
  }
 
  public static function getData()
  {
  // Simple function that gets something from the server.
  }
  }
 
  Then to use:
 
  ServerConnection.connect(myURL, myPort);
 
  - Original Message -
  From: JesterXL [EMAIL PROTECTED]
  To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com
  Sent: Friday, October 28, 2005 9:25 PM
  Subject: Re: [Flashcoders] Newbie AS3 question
 
 
  Naw, I don't know the exact way Singleton is implemented, hence my long
  battle with finding clarification. It could of been solved in 10 seconds
  over a beer, but email sux.
 
  I figured Math.abs was the Singleton pattern, and ARP, me, Sho, Steven
  Webster, and everyone else apparently has their own version of
 Controller
  as
  well. I figured I knew enough to use it.
 
  For instance, your example makes perfect sense and I can see why you'd
  want
  to do it that way. I, on the other hand would just put an if then
  statement
  in the connect method or whatever to ensure we're connected before
 making
  a
  method call, else throw an exception.
 
  Are they both the Singleton pattern? Does it matter?
 
 
  - Original Message -
  From: Spike [EMAIL PROTECTED]
  To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com
  Sent: Friday, October 28, 2005 7:14 PM
  Subject: Re: [Flashcoders] Newbie AS3 question
 
 
  Hmmm
 
  From your explanation, I think either I don't understand what happens
 in
  AS,
  or you're misunderstanding the use of the singleton pattern

Re: [Flashcoders] Newbie AS3 question

2005-10-29 Thread Martin Wood
but using Composition and a Singleton arent mutually exclusive. 
Composition is a very broad style of OO architecture, used widely 
throughout a lot of patterns.


You *might* call his example a Singleton Factory, but that probably 
confuses the issue as its not creating multiple instances of a concrete 
subclass, just creating one instance at runtime depending on particular 
external factors.


I think his example is a good one, it keeps the dependency on locale 
knowledge safely contained in one place, and as Spike says, if you start 
moving up to 20 or so locales to support, you arent going to want to 
have a massive switch / if else statement everytime you want some locale 
dependent currency formatting.


all the client code ever needs to do is ask the CurrencyFormatter for 
its instance and for that instance to format the number.



martin

JesterXL wrote:
As the coffee kicks in, that also looks like Composition, not Singleton. 
Like, you have a Singleton class instantiating instances and returning them 
of other classes from within itself.


- Original Message - 
From: JesterXL [EMAIL PROTECTED]

To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com
Sent: Saturday, October 29, 2005 10:19 AM
Subject: Re: [Flashcoders] Newbie AS3 question


It does a little.  Why can't can't you just extend the base
CurrencyFormatter class and do the same thing for the formatValue function?
Rather than return the correct one for getInstance(), just utilize the
particular format class you want?

Like, do:

var val = UKCurrencyFormatter.getFormat();

and:

var val = USCurrencyFormatter.getFormat();

?

- Original Message - 
From: Spike [EMAIL PROTECTED]

To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com
Sent: Friday, October 28, 2005 10:31 PM
Subject: Re: [Flashcoders] Newbie AS3 question


Sure,

Here's a slightly more complete implementation of that last example:


public class CurrencyFormatter {

private static formatter:CurrencyFormatter;

public function getInstance():CurrencyFormatter {
// use ExternalInterface or IP lookup or whatever to determine locale
if (locale == UK) {
formatter = new UKCurrencyFormatter();
} else {
formatter = new USCurrencyFormatter();
}
return formatter;
}

class USCurrencyFormatter extends CurrencyFormatter {

public formatValue(val:Number) {
// very simplistic formatting
return $ + String(val);
}
}

class UKCurrencyFormatter extends CurrencyFormatter {

public formatValue(val:Number) {
// very simplistic formatting
return £ + String(val);
}
}

}

Let me know if that explains it a bit better.

Spike


On 10/29/05, JesterXL [EMAIL PROTECTED] wrote:


Can you elaborate? Why wouldn't the static class work in that case?

- Original Message -
From: Spike [EMAIL PROTECTED]
To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com
Sent: Friday, October 28, 2005 9:54 PM
Subject: Re: [Flashcoders] Newbie AS3 question


ok,

That's just a static class.

Like I said, there's a subtle but important difference between singleton
and
a static class.

Here's another example.

You have a requirement to provide a currency formatter.

One way to do this is to create a singleton that returns a different
currency formatter depending on which locale you are in.

So in the class you would have something like this (Omitting method
declarations for simplicty):

public class CurrencyFormatter {

class USCurrencyFormatter extends CurrencyFormatter {

}


class UKCurrencyFormatter extends CurrencyFormatter {

}
}

Now if I call CurrencyFormatter.getInstance() it gives me the correct
formatter for my locale.

With your static class approach you have to check in every method what the
locale is and handle it accordingly. That's fine for one or two locales,
but
if you want to handle 20, it gets pretty ugly.

You can solve the problem in other ways of course, but it does demonstrate
the difference between static classes and the singleton pattern. The
singleton pattern offers you a lot more possibilities.

Spike

On 10/29/05, JesterXL [EMAIL PROTECTED] wrote:


To clarify:


class ServerConnection
{
private static var url;
private static var port;
private static var socket;

public static function connect(p_url, p_port)
{
url = p_url;
port = p_port;
socket = new Socket();
socket.connect(url, port);
}

public static function getData()
{
// Simple function that gets something from the server.
}
}

Then to use:

ServerConnection.connect(myURL, myPort);

- Original Message -
From: JesterXL [EMAIL PROTECTED]
To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com
Sent: Friday, October 28, 2005 9:25 PM
Subject: Re: [Flashcoders] Newbie AS3 question


Naw, I don't know the exact way Singleton is implemented, hence my long
battle with finding clarification. It could of been solved in 10 seconds
over a beer, but email sux.

I figured Math.abs was the Singleton pattern, and ARP, me, Sho, Steven
Webster, and everyone else apparently has their own version

Re: [Flashcoders] Newbie AS3 question

2005-10-29 Thread Spike
You're welcome!

This has been an interesting thread and I've learned a bit more about
ActionScript in the process :-)

Spike

On 10/29/05, JesterXL [EMAIL PROTECTED] wrote:

 That makes perfect sense and is a good reason.

 So, from this 2nd conversation, I've gleaned something else to add to the
 list:
 - getInstance() is a unspoken standard that implies the class is a
 Singleton
 used in other languages other than ActionScript
 - getInstance() treats a class as a true class without static properties,
 thus making it easier to go from Singleton to a true class without having
 to
 change a bunch of code, because all it really does is make 1, and only 1,
 instance of itself.

 The thought of changing multiple lines of code to go from static to non
 would really suck; that drives the point home for me. Thanks for taking
 the
 time to explain it Spike!

 - Original Message -
 From: Spike [EMAIL PROTECTED]
 To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com
 Sent: Saturday, October 29, 2005 12:05 PM
 Subject: Re: [Flashcoders] Newbie AS3 question


 It's not necessarily any better from an implementation point of view. You
 can often do the same thing with a static class as you can with a
 singleton.

 The big benefit comes if you need to change from singleton/static to
 different instances for each invocation.

 If you have followed the static class approach you have static method
 calls
 all through your code that you will need to change if the class now needs
 to
 be non-static.

 If you have followed the singleton approach, you only need to change the
 line of code that retrieves the instance inside the singleton.

 That's a pretty big benefit IMO.

 To get back to where we started all this, the original statement that
 brought all this up was your suggestion that

 Foo.someMethod()

 was identical to

 Foo.getInstance().someMethod()

 Whether one is better than another is something that can be debated to
 death, and often is on Java mailing lists, but hopefully you'll at least
 agree that they are indeed doing different things.

 Spike

 On 10/29/05, JesterXL [EMAIL PROTECTED] wrote:
 
  I would have 20 static classes, not 20 if/then/switch statements. You'd
  have that same if/then statement in the getInstance() function, though,
 to
  know which formatter to return.
 
  Again, I'm having a hard time seeing why getInstance is more appopriate
  than
  just making static classes, and how this applys to the Singleton
 pattern.
 
 
 
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders




--

Stephen Milligan
Do you do the Badger?
http://www.yellowbadger.com

Do you cfeclipse? http://www.cfeclipse.org
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


RE: [Flashcoders] Newbie AS3 question

2005-10-29 Thread Frédéric v . Bochmann
I'm not picking any sides,

The Idea of a getInstance method (Singleton), as you guys have been saying,
is to have a static way to get a non-static instance of a class. Also, that
way of working makes it easier for the creator of that class to know his
class will only get instantiated once. 

There are other advantages like the presence of a constructor and probably
many other things that you guys have also mentioned.

All this to say absolutely nothing:)


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of JesterXL
Sent: October 29, 2005 12:14 PM
To: Flashcoders mailing list
Subject: Re: [Flashcoders] Newbie AS3 question

That makes perfect sense and is a good reason.

So, from this 2nd conversation, I've gleaned something else to add to the 
list:
- getInstance() is a unspoken standard that implies the class is a Singleton

used in other languages other than ActionScript
- getInstance() treats a class as a true class without static properties, 
thus making it easier to go from Singleton to a true class without having to

change a bunch of code, because all it really does is make 1, and only 1, 
instance of itself.

The thought of changing multiple lines of code to go from static to non 
would really suck; that drives the point home for me.  Thanks for taking the

time to explain it Spike!

- Original Message - 
From: Spike [EMAIL PROTECTED]
To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com
Sent: Saturday, October 29, 2005 12:05 PM
Subject: Re: [Flashcoders] Newbie AS3 question


It's not necessarily any better from an implementation point of view. You
can often do the same thing with a static class as you can with a singleton.

The big benefit comes if you need to change from singleton/static to
different instances for each invocation.

If you have followed the static class approach you have static method calls
all through your code that you will need to change if the class now needs to
be non-static.

If you have followed the singleton approach, you only need to change the
line of code that retrieves the instance inside the singleton.

That's a pretty big benefit IMO.

To get back to where we started all this, the original statement that
brought all this up was your suggestion that

Foo.someMethod()

was identical to

Foo.getInstance().someMethod()

Whether one is better than another is something that can be debated to
death, and often is on Java mailing lists, but hopefully you'll at least
agree that they are indeed doing different things.

Spike

On 10/29/05, JesterXL [EMAIL PROTECTED] wrote:

 I would have 20 static classes, not 20 if/then/switch statements. You'd
 have that same if/then statement in the getInstance() function, though, to
 know which formatter to return.

 Again, I'm having a hard time seeing why getInstance is more appopriate
 than
 just making static classes, and how this applys to the Singleton pattern.



___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders 

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


RE: [Flashcoders] Newbie AS3 question

2005-10-29 Thread Frédéric v . Bochmann
(*Just looking back at the title of this Thread*)

Just in case someone's wonders; creating a Singleton is nothing new in
ActionScript, it can be done in AS1, AS2 or AS3.



-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Spike
Sent: October 29, 2005 12:25 PM
To: Flashcoders mailing list
Subject: Re: [Flashcoders] Newbie AS3 question

You're welcome!

This has been an interesting thread and I've learned a bit more about
ActionScript in the process :-)

Spike

On 10/29/05, JesterXL [EMAIL PROTECTED] wrote:

 That makes perfect sense and is a good reason.

 So, from this 2nd conversation, I've gleaned something else to add to the
 list:
 - getInstance() is a unspoken standard that implies the class is a
 Singleton
 used in other languages other than ActionScript
 - getInstance() treats a class as a true class without static properties,
 thus making it easier to go from Singleton to a true class without having
 to
 change a bunch of code, because all it really does is make 1, and only 1,
 instance of itself.

 The thought of changing multiple lines of code to go from static to non
 would really suck; that drives the point home for me. Thanks for taking
 the
 time to explain it Spike!

 - Original Message -
 From: Spike [EMAIL PROTECTED]
 To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com
 Sent: Saturday, October 29, 2005 12:05 PM
 Subject: Re: [Flashcoders] Newbie AS3 question


 It's not necessarily any better from an implementation point of view. You
 can often do the same thing with a static class as you can with a
 singleton.

 The big benefit comes if you need to change from singleton/static to
 different instances for each invocation.

 If you have followed the static class approach you have static method
 calls
 all through your code that you will need to change if the class now needs
 to
 be non-static.

 If you have followed the singleton approach, you only need to change the
 line of code that retrieves the instance inside the singleton.

 That's a pretty big benefit IMO.

 To get back to where we started all this, the original statement that
 brought all this up was your suggestion that

 Foo.someMethod()

 was identical to

 Foo.getInstance().someMethod()

 Whether one is better than another is something that can be debated to
 death, and often is on Java mailing lists, but hopefully you'll at least
 agree that they are indeed doing different things.

 Spike

 On 10/29/05, JesterXL [EMAIL PROTECTED] wrote:
 
  I would have 20 static classes, not 20 if/then/switch statements. You'd
  have that same if/then statement in the getInstance() function, though,
 to
  know which formatter to return.
 
  Again, I'm having a hard time seeing why getInstance is more appopriate
  than
  just making static classes, and how this applys to the Singleton
 pattern.
 
 
 
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders




--

Stephen Milligan
Do you do the Badger?
http://www.yellowbadger.com

Do you cfeclipse? http://www.cfeclipse.org
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Newbie AS3 question

2005-10-29 Thread Weyert de Boer

JesterXL wrote:


I didn't know what a Singleton was until AS2 was well underway.
 


I didn't know that it was called a Singleton until Moocks book :)
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


RE: [Flashcoders] Newbie AS3 question

2005-10-29 Thread Frédéric v . Bochmann
In AS1, I would write this a bit like that:

MyClass = function () {
  this.someProperty = whatever;
}
MyClass.instance = null;
MyClass.getInstance = function () {
  if(myClass.instance == null) {
MyClass.instance = new MyClass();
  }
  return MyClass.instance;
}
MyClass.prototope.someProperty;
MyClass.prototype.instanceMethod = function () {
  trace(value of my property: +this.someProperty);
}

That should give the same result and can be considered as a Singleton I
think. Now, I might be wrong but it sure seems to do the same thing.


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of JesterXL
Sent: October 29, 2005 12:48 PM
To: Flashcoders mailing list
Subject: Re: [Flashcoders] Newbie AS3 question

I didn't know what a Singleton was until AS2 was well underway.

- Original Message - 
From: Frédéric v. Bochmann [EMAIL PROTECTED]
To: 'Flashcoders mailing list' flashcoders@chattyfig.figleaf.com
Sent: Saturday, October 29, 2005 12:32 PM
Subject: RE: [Flashcoders] Newbie AS3 question


(*Just looking back at the title of this Thread*)

Just in case someone's wonders; creating a Singleton is nothing new in
ActionScript, it can be done in AS1, AS2 or AS3.



-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Spike
Sent: October 29, 2005 12:25 PM
To: Flashcoders mailing list
Subject: Re: [Flashcoders] Newbie AS3 question

You're welcome!

This has been an interesting thread and I've learned a bit more about
ActionScript in the process :-)

Spike

On 10/29/05, JesterXL [EMAIL PROTECTED] wrote:

 That makes perfect sense and is a good reason.

 So, from this 2nd conversation, I've gleaned something else to add to the
 list:
 - getInstance() is a unspoken standard that implies the class is a
 Singleton
 used in other languages other than ActionScript
 - getInstance() treats a class as a true class without static properties,
 thus making it easier to go from Singleton to a true class without having
 to
 change a bunch of code, because all it really does is make 1, and only 1,
 instance of itself.

 The thought of changing multiple lines of code to go from static to non
 would really suck; that drives the point home for me. Thanks for taking
 the
 time to explain it Spike!

 - Original Message -
 From: Spike [EMAIL PROTECTED]
 To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com
 Sent: Saturday, October 29, 2005 12:05 PM
 Subject: Re: [Flashcoders] Newbie AS3 question


 It's not necessarily any better from an implementation point of view. You
 can often do the same thing with a static class as you can with a
 singleton.

 The big benefit comes if you need to change from singleton/static to
 different instances for each invocation.

 If you have followed the static class approach you have static method
 calls
 all through your code that you will need to change if the class now needs
 to
 be non-static.

 If you have followed the singleton approach, you only need to change the
 line of code that retrieves the instance inside the singleton.

 That's a pretty big benefit IMO.

 To get back to where we started all this, the original statement that
 brought all this up was your suggestion that

 Foo.someMethod()

 was identical to

 Foo.getInstance().someMethod()

 Whether one is better than another is something that can be debated to
 death, and often is on Java mailing lists, but hopefully you'll at least
 agree that they are indeed doing different things.

 Spike

 On 10/29/05, JesterXL [EMAIL PROTECTED] wrote:
 
  I would have 20 static classes, not 20 if/then/switch statements. You'd
  have that same if/then statement in the getInstance() function, though,
 to
  know which formatter to return.
 
  Again, I'm having a hard time seeing why getInstance is more appopriate
  than
  just making static classes, and how this applys to the Singleton
 pattern.
 
 
 
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders




--

Stephen Milligan
Do you do the Badger?
http://www.yellowbadger.com

Do you cfeclipse? http://www.cfeclipse.org
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders 

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

___
Flashcoders mailing list

Re: [Flashcoders] Newbie AS3 question

2005-10-29 Thread Muzak
Well, actually there is a difference.
In AS3, class constructors can not be Private. In AS2 they can.

So in AS2 you can do this:

class MySingleton {
 private function MySingleton() {
 }
 public static function getInstance() {
// bah blah..
 }
}

Which is not allowed in AS3.

regards,
Muzak

- Original Message - 
From: Frédéric v. Bochmann [EMAIL PROTECTED]
To: 'Flashcoders mailing list' flashcoders@chattyfig.figleaf.com
Sent: Saturday, October 29, 2005 6:32 PM
Subject: RE: [Flashcoders] Newbie AS3 question


 (*Just looking back at the title of this Thread*)

 Just in case someone's wonders; creating a Singleton is nothing new in
 ActionScript, it can be done in AS1, AS2 or AS3.


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


RE: [Flashcoders] Newbie AS3 question

2005-10-29 Thread Frédéric v . Bochmann
Woah, I never noticed you can private your constructor!! Lol


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Muzak
Sent: October 29, 2005 1:15 PM
To: Flashcoders mailing list
Subject: Re: [Flashcoders] Newbie AS3 question

Well, actually there is a difference.
In AS3, class constructors can not be Private. In AS2 they can.

So in AS2 you can do this:

class MySingleton {
 private function MySingleton() {
 }
 public static function getInstance() {
// bah blah..
 }
}

Which is not allowed in AS3.

regards,
Muzak

- Original Message - 
From: Frédéric v. Bochmann [EMAIL PROTECTED]
To: 'Flashcoders mailing list' flashcoders@chattyfig.figleaf.com
Sent: Saturday, October 29, 2005 6:32 PM
Subject: RE: [Flashcoders] Newbie AS3 question


 (*Just looking back at the title of this Thread*)

 Just in case someone's wonders; creating a Singleton is nothing new in
 ActionScript, it can be done in AS1, AS2 or AS3.


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Newbie AS3 question

2005-10-29 Thread JesterXL
Had I been formerly trained in programming, I'm sure I would of known what a 
Singleton was years ago, and called it such before AS1 was called AS1.

However, since I had to learn how to code as well as advanced programming 
concepts at the same time, coupled by the fact ActionScript evolves so fast, 
thats why.

- Original Message - 
From: Frédéric v. Bochmann [EMAIL PROTECTED]
To: 'Flashcoders mailing list' flashcoders@chattyfig.figleaf.com
Sent: Saturday, October 29, 2005 1:18 PM
Subject: RE: [Flashcoders] Newbie AS3 question


True, nobody called that a Singleton until half way threw AS2. I think I
still don't use that word often enough. I often use something like a global
object to manage... and that often suffices for people to understand how
the implementation might have been done.

What's interesting with all this evolution of AS, is that, as it evolves
real OOP terms are being used more and more in our everyday Flash vocabulary
and that hence makes us look up those terms or simply make us remember of
those terms which brings us to better implement our code.





-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of JesterXL
Sent: October 29, 2005 12:48 PM
To: Flashcoders mailing list
Subject: Re: [Flashcoders] Newbie AS3 question

I didn't know what a Singleton was until AS2 was well underway.

- Original Message - 
From: Frédéric v. Bochmann [EMAIL PROTECTED]
To: 'Flashcoders mailing list' flashcoders@chattyfig.figleaf.com
Sent: Saturday, October 29, 2005 12:32 PM
Subject: RE: [Flashcoders] Newbie AS3 question


(*Just looking back at the title of this Thread*)

Just in case someone's wonders; creating a Singleton is nothing new in
ActionScript, it can be done in AS1, AS2 or AS3.



-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Spike
Sent: October 29, 2005 12:25 PM
To: Flashcoders mailing list
Subject: Re: [Flashcoders] Newbie AS3 question

You're welcome!

This has been an interesting thread and I've learned a bit more about
ActionScript in the process :-)

Spike

On 10/29/05, JesterXL [EMAIL PROTECTED] wrote:

 That makes perfect sense and is a good reason.

 So, from this 2nd conversation, I've gleaned something else to add to the
 list:
 - getInstance() is a unspoken standard that implies the class is a
 Singleton
 used in other languages other than ActionScript
 - getInstance() treats a class as a true class without static properties,
 thus making it easier to go from Singleton to a true class without having
 to
 change a bunch of code, because all it really does is make 1, and only 1,
 instance of itself.

 The thought of changing multiple lines of code to go from static to non
 would really suck; that drives the point home for me. Thanks for taking
 the
 time to explain it Spike!

 - Original Message -
 From: Spike [EMAIL PROTECTED]
 To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com
 Sent: Saturday, October 29, 2005 12:05 PM
 Subject: Re: [Flashcoders] Newbie AS3 question


 It's not necessarily any better from an implementation point of view. You
 can often do the same thing with a static class as you can with a
 singleton.

 The big benefit comes if you need to change from singleton/static to
 different instances for each invocation.

 If you have followed the static class approach you have static method
 calls
 all through your code that you will need to change if the class now needs
 to
 be non-static.

 If you have followed the singleton approach, you only need to change the
 line of code that retrieves the instance inside the singleton.

 That's a pretty big benefit IMO.

 To get back to where we started all this, the original statement that
 brought all this up was your suggestion that

 Foo.someMethod()

 was identical to

 Foo.getInstance().someMethod()

 Whether one is better than another is something that can be debated to
 death, and often is on Java mailing lists, but hopefully you'll at least
 agree that they are indeed doing different things.

 Spike

 On 10/29/05, JesterXL [EMAIL PROTECTED] wrote:
 
  I would have 20 static classes, not 20 if/then/switch statements. You'd
  have that same if/then statement in the getInstance() function, though,
 to
  know which formatter to return.
 
  Again, I'm having a hard time seeing why getInstance is more appopriate
  than
  just making static classes, and how this applys to the Singleton
 pattern.
 
 
 
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders




--

Stephen Milligan
Do you do the Badger?
http://www.yellowbadger.com

Do you cfeclipse? http://www.cfeclipse.org

Re: [Flashcoders] Newbie AS3 question

2005-10-29 Thread ryanm

The thought of changing multiple lines of code to go from static to non
would really suck; that drives the point home for me.  Thanks for taking 
the

time to explain it Spike!

   That's that whole maintainability thing, which, in commercial software, 
is usually just as or even more important than efficiency and optimization.


   Incidentally, the way I handled that particular example was by making a 
single dynamic class that can be instantiated as a particular locale, or can 
change locales with a single method call, with a common set of functions and 
loadable locale defenitions, which was instantiated in a singleton 
enviornment class. That way, there is only ever one application 
enviornment, but potentially several different locales that can be used to 
format dates and numbers through a common interface. It was way easier than 
making 276 static classes for all the locales I had to support. ;-)


ryanm 


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Newbie AS3 question

2005-10-29 Thread ryanm
Still weirding me out. To me part of the appeal of working with movieclips 
is their inherent hierarchy, which makes a kind of basic sense that's easy 
to grasp.


   To a Flash developer who understands Flash and has been working with it 
for a long time, that's true. To anyone coming from another language or 
platform, it makes no sense at all. It is also extremely limiting, and more 
flexxibility at the cost of an extra line of code is a beautiful trade off 
in my book.


I'm guessing part of why we're waiting til Flash 9 for this stuff is 
because it doesn't make immediate sense in a Flash IDE context yet.
   A movie clip is still a movie clip, but now, instead of being the basic 
unit of Flash, there are smaller units, such as sprites, displayobjects, 
etc. More granualrity means more control, but it also means a few extra 
lines of code.


ryanm 


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


RE: [Flashcoders] Newbie AS3 question

2005-10-28 Thread Shaw, Matt
Assuming the Game class is your root/stage class:


Public class Game extends MovieClip {
public function Game(){
var gameworld:MovieClip = new MovieClip(); //new GameWorld()?
this.addChild( gameworld );

var game_bg:MovieClip = new MovieClip();
gameworld.addChild( game_bg );
}



-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Andreas Rønning
Sent: Friday, October 28, 2005 1:08 PM
To: Flashcoders mailing list
Subject: [Flashcoders] Newbie AS3 question

AS3 noob question ahoy!

I'm reading the AS3 reference trying to get accustomed to the idea, but some 
things (though they look better) i don't really get right away :) Hence my 
feeling of incredible stupidity.

I realise the AS3 in the reference is Flex-related, but in Flash IDE terms, how 
would i do something like this in AS3:

var baseClip = _root.createEmptyMovieClip(gameworld,1);
var backGround = baseClip.createEmptyMovieClip(game_bg,1);

I get how much more practical myClip = new MovieClip(); looks, but i don't get 
how i connect a clip created this way with the traditional clip hierarchy. Is 
that out the window as well?
The reference describes |DisplayObjectContainer.addChild(), but i'm guessing 
this doesnt really count for how it'll work in the Flash IDE?

Any helpful hints at what the future holds? :)
|
- Andreas
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Newbie AS3 question

2005-10-28 Thread Andreas Rønning

Shaw, Matt wrote:


Assuming the Game class is your root/stage class:


Public class Game extends MovieClip {
public function Game(){
var gameworld:MovieClip = new MovieClip(); //new GameWorld()?
this.addChild( gameworld );

var game_bg:MovieClip = new MovieClip();
gameworld.addChild( game_bg );
}



-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Andreas Rønning
Sent: Friday, October 28, 2005 1:08 PM
To: Flashcoders mailing list
Subject: [Flashcoders] Newbie AS3 question

AS3 noob question ahoy!

I'm reading the AS3 reference trying to get accustomed to the idea, but some 
things (though they look better) i don't really get right away :) Hence my 
feeling of incredible stupidity.

I realise the AS3 in the reference is Flex-related, but in Flash IDE terms, how 
would i do something like this in AS3:

var baseClip = _root.createEmptyMovieClip(gameworld,1);
var backGround = baseClip.createEmptyMovieClip(game_bg,1);

I get how much more practical myClip = new MovieClip(); looks, but i don't get 
how i connect a clip created this way with the traditional clip hierarchy. Is 
that out the window as well?
The reference describes |DisplayObjectContainer.addChild(), but i'm guessing 
this doesnt really count for how it'll work in the Flash IDE?

Any helpful hints at what the future holds? :)
|
- Andreas
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
 


 That's horrifying.

- Andreas
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Newbie AS3 question

2005-10-28 Thread Spike
Good lord!

Why do you say that?

It's an extra 2 lines of code and it allows you to reparent any of the
children of any of the movie clipse.

I'd be more inclined to say it's awesome!

Spike

On 10/28/05, Andreas Rønning [EMAIL PROTECTED] wrote:

 Shaw, Matt wrote:

 Assuming the Game class is your root/stage class:
 
 
 Public class Game extends MovieClip {
 public function Game(){
  var gameworld:MovieClip = new MovieClip(); //new GameWorld()?
  this.addChild( gameworld );
 
  var game_bg:MovieClip = new MovieClip();
  gameworld.addChild( game_bg );
 }
 
 
 
 -Original Message-
 From: [EMAIL PROTECTED] [mailto:
 [EMAIL PROTECTED] On Behalf Of Andreas Rønning
 Sent: Friday, October 28, 2005 1:08 PM
 To: Flashcoders mailing list
 Subject: [Flashcoders] Newbie AS3 question
 
 AS3 noob question ahoy!
 
 I'm reading the AS3 reference trying to get accustomed to the idea, but
 some things (though they look better) i don't really get right away :) Hence
 my feeling of incredible stupidity.
 
 I realise the AS3 in the reference is Flex-related, but in Flash IDE
 terms, how would i do something like this in AS3:
 
 var baseClip = _root.createEmptyMovieClip(gameworld,1);
 var backGround = baseClip.createEmptyMovieClip(game_bg,1);
 
 I get how much more practical myClip = new MovieClip(); looks, but i
 don't get how i connect a clip created this way with the traditional clip
 hierarchy. Is that out the window as well?
 The reference describes |DisplayObjectContainer.addChild(), but i'm
 guessing this doesnt really count for how it'll work in the Flash IDE?
 
 Any helpful hints at what the future holds? :)
 |
 - Andreas
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
 
 
  That's horrifying.

 - Andreas
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders




--

Stephen Milligan
Do you do the Badger?
http://www.yellowbadger.com

Do you cfeclipse? http://www.cfeclipse.org
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Newbie AS3 question

2005-10-28 Thread Jon Bradley

On Oct 28, 2005, at 1:55 PM, Shaw, Matt wrote:


Assuming the Game class is your root/stage class:


Public class Game extends MovieClip {
public function Game(){
var gameworld:MovieClip = new MovieClip(); //new GameWorld()?
this.addChild( gameworld );

var game_bg:MovieClip = new MovieClip();
gameworld.addChild( game_bg );
}


What I don't get is why it needs this.addChild instead of just 
addChild.  I've been sick of the keyword this for a long time and 
have since avoided it in AS2.


Any reason that it needs to be back in for AS3?

- Jon

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


RE: [Flashcoders] Newbie AS3 question

2005-10-28 Thread Shaw, Matt
Avoiding the word this is to avoid easy to understand code

It tells you that a variable is not a local variable but a important one
that's gonna be around to a while ;]


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Jon
Bradley
Sent: Friday, October 28, 2005 2:54 PM
To: Flashcoders mailing list
Subject: Re: [Flashcoders] Newbie AS3 question

On Oct 28, 2005, at 1:55 PM, Shaw, Matt wrote:

 Assuming the Game class is your root/stage class:

 
 Public class Game extends MovieClip {
 public function Game(){
   var gameworld:MovieClip = new MovieClip(); //new GameWorld()?
   this.addChild( gameworld );

   var game_bg:MovieClip = new MovieClip();
   gameworld.addChild( game_bg );
 }

What I don't get is why it needs this.addChild instead of just
addChild.  I've been sick of the keyword this for a long time and have
since avoided it in AS2.

Any reason that it needs to be back in for AS3?

- Jon

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


RE: [Flashcoders] Newbie AS3 question

2005-10-28 Thread Geoffrey Williams
You don't need to use the 'this' keyword.

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Jon Bradley
Sent: Friday, October 28, 2005 2:54 PM
To: Flashcoders mailing list
Subject: Re: [Flashcoders] Newbie AS3 question

On Oct 28, 2005, at 1:55 PM, Shaw, Matt wrote:

 Assuming the Game class is your root/stage class:

 
 Public class Game extends MovieClip {
 public function Game(){
   var gameworld:MovieClip = new MovieClip(); //new GameWorld()?
   this.addChild( gameworld );

   var game_bg:MovieClip = new MovieClip();
   gameworld.addChild( game_bg );
 }

What I don't get is why it needs this.addChild instead of just 
addChild.  I've been sick of the keyword this for a long time and 
have since avoided it in AS2.

Any reason that it needs to be back in for AS3?

- Jon




___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


RE: [Flashcoders] Newbie AS3 question

2005-10-28 Thread Frédéric v . Bochmann
This example makes me wonder:

If I was to write this in AS2, it would probably look like:


class Game extends MovieClip {
public function Game(){
var gameworld:MovieClip = new
createEmptyMovieClip(gameworld_mc,getNextHighestDepth()); //new
GameWorld()?

var game_bg:MovieClip = gameworld.createEmptyMovieClip(game_bg_mc,
gameworld.getNextHighestDepth());

}

I wouldn't have access to addChild in AS2, how does that addChild actually
work in AS3? Are Child movieclips that are added still independent? 

For example, if I was to add two time the Background movieclip to the
gameworld movieclip in AS3.
Take for example:
...
var game_bg:MovieClip = new MovieClip();
gameworld.addChild( game_bg );
gameworld.addChild( game_bg );
...

What would happen if I affected game_bg _width or _height?
How does this go?

Just curious :)




-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Shaw, Matt
Sent: October 28, 2005 1:55 PM
To: Flashcoders mailing list
Subject: RE: [Flashcoders] Newbie AS3 question

Assuming the Game class is your root/stage class:


Public class Game extends MovieClip {
public function Game(){
var gameworld:MovieClip = new MovieClip(); //new GameWorld()?
this.addChild( gameworld );

var game_bg:MovieClip = new MovieClip();
gameworld.addChild( game_bg );
}



-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Andreas
Rønning
Sent: Friday, October 28, 2005 1:08 PM
To: Flashcoders mailing list
Subject: [Flashcoders] Newbie AS3 question

AS3 noob question ahoy!

I'm reading the AS3 reference trying to get accustomed to the idea, but some
things (though they look better) i don't really get right away :) Hence my
feeling of incredible stupidity.

I realise the AS3 in the reference is Flex-related, but in Flash IDE terms,
how would i do something like this in AS3:

var baseClip = _root.createEmptyMovieClip(gameworld,1);
var backGround = baseClip.createEmptyMovieClip(game_bg,1);

I get how much more practical myClip = new MovieClip(); looks, but i don't
get how i connect a clip created this way with the traditional clip
hierarchy. Is that out the window as well?
The reference describes |DisplayObjectContainer.addChild(), but i'm guessing
this doesnt really count for how it'll work in the Flash IDE?

Any helpful hints at what the future holds? :)
|
- Andreas
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Newbie AS3 question

2005-10-28 Thread ryanm

I'd be more inclined to say it's awesome!

   I have to agree, I'm just dissapointed that it doesn't work like that in 
Flash 8.


ryanm 


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Newbie AS3 question

2005-10-28 Thread ryanm

This example makes me wonder:

If I was to write this in AS2, it would probably look like:

   Think of it like this: createEmptyMovieClip is functionally equivilent 
to new MovieClip PLUS addChild. The benefit of seperating them is that 
you can add things to and remove things from the display list anytime you 
want, instead of creating a new movie clip and having it stuck in the scope 
you created it in.


   Think, for example, of a drag and drop paradigm. You can literally have 
something start dragging when you click it, only instead of just dragging, 
it is removed from its current container and placed in _root, so that it's 
on top of everything, and then when you drop it on another container, it is 
actually, physically (as far as that goes in the world of computers) added 
to that container. You didn't just move it from one array to another behind 
the scenes, you actually took the movie clip itself and changed which 
timeline it exists on, all without losing the state of the object.



var game_bg:MovieClip = new MovieClip();
gameworld.addChild( game_bg );
gameworld.addChild( game_bg );
...


   Think of the DisplayList as the stage, and addChild adds the movie clip 
to the stage at the next highest depth. Adding it again would do one of two 
things (depending on exactly how it was implemented), either remove it from 
the display list and add it back, which effectively did nothing, or throw an 
error because it was already on the display list. I'm pretty sure display 
objects can only have one parent.


ryanm 


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Newbie AS3 question

2005-10-28 Thread Muzak
Well, to me it's the other way around.
Code that doesn't use proper references looks messy to me.

Whe I'm lazy or in a hurry, I do skip them, but I usually find myself adding 
them afterwards anyway.

So, I'm with ryanm on this one ;-)

regards,
Muzak

- Original Message - 
From: Martin Wood [EMAIL PROTECTED]
To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com
Sent: Friday, October 28, 2005 11:03 PM
Subject: Re: [Flashcoders] Newbie AS3 question




 ryanm wrote:
 What I don't get is why it needs this.addChild instead of just addChild. 
 I've been sick of the keyword this for a long time 
 and have since avoided it in AS2.

 Any reason that it needs to be back in for AS3?

Maybe because it's one of the most useful scope references ever invented?

The fundamental concept that you seem to miss is that addChild is 
 meaningless by itself, it is a method of an object (in 
 proper OOP development), and if you just say addChild, who is adding the 
 child?

 the context is the current class. Occasionally 'this' is useful if you happen 
 to name a method parameter or local variable the 
 same as a member variable and need to distinguish the two.

 But, I dont agree that its bad form to leave it out, nor is it any more 
 difficult to maintain.

 in my opinion putting 'this' in everywhere to me just makes things harder to 
 read.

 thanks,

 Martin


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Newbie AS3 question

2005-10-28 Thread Andreas Rønning
Still weirding me out. To me part of the appeal of working with 
movieclips is their inherent hierarchy, which makes a kind of basic 
sense that's easy to grasp.
This new method seems to place more control in the hands of the 
developer, but at the same time complicating what has always been a 
really simple mechanism.
At the very least i'd expect the MovieClip constructor to accept an arg 
for its parent or somesuch so as to simplify the method.


I'm guessing part of why we're waiting til Flash 9 for this stuff is 
because it doesn't make immediate sense in a Flash IDE context yet. 
Makes a world of sense in a forms context, but with my way of working

it almost seems counterintuitive. Probably just developer paranoia though :)
I can imagine Flash 9 will look quite different to 8ball..

- Andreas

Frédéric v. Bochmann wrote:


This example makes me wonder:

If I was to write this in AS2, it would probably look like:


class Game extends MovieClip {
public function Game(){
var gameworld:MovieClip = new
createEmptyMovieClip(gameworld_mc,getNextHighestDepth()); //new
GameWorld()?

var game_bg:MovieClip = gameworld.createEmptyMovieClip(game_bg_mc,
gameworld.getNextHighestDepth());

}

I wouldn't have access to addChild in AS2, how does that addChild actually
work in AS3? Are Child movieclips that are added still independent? 


For example, if I was to add two time the Background movieclip to the
gameworld movieclip in AS3.
Take for example:
...
var game_bg:MovieClip = new MovieClip();
gameworld.addChild( game_bg );
gameworld.addChild( game_bg );
...

What would happen if I affected game_bg _width or _height?
How does this go?

Just curious :)




-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Shaw, Matt
Sent: October 28, 2005 1:55 PM
To: Flashcoders mailing list
Subject: RE: [Flashcoders] Newbie AS3 question

Assuming the Game class is your root/stage class:


Public class Game extends MovieClip {
public function Game(){
var gameworld:MovieClip = new MovieClip(); //new GameWorld()?
this.addChild( gameworld );

var game_bg:MovieClip = new MovieClip();
gameworld.addChild( game_bg );
}



-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Andreas
Rønning
Sent: Friday, October 28, 2005 1:08 PM
To: Flashcoders mailing list
Subject: [Flashcoders] Newbie AS3 question

AS3 noob question ahoy!

I'm reading the AS3 reference trying to get accustomed to the idea, but some
things (though they look better) i don't really get right away :) Hence my
feeling of incredible stupidity.

I realise the AS3 in the reference is Flex-related, but in Flash IDE terms,
how would i do something like this in AS3:

var baseClip = _root.createEmptyMovieClip(gameworld,1);
var backGround = baseClip.createEmptyMovieClip(game_bg,1);

I get how much more practical myClip = new MovieClip(); looks, but i don't
get how i connect a clip created this way with the traditional clip
hierarchy. Is that out the window as well?
The reference describes |DisplayObjectContainer.addChild(), but i'm guessing
this doesnt really count for how it'll work in the Flash IDE?

Any helpful hints at what the future holds? :)
|
- Andreas
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
 



___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Newbie AS3 question

2005-10-28 Thread Derek Vadneau
The keyword this makes sense to me.  I use it for instance variables.  I 
guess at the end of the day, though, as long as you're consistent anyone 
can pick up your code.

For MovieClip and addChild, is this similar to the way we use XML in AS2? 
As in, you use createElement, then appendChild?

I'm a little confused like Frédéric about what happens when you add a 
child multiple times.  Is a new instance created for each addChild?  If 
so, is the return a reference to the new instance? (again, in the same 
metaphor as XML children)

If this is not the case, then would adding multiple times just cause an 
error or overwrite the previous addChild?  Just wondering how you 
reference the child(ren).


Derek Vadneau



___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Newbie AS3 question

2005-10-28 Thread Spike
*snip*
AS3 and Flex both hammer the point that this really has little use other
than confirming for those programmers who are not familiar with
ActionScript. Same goes for the Singleton.method vs.
Singleton.getInstance().method argument; the latter is for those programmers
who don't know ActionScript well.
*snip*

Maybe there's something I don't understand, or maybe you typed it wrong, but
in every other OO language I've dealt with there's a significant but subtle
difference between

Singleton.getInstance().method()

and

Singleton.method()

The former is calling an instance method and the latter is calling a static
method.

Instance methods have access to instance data that is persisted as long as
the instance exists, static methods have access only to static data and that
data passed in to the method call.

Is this not true in ActionScript?

Spike

On 10/28/05, JesterXL [EMAIL PROTECTED] wrote:

 I'm the opposite end of the spectrum. This:

 class Box extends UIObject
 {
 function doStuff()
 {
 move(x + 10, y + 10);
 setSize(width + 100, height + 100);
 visible = !visible;
 }
 }

 looks more readable to me than:

 class Box extends UIObject
 {
 function doStuff()
 {
 this.move(this.x + 10, this.y + 10);
 this.setSize(this.width + 100, this.height + 100);
 this.visible = !this.visible;
 }
 }

 To each their own. I can see it justified in extending intrinsic classes,
 as the first parameter to setInterval, and the first parameter in
 Delegate.

 AS3 and Flex both hammer the point that this really has little use other
 than confirming for those programmers who are not familiar with
 ActionScript. Same goes for the Singleton.method vs.
 Singleton.getInstance().method argument; the latter is for those
 programmers
 who don't know ActionScript well.

 If you do it every day, there is no point.

 - Original Message -
 From: Muzak [EMAIL PROTECTED]
 To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com
 Sent: Friday, October 28, 2005 5:37 PM
 Subject: Re: [Flashcoders] Newbie AS3 question


 Well, to me it's the other way around.
 Code that doesn't use proper references looks messy to me.

 Whe I'm lazy or in a hurry, I do skip them, but I usually find myself
 adding
 them afterwards anyway.

 So, I'm with ryanm on this one ;-)

 regards,
 Muzak

 - Original Message -
 From: Martin Wood [EMAIL PROTECTED]
 To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com
 Sent: Friday, October 28, 2005 11:03 PM
 Subject: Re: [Flashcoders] Newbie AS3 question


 
 
  ryanm wrote:
  What I don't get is why it needs this.addChild instead of just
  addChild. I've been sick of the keyword this for a long time
  and have since avoided it in AS2.
 
  Any reason that it needs to be back in for AS3?
 
  Maybe because it's one of the most useful scope references ever
  invented?
 
  The fundamental concept that you seem to miss is that addChild is
  meaningless by itself, it is a method of an object (in
  proper OOP development), and if you just say addChild, who is adding
  the child?
 
  the context is the current class. Occasionally 'this' is useful if you
  happen to name a method parameter or local variable the
  same as a member variable and need to distinguish the two.
 
  But, I dont agree that its bad form to leave it out, nor is it any more
  difficult to maintain.
 
  in my opinion putting 'this' in everywhere to me just makes things
 harder
  to read.
 
  thanks,
 
  Martin


 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders




--

Stephen Milligan
Do you do the Badger?
http://www.yellowbadger.com

Do you cfeclipse? http://www.cfeclipse.org
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Newbie AS3 question

2005-10-28 Thread JesterXL
ActionScript 2, no, no difference.  You actually have to do a tincy bit of 
extra work to get AS2 to support getInstance like I've seen it in Java.

This all goes way in AS3 since prototype is strictly in the hands of 
flash.util.Proxy; basically, prototype is now read-only, and Proxy is the 
only one who can wriggle around the rules in the new AVM.

That's the one thing that always pissed me off about Cairngorm, and I 
debated for days on the ARP Advisory list till I was overulled merely by 
strength of numbers of opposing viewpoints.

First, to clarify, when I speak of Singleton.getInstance(), I speak of the 
only way to utilize the Singleton's methods, so yes, if you want to call it 
calling a method on an instance, that's fine, but it's still spoken of as a 
Singleton only has 1 instance.

That being the case, what I used to like to do was, even from AS1:

class MyClass
{
public static function sup()
{
trace(yo);
}
}

Which boils down to:

function MyClass()
{
}

MyClass.sup = function()
{
trace(yo);
};

Therefore, allowing this:

MyClass.sup();

Since Functions are objects in ActionScript 1  2, and about the same in 3.

However, when talking about why EventDispatcher in Cairngorm, and Controller 
in ARP both have the getInstance method, I was told that it was to ensure 
that there was only ever 1 instance of it.

I replied that there is; it's already defined, use it.  Math.abs() works 
just fine, you don't do Math.getInstance().abs(), so why should I have to do 
that extra function when I know there is only 1 instance, and it's static, 
and ready to go?

Fast-forward 4 days, class based vs. protoytpe languages, and demographics 
exploration later, and I see their point; if you don't understand how 
ActionScript is written, doing things like Math.random() really doesn't make 
any sense to traditional programmers, and having to know that much about how 
a language works is really unfair, doesn't make people want to dive in 
without it being familiar  comfortable, and is an elitist stance.

So, although I think getIstance() isn't technically needed (in AS1 or AS2), 
I still see the need for it, and respect it from a traditional developer 
standpoint.

- Original Message - 
From: Spike [EMAIL PROTECTED]
To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com
Sent: Friday, October 28, 2005 6:38 PM
Subject: Re: [Flashcoders] Newbie AS3 question


*snip*
AS3 and Flex both hammer the point that this really has little use other
than confirming for those programmers who are not familiar with
ActionScript. Same goes for the Singleton.method vs.
Singleton.getInstance().method argument; the latter is for those programmers
who don't know ActionScript well.
*snip*

Maybe there's something I don't understand, or maybe you typed it wrong, but
in every other OO language I've dealt with there's a significant but subtle
difference between

Singleton.getInstance().method()

and

Singleton.method()

The former is calling an instance method and the latter is calling a static
method.

Instance methods have access to instance data that is persisted as long as
the instance exists, static methods have access only to static data and that
data passed in to the method call.

Is this not true in ActionScript?

Spike

On 10/28/05, JesterXL [EMAIL PROTECTED] wrote:

 I'm the opposite end of the spectrum. This:

 class Box extends UIObject
 {
 function doStuff()
 {
 move(x + 10, y + 10);
 setSize(width + 100, height + 100);
 visible = !visible;
 }
 }

 looks more readable to me than:

 class Box extends UIObject
 {
 function doStuff()
 {
 this.move(this.x + 10, this.y + 10);
 this.setSize(this.width + 100, this.height + 100);
 this.visible = !this.visible;
 }
 }

 To each their own. I can see it justified in extending intrinsic classes,
 as the first parameter to setInterval, and the first parameter in
 Delegate.

 AS3 and Flex both hammer the point that this really has little use other
 than confirming for those programmers who are not familiar with
 ActionScript. Same goes for the Singleton.method vs.
 Singleton.getInstance().method argument; the latter is for those
 programmers
 who don't know ActionScript well.

 If you do it every day, there is no point.

 - Original Message -
 From: Muzak [EMAIL PROTECTED]
 To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com
 Sent: Friday, October 28, 2005 5:37 PM
 Subject: Re: [Flashcoders] Newbie AS3 question


 Well, to me it's the other way around.
 Code that doesn't use proper references looks messy to me.

 Whe I'm lazy or in a hurry, I do skip them, but I usually find myself
 adding
 them afterwards anyway.

 So, I'm with ryanm on this one ;-)

 regards,
 Muzak

 - Original Message -
 From: Martin Wood [EMAIL PROTECTED]
 To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com
 Sent: Friday, October 28, 2005 11:03 PM
 Subject: Re: [Flashcoders] Newbie AS3 question


 
 
  ryanm wrote:
  What I don't get is why

Re: [Flashcoders] Newbie AS3 question

2005-10-28 Thread JesterXL
Close; the MovieClip IS instantiated, just not drawn.  I think Ryan said it 
best earlier when you think of:

var a:MovieClip = createEmptyMovieClip(mc);

as:

var a:MovieClip = new MovieClip();
addChild(a);

addChild merely tells Flash to draw it each frame.

So yeah, you could have a list, and choose which one you want to draw, when, 
and where in the DL.

Absolutely; you can screw with the movieclips as much as you want without 
having them drawn; they are valid movieclip objects with all the methods and 
properties to boot.

- Original Message - 
From: Michael Bedar [EMAIL PROTECTED]
To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com
Sent: Friday, October 28, 2005 6:40 PM
Subject: Re: [Flashcoders] Newbie AS3 question


ok, so if in AS 3.0 i make an array of new MovieClip() objects, i
can choose to only keep one actually instantiated by only adding the
one i want to the display list?  Can such movieclip objects that are
not in the display list be manipulated?





On Oct 28, 2005, at 2:21 PM, Spike wrote:

 Good lord!

 Why do you say that?

 It's an extra 2 lines of code and it allows you to reparent any of the
 children of any of the movie clipse.

 I'd be more inclined to say it's awesome!

 Spike

 On 10/28/05, Andreas Rønning [EMAIL PROTECTED] wrote:


 Shaw, Matt wrote:


 Assuming the Game class is your root/stage class:

 
 Public class Game extends MovieClip {
 public function Game(){
 var gameworld:MovieClip = new MovieClip(); //new GameWorld()?
 this.addChild( gameworld );

 var game_bg:MovieClip = new MovieClip();
 gameworld.addChild( game_bg );
 }



 -Original Message-
 From: [EMAIL PROTECTED] [mailto:

 [EMAIL PROTECTED] On Behalf Of Andreas
 Rønning

 Sent: Friday, October 28, 2005 1:08 PM
 To: Flashcoders mailing list
 Subject: [Flashcoders] Newbie AS3 question

 AS3 noob question ahoy!

 I'm reading the AS3 reference trying to get accustomed to the
 idea, but

 some things (though they look better) i don't really get right
 away :) Hence
 my feeling of incredible stupidity.


 I realise the AS3 in the reference is Flex-related, but in Flash IDE

 terms, how would i do something like this in AS3:


 var baseClip = _root.createEmptyMovieClip(gameworld,1);
 var backGround = baseClip.createEmptyMovieClip(game_bg,1);

 I get how much more practical myClip = new MovieClip(); looks, but i

 don't get how i connect a clip created this way with the
 traditional clip
 hierarchy. Is that out the window as well?

 The reference describes |DisplayObjectContainer.addChild(), but i'm

 guessing this doesnt really count for how it'll work in the Flash
 IDE?


 Any helpful hints at what the future holds? :)
 |
 - Andreas
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders



  That's horrifying.

 - Andreas
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders





 --
 
 Stephen Milligan
 Do you do the Badger?
 http://www.yellowbadger.com

 Do you cfeclipse? http://www.cfeclipse.org
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders 

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Newbie AS3 question

2005-10-28 Thread JesterXL
Example:

var a:MovieClip = new MovieClip();
a.graphics.beginFill(0x00);
a.graphics.lineTo(100, 0);
a.graphics.endFill();

That creates a new MovieClip, and draws a black line in it.

But, you won't see anything drawn on the screen until you actually add it to 
the DL.

- Original Message - 
From: JesterXL [EMAIL PROTECTED]
To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com
Sent: Friday, October 28, 2005 6:58 PM
Subject: Re: [Flashcoders] Newbie AS3 question


Close; the MovieClip IS instantiated, just not drawn.  I think Ryan said it
best earlier when you think of:

var a:MovieClip = createEmptyMovieClip(mc);

as:

var a:MovieClip = new MovieClip();
addChild(a);

addChild merely tells Flash to draw it each frame.

So yeah, you could have a list, and choose which one you want to draw, when,
and where in the DL.

Absolutely; you can screw with the movieclips as much as you want without
having them drawn; they are valid movieclip objects with all the methods and
properties to boot.

- Original Message - 
From: Michael Bedar [EMAIL PROTECTED]
To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com
Sent: Friday, October 28, 2005 6:40 PM
Subject: Re: [Flashcoders] Newbie AS3 question


ok, so if in AS 3.0 i make an array of new MovieClip() objects, i
can choose to only keep one actually instantiated by only adding the
one i want to the display list?  Can such movieclip objects that are
not in the display list be manipulated?





On Oct 28, 2005, at 2:21 PM, Spike wrote:

 Good lord!

 Why do you say that?

 It's an extra 2 lines of code and it allows you to reparent any of the
 children of any of the movie clipse.

 I'd be more inclined to say it's awesome!

 Spike

 On 10/28/05, Andreas Rønning [EMAIL PROTECTED] wrote:


 Shaw, Matt wrote:


 Assuming the Game class is your root/stage class:

 
 Public class Game extends MovieClip {
 public function Game(){
 var gameworld:MovieClip = new MovieClip(); //new GameWorld()?
 this.addChild( gameworld );

 var game_bg:MovieClip = new MovieClip();
 gameworld.addChild( game_bg );
 }



 -Original Message-
 From: [EMAIL PROTECTED] [mailto:

 [EMAIL PROTECTED] On Behalf Of Andreas
 Rønning

 Sent: Friday, October 28, 2005 1:08 PM
 To: Flashcoders mailing list
 Subject: [Flashcoders] Newbie AS3 question

 AS3 noob question ahoy!

 I'm reading the AS3 reference trying to get accustomed to the
 idea, but

 some things (though they look better) i don't really get right
 away :) Hence
 my feeling of incredible stupidity.


 I realise the AS3 in the reference is Flex-related, but in Flash IDE

 terms, how would i do something like this in AS3:


 var baseClip = _root.createEmptyMovieClip(gameworld,1);
 var backGround = baseClip.createEmptyMovieClip(game_bg,1);

 I get how much more practical myClip = new MovieClip(); looks, but i

 don't get how i connect a clip created this way with the
 traditional clip
 hierarchy. Is that out the window as well?

 The reference describes |DisplayObjectContainer.addChild(), but i'm

 guessing this doesnt really count for how it'll work in the Flash
 IDE?


 Any helpful hints at what the future holds? :)
 |
 - Andreas
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders



  That's horrifying.

 - Andreas
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders





 --
 
 Stephen Milligan
 Do you do the Badger?
 http://www.yellowbadger.com

 Do you cfeclipse? http://www.cfeclipse.org
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders 

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


RE: [Flashcoders] Newbie AS3 question

2005-10-28 Thread Frédéric v . Bochmann
What's drawn at each frame is it only the BitmapData representation of the
movieclip or is it the actual movieclip? I know technically that could
end-up to the same thing, that's why I'm curious.

Just trying to get a good grasp of how addChild and new MovieClip work
internally.

Anyone know?

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of JesterXL
Sent: October 28, 2005 6:58 PM
To: Flashcoders mailing list
Subject: Re: [Flashcoders] Newbie AS3 question

Close; the MovieClip IS instantiated, just not drawn.  I think Ryan said it 
best earlier when you think of:

var a:MovieClip = createEmptyMovieClip(mc);

as:

var a:MovieClip = new MovieClip();
addChild(a);

addChild merely tells Flash to draw it each frame.

So yeah, you could have a list, and choose which one you want to draw, when,

and where in the DL.

Absolutely; you can screw with the movieclips as much as you want without 
having them drawn; they are valid movieclip objects with all the methods and

properties to boot.

- Original Message - 
From: Michael Bedar [EMAIL PROTECTED]
To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com
Sent: Friday, October 28, 2005 6:40 PM
Subject: Re: [Flashcoders] Newbie AS3 question


ok, so if in AS 3.0 i make an array of new MovieClip() objects, i
can choose to only keep one actually instantiated by only adding the
one i want to the display list?  Can such movieclip objects that are
not in the display list be manipulated?





On Oct 28, 2005, at 2:21 PM, Spike wrote:

 Good lord!

 Why do you say that?

 It's an extra 2 lines of code and it allows you to reparent any of the
 children of any of the movie clipse.

 I'd be more inclined to say it's awesome!

 Spike

 On 10/28/05, Andreas Rønning [EMAIL PROTECTED] wrote:


 Shaw, Matt wrote:


 Assuming the Game class is your root/stage class:

 
 Public class Game extends MovieClip {
 public function Game(){
 var gameworld:MovieClip = new MovieClip(); //new GameWorld()?
 this.addChild( gameworld );

 var game_bg:MovieClip = new MovieClip();
 gameworld.addChild( game_bg );
 }



 -Original Message-
 From: [EMAIL PROTECTED] [mailto:

 [EMAIL PROTECTED] On Behalf Of Andreas
 Rønning

 Sent: Friday, October 28, 2005 1:08 PM
 To: Flashcoders mailing list
 Subject: [Flashcoders] Newbie AS3 question

 AS3 noob question ahoy!

 I'm reading the AS3 reference trying to get accustomed to the
 idea, but

 some things (though they look better) i don't really get right
 away :) Hence
 my feeling of incredible stupidity.


 I realise the AS3 in the reference is Flex-related, but in Flash IDE

 terms, how would i do something like this in AS3:


 var baseClip = _root.createEmptyMovieClip(gameworld,1);
 var backGround = baseClip.createEmptyMovieClip(game_bg,1);

 I get how much more practical myClip = new MovieClip(); looks, but i

 don't get how i connect a clip created this way with the
 traditional clip
 hierarchy. Is that out the window as well?

 The reference describes |DisplayObjectContainer.addChild(), but i'm

 guessing this doesnt really count for how it'll work in the Flash
 IDE?


 Any helpful hints at what the future holds? :)
 |
 - Andreas
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders



  That's horrifying.

 - Andreas
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders





 --
 
 Stephen Milligan
 Do you do the Badger?
 http://www.yellowbadger.com

 Do you cfeclipse? http://www.cfeclipse.org
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders 

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Newbie AS3 question

2005-10-28 Thread JesterXL
To clarify:


class ServerConnection
{
private static var url;
private static var port;
private static var socket;

public static function connect(p_url, p_port)
{
url = p_url;
port = p_port;
socket = new Socket();
socket.connect(url, port);
}

public static function getData()
{
// Simple function that gets something from the server.
}
  }

Then to use:

ServerConnection.connect(myURL, myPort);

- Original Message - 
From: JesterXL [EMAIL PROTECTED]
To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com
Sent: Friday, October 28, 2005 9:25 PM
Subject: Re: [Flashcoders] Newbie AS3 question


Naw, I don't know the exact way Singleton is implemented, hence my long
battle with finding clarification.  It could of been solved in 10 seconds
over a beer, but email sux.

I figured Math.abs was the Singleton pattern, and ARP, me, Sho, Steven
Webster, and everyone else apparently has their own version of Controller as
well.  I figured I knew enough to use it.

For instance, your example makes perfect sense and I can see why you'd want
to do it that way.  I, on the other hand would just put an if then statement
in the connect method or whatever to ensure we're connected before making a
method call, else throw an exception.

Are they both the Singleton pattern?  Does it matter?


- Original Message - 
From: Spike [EMAIL PROTECTED]
To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com
Sent: Friday, October 28, 2005 7:14 PM
Subject: Re: [Flashcoders] Newbie AS3 question


Hmmm

From your explanation, I think either I don't understand what happens in
AS,
or you're misunderstanding the use of the singleton pattern.

In an attempt to understand better, here's an example of where I would use
the singleton pattern.

I have a requirement to talk to a socket on a server, but I need to make
sure that I only ever have a single connection from each user.

So...

I create a ServerConnection class that has something like this (ignoring
private constructors etc.):

ServerConnection {

private static instance:ServerConnection;

static function getInstance() {
if (this.instance == null) {
instance = new ServerConnection(url,port);
} else {
// make sure that the port and url for the instance match the passed url and
port.
// if not, barf an error
}
return instance;
}

public function getData() {
// Simple function that gets something from the server.
}
}

ok, so I have now guaranteed that I will only ever create a single
connection to the server because I'm always getting the same object back
regardless of how many times I call getInstance() in my code.

So I can happily do this anywhere I like in my code:

ServerConnection.getInstance().getData()

If I had something like what you have in the Math class, the getData()
method would have to be declared as static and it would have to check every
time you called it to see if there was an active connnection to the server.
If not it would have to create one and you would have to hope that 2 method
calls didn't step on each other and create multiple server connections.

Not sure if that clarifies or confuses, but hopefully you can let me know if
and how it differs in Flash.

Spike

On 10/28/05, JesterXL [EMAIL PROTECTED] wrote:

 ActionScript 2, no, no difference. You actually have to do a tincy bit of
 extra work to get AS2 to support getInstance like I've seen it in Java.

 This all goes way in AS3 since prototype is strictly in the hands of
 flash.util.Proxy; basically, prototype is now read-only, and Proxy is the
 only one who can wriggle around the rules in the new AVM.

 That's the one thing that always pissed me off about Cairngorm, and I
 debated for days on the ARP Advisory list till I was overulled merely by
 strength of numbers of opposing viewpoints.

 First, to clarify, when I speak of Singleton.getInstance(), I speak of the
 only way to utilize the Singleton's methods, so yes, if you want to call
 it
 calling a method on an instance, that's fine, but it's still spoken of as
 a
 Singleton only has 1 instance.

 That being the case, what I used to like to do was, even from AS1:

 class MyClass
 {
 public static function sup()
 {
 trace(yo);
 }
 }

 Which boils down to:

 function MyClass()
 {
 }

 MyClass.sup = function()
 {
 trace(yo);
 };

 Therefore, allowing this:

 MyClass.sup();

 Since Functions are objects in ActionScript 1  2, and about the same in
 3.

 However, when talking about why EventDispatcher in Cairngorm, and
 Controller
 in ARP both have the getInstance method, I was told that it was to ensure
 that there was only ever 1 instance of it.

 I replied that there is; it's already defined, use it. Math.abs() works
 just fine, you don't do Math.getInstance().abs(), so why should I have to
 do
 that extra function when I know there is only 1 instance, and it's static,
 and ready to go?

 Fast-forward 4 days, class based vs. protoytpe languages, and demographics

Re: [Flashcoders] Newbie AS3 question

2005-10-28 Thread JesterXL
Can you elaborate?  Why wouldn't the static class work in that case?

- Original Message - 
From: Spike [EMAIL PROTECTED]
To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com
Sent: Friday, October 28, 2005 9:54 PM
Subject: Re: [Flashcoders] Newbie AS3 question


ok,

That's just a static class.

Like I said, there's a subtle but important difference between singleton and
a static class.

Here's another example.

You have a requirement to provide a currency formatter.

One way to do this is to create a singleton that returns a different
currency formatter depending on which locale you are in.

So in the class you would have something like this (Omitting method
declarations for simplicty):

public class CurrencyFormatter {

class USCurrencyFormatter extends CurrencyFormatter {

}


class UKCurrencyFormatter extends CurrencyFormatter {

}
}

Now if I call CurrencyFormatter.getInstance() it gives me the correct
formatter for my locale.

With your static class approach you have to check in every method what the
locale is and handle it accordingly. That's fine for one or two locales, but
if you want to handle 20, it gets pretty ugly.

You can solve the problem in other ways of course, but it does demonstrate
the difference between static classes and the singleton pattern. The
singleton pattern offers you a lot more possibilities.

Spike

On 10/29/05, JesterXL [EMAIL PROTECTED] wrote:

 To clarify:


 class ServerConnection
 {
 private static var url;
 private static var port;
 private static var socket;

 public static function connect(p_url, p_port)
 {
 url = p_url;
 port = p_port;
 socket = new Socket();
 socket.connect(url, port);
 }

 public static function getData()
 {
 // Simple function that gets something from the server.
 }
 }

 Then to use:

 ServerConnection.connect(myURL, myPort);

 - Original Message -
 From: JesterXL [EMAIL PROTECTED]
 To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com
 Sent: Friday, October 28, 2005 9:25 PM
 Subject: Re: [Flashcoders] Newbie AS3 question


 Naw, I don't know the exact way Singleton is implemented, hence my long
 battle with finding clarification. It could of been solved in 10 seconds
 over a beer, but email sux.

 I figured Math.abs was the Singleton pattern, and ARP, me, Sho, Steven
 Webster, and everyone else apparently has their own version of Controller
 as
 well. I figured I knew enough to use it.

 For instance, your example makes perfect sense and I can see why you'd
 want
 to do it that way. I, on the other hand would just put an if then
 statement
 in the connect method or whatever to ensure we're connected before making
 a
 method call, else throw an exception.

 Are they both the Singleton pattern? Does it matter?


 - Original Message -
 From: Spike [EMAIL PROTECTED]
 To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com
 Sent: Friday, October 28, 2005 7:14 PM
 Subject: Re: [Flashcoders] Newbie AS3 question


 Hmmm

 From your explanation, I think either I don't understand what happens in
 AS,
 or you're misunderstanding the use of the singleton pattern.

 In an attempt to understand better, here's an example of where I would use
 the singleton pattern.

 I have a requirement to talk to a socket on a server, but I need to make
 sure that I only ever have a single connection from each user.

 So...

 I create a ServerConnection class that has something like this (ignoring
 private constructors etc.):

 ServerConnection {

 private static instance:ServerConnection;

 static function getInstance() {
 if (this.instance == null) {
 instance = new ServerConnection(url,port);
 } else {
 // make sure that the port and url for the instance match the passed url
 and
 port.
 // if not, barf an error
 }
 return instance;
 }

 public function getData() {
 // Simple function that gets something from the server.
 }
 }

 ok, so I have now guaranteed that I will only ever create a single
 connection to the server because I'm always getting the same object back
 regardless of how many times I call getInstance() in my code.

 So I can happily do this anywhere I like in my code:

 ServerConnection.getInstance().getData()

 If I had something like what you have in the Math class, the getData()
 method would have to be declared as static and it would have to check
 every
 time you called it to see if there was an active connnection to the
 server.
 If not it would have to create one and you would have to hope that 2
 method
 calls didn't step on each other and create multiple server connections.

 Not sure if that clarifies or confuses, but hopefully you can let me know
 if
 and how it differs in Flash.

 Spike

 On 10/28/05, JesterXL [EMAIL PROTECTED] wrote:
 
  ActionScript 2, no, no difference. You actually have to do a tincy bit
 of
  extra work to get AS2 to support getInstance like I've seen it in Java.
 
  This all goes way in AS3 since prototype is strictly in the hands of
  flash.util.Proxy; basically