Re: [Flashcoders] component def doesn't pass params to constructor?

2009-02-19 Thread Gregory N
Michael,

Haven't you read my reply to one of your prev. questions?
Well, let me quote it here again:
===
Subject: Re: [Flashcoders] my component not instancing properly on  timeline

It seems your problem is similar to one I had with my components.
The matter is that, unlike their behavior in AS2, in AS3 (CS3)
components setters of  [Inspectable] parameters are called lo-o-ong
AFTER constructor

As described here
 http://www.bit-101.com/blog/?p=1181
So, even if I set my init() as listener for ADDED_TO_STAGE event...
it's still before setters.

for now, I found a solution:
I put my init() in ENTER_FRAME listener and then remove this listener :-)
This means that listeners are called before 1st  ENTER_FRAME event.
Perhaps my solution isn't too elegant but it works :-)

Also, be sure to duplicate default values for your parameters :-)
===

Note that the above solution is intended to use with sprite-based components.
Perhaps if you subclass UIComponent, the situation with setters is
better... perhaps :-)



On 2/18/09, Muzak p.ginnebe...@telenet.be wrote:
 You can either make a component designed for the
 stage OR for instancing through code?

 Not really, that's not what it says.
 Just says that you can't (and IMO should never have to) pass arguments to
 the constructor when dropped on stage.

 If you want talk to your component both through AS and when on stage, use
 [Inspectable] getter/setters

 class MyComp {

 [Inspectable]
 public function get symbolName():String {
 return _symbolName
 }
 public function set symbolName(value:String):void {
 _symbolName = value;
 // do stuff with value
 }
 }

 regards,
 Muzak

 - Original Message -
 From: Mendelsohn, Michael michael.mendels...@fmglobal.com
 To: Flash Coders List flashcoders@chattyfig.figleaf.com
 Sent: Wednesday, February 18, 2009 6:55 PM
 Subject: RE: [Flashcoders] component def doesn't pass params to constructor?


 Hi list...

 Researching my own pesky issue (custom components initializing properly
 when they're dragged on the stage at author time), I found this:

 if you want to create instances of your classes by dragging them to
 the stage, keep in mind that their constuctors can not accept arguments.
 Also, keep in mind that
 Its a really good idea to pick unique names for your custom classes.
 It's widely agreed class-names should start with the capital letter

 Source: http://www.actionscript.org/forums/showthread.php3?t=159332

 So, is this true??  You can either make a component designed for the
 stage OR for instancing through code?  That seems wrong in AS3.

 Any feedback is appreciated.
 - Michael M.


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



-- 
-- 
Best regards,
 GregoryN

http://GOusable.com
Flash components development.
Usability services.
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] component def doesn't pass params to constructor?

2009-02-19 Thread Gregory N
Muzak,

Nice addition, thanks for pointing to it.
Frankly, I'd prefer to avoid calling commitProperties() after *each*
of the setters...
Anyway, this way looks better than my enter_frame trick :-)

However, the problem  none of the setters are called if no
inspectable params were changed still remains. So we have to
duplicate default values in [Inspectable] and constructor/declaration
(or some init function)

On 2/19/09, Muzak p.ginnebe...@telenet.be wrote:
 This workflow is more or less what the Flex components follow:

 package {

  import flash.display.MovieClip;

  public class Rectangle extends MovieClip {

   private var _prop:String = Hello;
   private var propChanged:Boolean = false;

   public function Rectangle():void {
trace(Rectangle ::: CONSTRUCTOR);
init();
   }

   private function init():void {
trace(Rectangle ::: init);
// do stuff here
commitProperties();
   }

   protected function commitProperties():void {
trace(Rectangle ::: commitProperties);
if(propChanged) {
 trace(- propChanged: , propChanged);
 trace(- prop: , _prop);
 propChanged = false;
 // do stuff with _prop
}
   }

   [Inspectable(defaultValue=Hello)]
   public function get prop():String {
trace(Rectangle ::: get prop);
return _prop;
   }
   public function set prop(value:String):void {
trace(Rectangle ::: set prop);
if(value != _prop) {
 _prop = value;
 propChanged = true;
 commitProperties();
}
   }
  }
 }

 regards,
 Muzak

 - Original Message -
 From: Gregory N greg.gousa...@gmail.com
 To: Flash Coders List flashcoders@chattyfig.figleaf.com
 Sent: Thursday, February 19, 2009 10:25 AM
 Subject: Re: [Flashcoders] component def doesn't pass params to constructor?


 Michael,

 Haven't you read my reply to one of your prev. questions?
 Well, let me quote it here again:
 ===
 Subject: Re: [Flashcoders] my component not instancing properly on
 timeline

 It seems your problem is similar to one I had with my components.
 The matter is that, unlike their behavior in AS2, in AS3 (CS3)
 components setters of  [Inspectable] parameters are called lo-o-ong
 AFTER constructor

 As described here
 http://www.bit-101.com/blog/?p=1181
 So, even if I set my init() as listener for ADDED_TO_STAGE event...
 it's still before setters.

 for now, I found a solution:
 I put my init() in ENTER_FRAME listener and then remove this listener :-)
 This means that listeners are called before 1st  ENTER_FRAME event.
 Perhaps my solution isn't too elegant but it works :-)

 Also, be sure to duplicate default values for your parameters :-)
 ===

 Note that the above solution is intended to use with sprite-based
 components.
 Perhaps if you subclass UIComponent, the situation with setters is
 better... perhaps :-)




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



-- 
-- 
Best regards,
 GregoryN

http://GOusable.com
Flash components development.
Usability services.
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] component def doesn't pass params to constructor?

2009-02-19 Thread Gregory N
After some consideration...

If I have, say dozen of Inspectable parameters AND a method that need
several of them to work properly, then I'll have to call this method
after a delay - to be sure that all necessary setters were called
before it..
Thus, turning back to enter_frame trick :-(
Or am I missing something trivial?

On 2/19/09, Gregory N greg.gousa...@gmail.com wrote:
 Muzak,

 Nice addition, thanks for pointing to it.
 Frankly, I'd prefer to avoid calling commitProperties() after *each*
 of the setters...
 Anyway, this way looks better than my enter_frame trick :-)

 However, the problem  none of the setters are called if no
 inspectable params were changed still remains. So we have to
 duplicate default values in [Inspectable] and constructor/declaration
 (or some init function)

 On 2/19/09, Muzak p.ginnebe...@telenet.be wrote:
 This workflow is more or less what the Flex components follow:

 package {

  import flash.display.MovieClip;

  public class Rectangle extends MovieClip {

   private var _prop:String = Hello;
   private var propChanged:Boolean = false;

   public function Rectangle():void {
trace(Rectangle ::: CONSTRUCTOR);
init();
   }

   private function init():void {
trace(Rectangle ::: init);
// do stuff here
commitProperties();
   }

   protected function commitProperties():void {
trace(Rectangle ::: commitProperties);
if(propChanged) {
 trace(- propChanged: , propChanged);
 trace(- prop: , _prop);
 propChanged = false;
 // do stuff with _prop
}
   }

   [Inspectable(defaultValue=Hello)]
   public function get prop():String {
trace(Rectangle ::: get prop);
return _prop;
   }
   public function set prop(value:String):void {
trace(Rectangle ::: set prop);
if(value != _prop) {
 _prop = value;
 propChanged = true;
 commitProperties();
}
   }
  }
 }

 regards,
 Muzak

 - Original Message -
 From: Gregory N greg.gousa...@gmail.com
 To: Flash Coders List flashcoders@chattyfig.figleaf.com
 Sent: Thursday, February 19, 2009 10:25 AM
 Subject: Re: [Flashcoders] component def doesn't pass params to
 constructor?


 Michael,

 Haven't you read my reply to one of your prev. questions?
 Well, let me quote it here again:
 ===
 Subject: Re: [Flashcoders] my component not instancing properly on
 timeline

 It seems your problem is similar to one I had with my components.
 The matter is that, unlike their behavior in AS2, in AS3 (CS3)
 components setters of  [Inspectable] parameters are called lo-o-ong
 AFTER constructor

 As described here
 http://www.bit-101.com/blog/?p=1181
 So, even if I set my init() as listener for ADDED_TO_STAGE event...
 it's still before setters.

 for now, I found a solution:
 I put my init() in ENTER_FRAME listener and then remove this listener
 :-)
 This means that listeners are called before 1st  ENTER_FRAME event.
 Perhaps my solution isn't too elegant but it works :-)

 Also, be sure to duplicate default values for your parameters :-)
 ===

 Note that the above solution is intended to use with sprite-based
 components.
 Perhaps if you subclass UIComponent, the situation with setters is
 better... perhaps :-)




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



 --
 --
 Best regards,
  GregoryN
 
 http://GOusable.com
 Flash components development.
 Usability services.



-- 
-- 
Best regards,
 GregoryN

http://GOusable.com
Flash components development.
Usability services.
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] component def doesn't pass params to constructor?

2009-02-19 Thread Taka Kojima
As Weyert was getting at, just use default argument values, which
would only be applied if you didn't specify an argument...

i.e.

   public function Ball(which:String = soccerball){
   gotoAndStop(which);
   }

this way you can do:

var b:Ball = new Ball(basketball);
addChild(b);

and you can drag an instance to the stage (which would default going
to frame soccerball

but, seeing as it is a component, you probably want to have an
inspectable, these are properties that can be set through the
Component Inspector

If I were to write the class/component, I would probably do write it like:

package{

import flash.display.MovieClip;

public class Ball extends MovieClip{

private var _ballType:String = ;

[Inspectable(name=Ball Type, defaultValue = soccerball,  
type = String)]

public function set ballType(_value:String):void{
_ballType= _value;
gotoAndStop(_ballType);
}
public function get ballType():String{return _ballType;}

public function Ball(which:String = soccerball){
ballType = which;
}
}
}

- Taka

On Thu, Feb 19, 2009 at 9:12 AM, Gregory N greg.gousa...@gmail.com wrote:
 Muzak,

 Nice addition, thanks for pointing to it.
 Frankly, I'd prefer to avoid calling commitProperties() after *each*
 of the setters...
 Anyway, this way looks better than my enter_frame trick :-)

 However, the problem  none of the setters are called if no
 inspectable params were changed still remains. So we have to
 duplicate default values in [Inspectable] and constructor/declaration
 (or some init function)

 On 2/19/09, Muzak p.ginnebe...@telenet.be wrote:
 This workflow is more or less what the Flex components follow:

 package {

  import flash.display.MovieClip;

  public class Rectangle extends MovieClip {

   private var _prop:String = Hello;
   private var propChanged:Boolean = false;

   public function Rectangle():void {
trace(Rectangle ::: CONSTRUCTOR);
init();
   }

   private function init():void {
trace(Rectangle ::: init);
// do stuff here
commitProperties();
   }

   protected function commitProperties():void {
trace(Rectangle ::: commitProperties);
if(propChanged) {
 trace(- propChanged: , propChanged);
 trace(- prop: , _prop);
 propChanged = false;
 // do stuff with _prop
}
   }

   [Inspectable(defaultValue=Hello)]
   public function get prop():String {
trace(Rectangle ::: get prop);
return _prop;
   }
   public function set prop(value:String):void {
trace(Rectangle ::: set prop);
if(value != _prop) {
 _prop = value;
 propChanged = true;
 commitProperties();
}
   }
  }
 }

 regards,
 Muzak

 - Original Message -
 From: Gregory N greg.gousa...@gmail.com
 To: Flash Coders List flashcoders@chattyfig.figleaf.com
 Sent: Thursday, February 19, 2009 10:25 AM
 Subject: Re: [Flashcoders] component def doesn't pass params to constructor?


 Michael,

 Haven't you read my reply to one of your prev. questions?
 Well, let me quote it here again:
 ===
 Subject: Re: [Flashcoders] my component not instancing properly on
 timeline

 It seems your problem is similar to one I had with my components.
 The matter is that, unlike their behavior in AS2, in AS3 (CS3)
 components setters of  [Inspectable] parameters are called lo-o-ong
 AFTER constructor

 As described here
 http://www.bit-101.com/blog/?p=1181
 So, even if I set my init() as listener for ADDED_TO_STAGE event...
 it's still before setters.

 for now, I found a solution:
 I put my init() in ENTER_FRAME listener and then remove this listener :-)
 This means that listeners are called before 1st  ENTER_FRAME event.
 Perhaps my solution isn't too elegant but it works :-)

 Also, be sure to duplicate default values for your parameters :-)
 ===

 Note that the above solution is intended to use with sprite-based
 components.
 Perhaps if you subclass UIComponent, the situation with setters is
 better... perhaps :-)




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



 --
 --
 Best regards,
  GregoryN
 
 http://GOusable.com
 Flash components development.
 Usability services.
 ___
 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] component def doesn't pass params to constructor?

2009-02-19 Thread Taka Kojima
Gregory,

A lot of times, I do something like...

private var propsSet:Array = new Array();

public function set ballType(_value:String):void{
_ballType= _value;
propsSet.push(ballType);
checkProps();
}

private function checkProps():void{
if(propsSet.length = 12){
// do Blah once all are set...  
}

// You can also check to see if a single property or different
multiple properties have been set, and do certain actions then...
if(propsSet.indexOf(ballType) != -1){
// do Blah if ballType has been set...
}
}

I try to avoid onEnterFrames if possible (unless I really need them,
for something like papervision scene rendering)..

Timers are not the best method, although they usually work, but I find
that the above approach is the best method.

- Taka

On Thu, Feb 19, 2009 at 10:17 AM, Gregory N greg.gousa...@gmail.com wrote:
 After some consideration...

 If I have, say dozen of Inspectable parameters AND a method that need
 several of them to work properly, then I'll have to call this method
 after a delay - to be sure that all necessary setters were called
 before it..
 Thus, turning back to enter_frame trick :-(
 Or am I missing something trivial?

 On 2/19/09, Gregory N greg.gousa...@gmail.com wrote:
 Muzak,

 Nice addition, thanks for pointing to it.
 Frankly, I'd prefer to avoid calling commitProperties() after *each*
 of the setters...
 Anyway, this way looks better than my enter_frame trick :-)

 However, the problem  none of the setters are called if no
 inspectable params were changed still remains. So we have to
 duplicate default values in [Inspectable] and constructor/declaration
 (or some init function)

 On 2/19/09, Muzak p.ginnebe...@telenet.be wrote:
 This workflow is more or less what the Flex components follow:

 package {

  import flash.display.MovieClip;

  public class Rectangle extends MovieClip {

   private var _prop:String = Hello;
   private var propChanged:Boolean = false;

   public function Rectangle():void {
trace(Rectangle ::: CONSTRUCTOR);
init();
   }

   private function init():void {
trace(Rectangle ::: init);
// do stuff here
commitProperties();
   }

   protected function commitProperties():void {
trace(Rectangle ::: commitProperties);
if(propChanged) {
 trace(- propChanged: , propChanged);
 trace(- prop: , _prop);
 propChanged = false;
 // do stuff with _prop
}
   }

   [Inspectable(defaultValue=Hello)]
   public function get prop():String {
trace(Rectangle ::: get prop);
return _prop;
   }
   public function set prop(value:String):void {
trace(Rectangle ::: set prop);
if(value != _prop) {
 _prop = value;
 propChanged = true;
 commitProperties();
}
   }
  }
 }

 regards,
 Muzak

 - Original Message -
 From: Gregory N greg.gousa...@gmail.com
 To: Flash Coders List flashcoders@chattyfig.figleaf.com
 Sent: Thursday, February 19, 2009 10:25 AM
 Subject: Re: [Flashcoders] component def doesn't pass params to
 constructor?


 Michael,

 Haven't you read my reply to one of your prev. questions?
 Well, let me quote it here again:
 ===
 Subject: Re: [Flashcoders] my component not instancing properly on
 timeline

 It seems your problem is similar to one I had with my components.
 The matter is that, unlike their behavior in AS2, in AS3 (CS3)
 components setters of  [Inspectable] parameters are called lo-o-ong
 AFTER constructor

 As described here
 http://www.bit-101.com/blog/?p=1181
 So, even if I set my init() as listener for ADDED_TO_STAGE event...
 it's still before setters.

 for now, I found a solution:
 I put my init() in ENTER_FRAME listener and then remove this listener
 :-)
 This means that listeners are called before 1st  ENTER_FRAME event.
 Perhaps my solution isn't too elegant but it works :-)

 Also, be sure to duplicate default values for your parameters :-)
 ===

 Note that the above solution is intended to use with sprite-based
 components.
 Perhaps if you subclass UIComponent, the situation with setters is
 better... perhaps :-)




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



 --
 --
 Best regards,
  GregoryN
 
 http://GOusable.com
 Flash components development.
 Usability services.



 --
 --
 Best regards,
  GregoryN
 
 http://GOusable.com
 Flash components development.
 Usability services.
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Re: [Flashcoders] component def doesn't pass params to constructor?

2009-02-19 Thread Muzak


- Original Message - 
From: Gregory N greg.gousa...@gmail.com

To: Flash Coders List flashcoders@chattyfig.figleaf.com
Sent: Thursday, February 19, 2009 6:12 PM
Subject: Re: [Flashcoders] component def doesn't pass params to constructor?



Muzak,

Nice addition, thanks for pointing to it.
Frankly, I'd prefer to avoid calling commitProperties() after *each*
of the setters...
Anyway, this way looks better than my enter_frame trick :-)

However, the problem  none of the setters are called if no
inspectable params were changed still remains. So we have to
duplicate default values in [Inspectable] and constructor/declaration
(or some init function)



You shouldn't rely on them as init properties (if that makes sense) but as a way for a user to changed them visually (in the 
IDE).
So yes, you have to define defaultValue=blah, but I guess that's because Flash (the IDE) has no way of knowing what the 
corresponding internal property is (if any).


private var _prop:String = Hello;
[Inspectable(defaultValue=Hello)]
public function set prop(value:String):void {
   //
}

Personally I don't see that as a huge problem.

regards,
Muzak 


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


Re: [Flashcoders] component def doesn't pass params to constructor?

2009-02-19 Thread Muzak


- Original Message - 
From: Gregory N greg.gousa...@gmail.com

To: Flash Coders List flashcoders@chattyfig.figleaf.com
Sent: Thursday, February 19, 2009 7:17 PM
Subject: Re: [Flashcoders] component def doesn't pass params to constructor?



After some consideration...

If I have, say dozen of Inspectable parameters AND a method that need
several of them to work properly, then I'll have to call this method
after a delay - to be sure that all necessary setters were called
before it..
Thus, turning back to enter_frame trick :-(
Or am I missing something trivial?



With the use of commitProperties() you'll be calling it from your init() method and nothing will happen, as all xxxChanged flags 
will be false.

If you set default values for you internal properties, your component should 
work fine.
There should be no need for a delay, if there is, youl probably need to rethink 
your components inner workflow.

regards,
Muzak

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


Re: [Flashcoders] component def doesn't pass params to constructor?

2009-02-19 Thread Gregory N
Well...
Let consider an example.
- I have 10 Inspectable parameters which user can modify in Component inspector
- I need all of them to start  the component
- There are default values for each, of course.

So, with use of commitProperties(), I have to create
- 10 conditions in my commitProperties() function to check all vars
- 10 flags xxxChanged

While I agree that it looks more like best practice example (and
will probable use it), there is some unpleasant feeling that that's
too many code/variables just to call simple setters...
Again, thanks for pointing to this way.




On 2/19/09, Muzak p.ginnebe...@telenet.be wrote:

 - Original Message -
 From: Gregory N greg.gousa...@gmail.com
 To: Flash Coders List flashcoders@chattyfig.figleaf.com
 Sent: Thursday, February 19, 2009 7:17 PM
 Subject: Re: [Flashcoders] component def doesn't pass params to constructor?


 After some consideration...

 If I have, say dozen of Inspectable parameters AND a method that need
 several of them to work properly, then I'll have to call this method
 after a delay - to be sure that all necessary setters were called
 before it..
 Thus, turning back to enter_frame trick :-(
 Or am I missing something trivial?


 With the use of commitProperties() you'll be calling it from your init()
 method and nothing will happen, as all xxxChanged flags
 will be false.
 If you set default values for you internal properties, your component should
 work fine.
 There should be no need for a delay, if there is, youl probably need to
 rethink your components inner workflow.

 regards,
 Muzak

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



-- 
-- 
Best regards,
 GregoryN

http://GOusable.com
Flash components development.
Usability services.
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


RE: [Flashcoders] component def doesn't pass params to constructor?

2009-02-18 Thread Mendelsohn, Michael
Hi list...

Researching my own pesky issue (custom components initializing properly
when they're dragged on the stage at author time), I found this:

 if you want to create instances of your classes by dragging them to
the stage, keep in mind that their constuctors can not accept arguments.
Also, keep in mind that 
Its a really good idea to pick unique names for your custom classes. 
It's widely agreed class-names should start with the capital letter

Source: http://www.actionscript.org/forums/showthread.php3?t=159332

So, is this true??  You can either make a component designed for the
stage OR for instancing through code?  That seems wrong in AS3.

Any feedback is appreciated.
- Michael M.

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


Re: [Flashcoders] component def doesn't pass params to constructor?

2009-02-18 Thread Paul Andrews
- Original Message - 
From: Mendelsohn, Michael michael.mendels...@fmglobal.com

To: Flash Coders List flashcoders@chattyfig.figleaf.com
Sent: Wednesday, February 18, 2009 5:55 PM
Subject: RE: [Flashcoders] component def doesn't pass params to constructor?



Hi list...

Researching my own pesky issue (custom components initializing properly
when they're dragged on the stage at author time), I found this:


if you want to create instances of your classes by dragging them to

the stage, keep in mind that their constuctors can not accept arguments.
Also, keep in mind that
Its a really good idea to pick unique names for your custom classes.
It's widely agreed class-names should start with the capital letter

Source: http://www.actionscript.org/forums/showthread.php3?t=159332

So, is this true??  You can either make a component designed for the
stage OR for instancing through code?  That seems wrong in AS3.


That's a polarised view that isn't strictly true. If you're dragging 
components to the stage in the IDE, how is the IDE supposed to instantiate 
the component with the appropriate parameters?


You can always achieve a similar effect by having a parameterless 
constructor coupled with a parameterised init() method. Nothing stopping you 
having the same architecture for stage components and actionscript created 
class instances. In many ways, the parameterised init() is preferable to a 
parameterised constructor.


Paul


Any feedback is appreciated.
- Michael M.


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


RE: [Flashcoders] component def doesn't pass params to constructor?

2009-02-18 Thread Mendelsohn, Michael
Thanks for responding Paul!

So going forward with my custom components, I was trying to avoid two
lines of code, but you're suggesting that?

//Instead of:
var cc:CustomComponent = new CustomComponent(red, 5);

//it's better to do:
var cc:CustomComponent = new CustomComponent();
cc.init(red, 5);

I thought one line of code would be a cleaner technique?

- MM


That's a polarised view that isn't strictly true. If you're dragging 
components to the stage in the IDE, how is the IDE supposed to
instantiate 
the component with the appropriate parameters?

You can always achieve a similar effect by having a parameterless 
constructor coupled with a parameterised init() method. Nothing stopping
you 
having the same architecture for stage components and actionscript
created 
class instances. In many ways, the parameterised init() is preferable to
a 
parameterised constructor.

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


Re: [Flashcoders] component def doesn't pass params to constructor?

2009-02-18 Thread Paul Andrews
- Original Message - 
From: Mendelsohn, Michael michael.mendels...@fmglobal.com

To: Flash Coders List flashcoders@chattyfig.figleaf.com
Sent: Wednesday, February 18, 2009 9:12 PM
Subject: RE: [Flashcoders] component def doesn't pass params to constructor?



Thanks for responding Paul!

So going forward with my custom components, I was trying to avoid two
lines of code, but you're suggesting that?

//Instead of:
var cc:CustomComponent = new CustomComponent(red, 5);

//it's better to do:
var cc:CustomComponent = new CustomComponent();
cc.init(red, 5);

I thought one line of code would be a cleaner technique?


Some people prefer to use the constructor, others like init(). With a 
separate init() you can re-initialise an existing instance rather than 
create a new instance. You could even have multiple init() functions:


cc.initTexturedBall(red,5,roughTexture);

Your constructor can also call a default init().

etc.

It's not a black and white choice. Whatever it is, it's not an obstacle to 
getting to where you need to be.


Paul


- MM


That's a polarised view that isn't strictly true. If you're dragging
components to the stage in the IDE, how is the IDE supposed to
instantiate
the component with the appropriate parameters?

You can always achieve a similar effect by having a parameterless
constructor coupled with a parameterised init() method. Nothing stopping
you
having the same architecture for stage components and actionscript
created
class instances. In many ways, the parameterised init() is preferable to
a
parameterised constructor.

___
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] component def doesn't pass params to constructor?

2009-02-18 Thread Muzak

You can either make a component designed for the
stage OR for instancing through code? 


Not really, that's not what it says. 
Just says that you can't (and IMO should never have to) pass arguments to the constructor when dropped on stage.


If you want talk to your component both through AS and when on stage, use [Inspectable] getter/setters 


class MyComp {

   [Inspectable]
   public function get symbolName():String {
   return _symbolName
   }
   public function set symbolName(value:String):void {
   _symbolName = value;
   // do stuff with value
   }
}

regards,
Muzak

- Original Message - 
From: Mendelsohn, Michael michael.mendels...@fmglobal.com

To: Flash Coders List flashcoders@chattyfig.figleaf.com
Sent: Wednesday, February 18, 2009 6:55 PM
Subject: RE: [Flashcoders] component def doesn't pass params to constructor?



Hi list...

Researching my own pesky issue (custom components initializing properly
when they're dragged on the stage at author time), I found this:


if you want to create instances of your classes by dragging them to

the stage, keep in mind that their constuctors can not accept arguments.
Also, keep in mind that 
Its a really good idea to pick unique names for your custom classes. 
It's widely agreed class-names should start with the capital letter


Source: http://www.actionscript.org/forums/showthread.php3?t=159332

So, is this true??  You can either make a component designed for the
stage OR for instancing through code?  That seems wrong in AS3.

Any feedback is appreciated.
- Michael M.



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


Re: [Flashcoders] component def doesn't pass params to constructor?

2009-02-18 Thread Weyert de Boer
I would just set default values like the colour red in the constructor 
of the component and then just the normal invalidate()-fun for the 
designer view. Now I haven't experience with making components which 
work during design time
for Flash/Flex, though. Only .NET and Delphi in that regard. But that's 
how I did it back then.


constructor TDxColorComboBox.Create(AOwner: TComponent);
begin
 inherited;
 Style := csOwnerDrawFixed;
 Width := 40;
  FSelectedColor := clRed;
end;

Apparently you can use UIComponentGlobals.designMode (boolean) in Flex 
for design time things. Similar to csDesigning in ComponentState in the 
VCL.


Yours,
Weyert de Boer  
___

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