Re: [Flashcoders] Adding a property to an AS3-component

2009-01-26 Thread Alexander Farber
Thanks Dave, I've read up on it and understand this now.

Too bad Flash docs do not mention which class is dynamic

Regards
Alex

On Sat, Jan 24, 2009 at 6:14 PM, Dave Watts dwa...@figleaf.com wrote:
 is it actually possible to add a new property
 to an AS3-component, like button?

 In AS3, classes will only allow this if they're dynamic classes, and
 most classes aren't dynamic. You could, however, write a new class to
 extend Button.

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


Re: [Flashcoders] Adding a property to an AS3-component

2009-01-26 Thread Ian Thomas
On Mon, Jan 26, 2009 at 9:00 AM, Alexander Farber
alexander.far...@gmail.com wrote:
 Thanks Dave, I've read up on it and understand this now.

 Too bad Flash docs do not mention which class is dynamic

At the top of the documentation page:
http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/display/MovieClip.html

It says under Class:
'public _dynamic_ class MovieClip'

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


Re: [Flashcoders] Adding a property to an AS3-component

2009-01-25 Thread jonathan howe
Seems like Cor's Array solution would make it through the compiler but would
still throw a runtime error, right? I would much more strongly recommend the
extending solution that Dave suggests.

On Sat, Jan 24, 2009 at 12:14 PM, Dave Watts dwa...@figleaf.com wrote:

  is it actually possible to add a new property
  to an AS3-component, like button?

 In AS3, classes will only allow this if they're dynamic classes, and
 most classes aren't dynamic. You could, however, write a new class to
 extend Button.

 Dave Watts, CTO, Fig Leaf Software
 http://www.figleaf.com/

 Fig Leaf Software provides the highest caliber vendor-authorized
 instruction at our training centers in Washington DC, Atlanta,
 Chicago, Baltimore, Northern Virginia, or on-site at your location.
 Visit http://training.figleaf.com/ for more information!
  ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders




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


RE: [Flashcoders] Adding a property to an AS3-component

2009-01-25 Thread Cor
About the array, that works fine!!
When you are into classes, that is preferable!

If you want an example of how I do it with an array, let me know.

HTH
Cor

-Original Message-
From: flashcoders-boun...@chattyfig.figleaf.com
[mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of jonathan
howe
Sent: zondag 25 januari 2009 14:33
To: Flash Coders List
Subject: Re: [Flashcoders] Adding a property to an AS3-component

Seems like Cor's Array solution would make it through the compiler but would
still throw a runtime error, right? I would much more strongly recommend the
extending solution that Dave suggests.

On Sat, Jan 24, 2009 at 12:14 PM, Dave Watts dwa...@figleaf.com wrote:

  is it actually possible to add a new property
  to an AS3-component, like button?

 In AS3, classes will only allow this if they're dynamic classes, and
 most classes aren't dynamic. You could, however, write a new class to
 extend Button.

 Dave Watts, CTO, Fig Leaf Software
 http://www.figleaf.com/

 Fig Leaf Software provides the highest caliber vendor-authorized
 instruction at our training centers in Washington DC, Atlanta,
 Chicago, Baltimore, Northern Virginia, or on-site at your location.
 Visit http://training.figleaf.com/ for more information!
  ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders




-- 
-jonathan howe
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
No virus found in this incoming message.
Checked by AVG - http://www.avg.com 
Version: 8.0.176 / Virus Database: 270.10.13/1914 - Release Date: 24-1-2009
20:40

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


RE: [Flashcoders] Adding a property to an AS3-component

2009-01-25 Thread Cor
Here is the example:

1. create an new movieclip and put a rectangle in as background
2. on top (or higher layer) put a dynamic textfield, give it an instance
name of tf
3. give the movieclip in the library a linkage MyButton
4. paste this code in the first and only frame on the Main timeline!:

//BEGIN CODE
//create array for buttonlabels
var arrButtonsLabels:Array = [One, Two, Three, Four, Five, Six,
Seven];
var arrButtons = [];
var amount:int = arrButtonsLabels.length;

//Using one loop to do it all
for (var i=0; iamount; i++) {
var b:MyButton = new MyButton();
b.tf.text = arrButtonsLabels[i];
//position buttons
b.x = Math.round(stage.stageWidth-(amount*b.width))/2 + i* b.width;
b.y = stage.stageHeight-b.height;
//set the name to its index
b.name = i;
//prevent listener to react when items within the movieclip, like
the tf, are clicked
b.mouseChildren =false;
//show nice hand on mouse over
b.buttonMode = true;
//listen to me...
b.addEventListener(MouseEvent.CLICK, b_Clicked);
b.addEventListener(MouseEvent.MOUSE_OVER, b_Moused);
arrButtons.push(b);
//show on displaylist (=stage)
addChild(b);
}

function b_Clicked(e:MouseEvent):void {
for(var i:int = 0; i amount; i++){
trace(arrButtons[i].myNewProp);
}
}

function b_Moused(e:MouseEvent):void {
var idx:int = arrButtons.indexOf(e.target);
arrButtons[idx].myNewProp = The button + arrButtonsLabels[idx] +
is moused.;
}

//END CODE

5. Test Movie and look at Output panel


HTH
Cor


-Original Message-

Seems like Cor's Array solution would make it through the compiler but would
still throw a runtime error, right? I would much more strongly recommend the
extending solution that Dave suggests.

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


RE: [Flashcoders] Adding a property to an AS3-component

2009-01-25 Thread Cor
I forgot to mention what to do when testing:

Mouse over 2 or 3 buttons and then click one of them.
Notice in the trace the new custom property of every button is stored in the
array.

Kind regards,
Cor

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


Re: [Flashcoders] Adding a property to an AS3-component

2009-01-25 Thread Paul Andrews
The array is just handling objects, so you lose the protection that having 
known classes gives you.


There are occassions when having dynamic classes is essential, but they must 
be rare. I think too many developers just try and emulate the bad habits of 
AS1 and AS2 to get around learning the good habits of AS3 ( explicit 
classes, inheritance, etc.).


Dynamically adding attributes like this makes you open to runtime failure, 
something that extending classes helps to protect you from.


I know - I get tempted by the dark side myself..

Paul
- Original Message - 
From: Cor c...@chello.nl

To: 'Flash Coders List' flashcoders@chattyfig.figleaf.com
Sent: Sunday, January 25, 2009 1:44 PM
Subject: RE: [Flashcoders] Adding a property to an AS3-component



About the array, that works fine!!
When you are into classes, that is preferable!

If you want an example of how I do it with an array, let me know.

HTH
Cor

-Original Message-
From: flashcoders-boun...@chattyfig.figleaf.com
[mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of jonathan
howe
Sent: zondag 25 januari 2009 14:33
To: Flash Coders List
Subject: Re: [Flashcoders] Adding a property to an AS3-component

Seems like Cor's Array solution would make it through the compiler but 
would
still throw a runtime error, right? I would much more strongly recommend 
the

extending solution that Dave suggests.

On Sat, Jan 24, 2009 at 12:14 PM, Dave Watts dwa...@figleaf.com wrote:


 is it actually possible to add a new property
 to an AS3-component, like button?

In AS3, classes will only allow this if they're dynamic classes, and
most classes aren't dynamic. You could, however, write a new class to
extend Button.

Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/

Fig Leaf Software provides the highest caliber vendor-authorized
instruction at our training centers in Washington DC, Atlanta,
Chicago, Baltimore, Northern Virginia, or on-site at your location.
Visit http://training.figleaf.com/ for more information!
 ___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders





--
-jonathan howe
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
No virus found in this incoming message.
Checked by AVG - http://www.avg.com
Version: 8.0.176 / Virus Database: 270.10.13/1914 - Release Date: 
24-1-2009

20:40

___
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] Adding a property to an AS3-component

2009-01-25 Thread Cor
As said before: I completely agree and you should use classes.
But I thought the questioner was not in to that, so maybe a bad habit is a
better solution, then none. :-)

Kind regards
Cor

-Original Message-
From: flashcoders-boun...@chattyfig.figleaf.com
[mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Paul Andrews
Sent: zondag 25 januari 2009 15:54
To: Flash Coders List
Subject: Re: [Flashcoders] Adding a property to an AS3-component

The array is just handling objects, so you lose the protection that having 
known classes gives you.

There are occassions when having dynamic classes is essential, but they must

be rare. I think too many developers just try and emulate the bad habits of 
AS1 and AS2 to get around learning the good habits of AS3 ( explicit 
classes, inheritance, etc.).

Dynamically adding attributes like this makes you open to runtime failure, 
something that extending classes helps to protect you from.

I know - I get tempted by the dark side myself..

Paul
- Original Message - 
From: Cor c...@chello.nl
To: 'Flash Coders List' flashcoders@chattyfig.figleaf.com
Sent: Sunday, January 25, 2009 1:44 PM
Subject: RE: [Flashcoders] Adding a property to an AS3-component


 About the array, that works fine!!
 When you are into classes, that is preferable!

 If you want an example of how I do it with an array, let me know.

 HTH
 Cor

 -Original Message-
 From: flashcoders-boun...@chattyfig.figleaf.com
 [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of jonathan
 howe
 Sent: zondag 25 januari 2009 14:33
 To: Flash Coders List
 Subject: Re: [Flashcoders] Adding a property to an AS3-component

 Seems like Cor's Array solution would make it through the compiler but 
 would
 still throw a runtime error, right? I would much more strongly recommend 
 the
 extending solution that Dave suggests.

 On Sat, Jan 24, 2009 at 12:14 PM, Dave Watts dwa...@figleaf.com wrote:

  is it actually possible to add a new property
  to an AS3-component, like button?

 In AS3, classes will only allow this if they're dynamic classes, and
 most classes aren't dynamic. You could, however, write a new class to
 extend Button.

 Dave Watts, CTO, Fig Leaf Software
 http://www.figleaf.com/

 Fig Leaf Software provides the highest caliber vendor-authorized
 instruction at our training centers in Washington DC, Atlanta,
 Chicago, Baltimore, Northern Virginia, or on-site at your location.
 Visit http://training.figleaf.com/ for more information!
  ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders




 -- 
 -jonathan howe
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
 No virus found in this incoming message.
 Checked by AVG - http://www.avg.com
 Version: 8.0.176 / Virus Database: 270.10.13/1914 - Release Date: 
 24-1-2009
 20:40

 ___
 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

No virus found in this incoming message.
Checked by AVG - http://www.avg.com 
Version: 8.0.176 / Virus Database: 270.10.13/1914 - Release Date: 24-1-2009
20:40

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


Re: [Flashcoders] Adding a property to an AS3-component

2009-01-25 Thread Paul Andrews

It's not a criticism of you Cor.

The OP may not really understand why people do things in a particular and 
why AS3 seems to make things difficullt when in practice it makes their life 
easier.


Anyway, when needs must, I'm as bad as the next man or woman.

Paul
- Original Message - 
From: Cor c...@chello.nl

To: 'Flash Coders List' flashcoders@chattyfig.figleaf.com
Sent: Sunday, January 25, 2009 3:15 PM
Subject: RE: [Flashcoders] Adding a property to an AS3-component



As said before: I completely agree and you should use classes.
But I thought the questioner was not in to that, so maybe a bad habit is a
better solution, then none. :-)

Kind regards
Cor

-Original Message-
From: flashcoders-boun...@chattyfig.figleaf.com
[mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Paul 
Andrews

Sent: zondag 25 januari 2009 15:54
To: Flash Coders List
Subject: Re: [Flashcoders] Adding a property to an AS3-component

The array is just handling objects, so you lose the protection that having
known classes gives you.

There are occassions when having dynamic classes is essential, but they 
must


be rare. I think too many developers just try and emulate the bad habits 
of

AS1 and AS2 to get around learning the good habits of AS3 ( explicit
classes, inheritance, etc.).

Dynamically adding attributes like this makes you open to runtime failure,
something that extending classes helps to protect you from.

I know - I get tempted by the dark side myself..

Paul
- Original Message - 
From: Cor c...@chello.nl

To: 'Flash Coders List' flashcoders@chattyfig.figleaf.com
Sent: Sunday, January 25, 2009 1:44 PM
Subject: RE: [Flashcoders] Adding a property to an AS3-component



About the array, that works fine!!
When you are into classes, that is preferable!

If you want an example of how I do it with an array, let me know.

HTH
Cor

-Original Message-
From: flashcoders-boun...@chattyfig.figleaf.com
[mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of jonathan
howe
Sent: zondag 25 januari 2009 14:33
To: Flash Coders List
Subject: Re: [Flashcoders] Adding a property to an AS3-component

Seems like Cor's Array solution would make it through the compiler but
would
still throw a runtime error, right? I would much more strongly recommend
the
extending solution that Dave suggests.

On Sat, Jan 24, 2009 at 12:14 PM, Dave Watts dwa...@figleaf.com wrote:


 is it actually possible to add a new property
 to an AS3-component, like button?

In AS3, classes will only allow this if they're dynamic classes, and
most classes aren't dynamic. You could, however, write a new class to
extend Button.

Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/

Fig Leaf Software provides the highest caliber vendor-authorized
instruction at our training centers in Washington DC, Atlanta,
Chicago, Baltimore, Northern Virginia, or on-site at your location.
Visit http://training.figleaf.com/ for more information!
 ___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders





--
-jonathan howe
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
No virus found in this incoming message.
Checked by AVG - http://www.avg.com
Version: 8.0.176 / Virus Database: 270.10.13/1914 - Release Date:
24-1-2009
20:40

___
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

No virus found in this incoming message.
Checked by AVG - http://www.avg.com
Version: 8.0.176 / Virus Database: 270.10.13/1914 - Release Date: 
24-1-2009

20:40

___
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] Adding a property to an AS3-component

2009-01-25 Thread Cor
@Paul,

I didn't thought of it as criticism.

Cheers
Cor

-Original Message-
From: flashcoders-boun...@chattyfig.figleaf.com
[mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Paul Andrews
Sent: zondag 25 januari 2009 16:58
To: Flash Coders List
Subject: Re: [Flashcoders] Adding a property to an AS3-component

It's not a criticism of you Cor.

The OP may not really understand why people do things in a particular and 
why AS3 seems to make things difficullt when in practice it makes their life

easier.

Anyway, when needs must, I'm as bad as the next man or woman.

Paul
- Original Message - 
From: Cor c...@chello.nl
To: 'Flash Coders List' flashcoders@chattyfig.figleaf.com
Sent: Sunday, January 25, 2009 3:15 PM
Subject: RE: [Flashcoders] Adding a property to an AS3-component


 As said before: I completely agree and you should use classes.
 But I thought the questioner was not in to that, so maybe a bad habit is a
 better solution, then none. :-)

 Kind regards
 Cor

 -Original Message-
 From: flashcoders-boun...@chattyfig.figleaf.com
 [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Paul 
 Andrews
 Sent: zondag 25 januari 2009 15:54
 To: Flash Coders List
 Subject: Re: [Flashcoders] Adding a property to an AS3-component

 The array is just handling objects, so you lose the protection that having
 known classes gives you.

 There are occassions when having dynamic classes is essential, but they 
 must

 be rare. I think too many developers just try and emulate the bad habits 
 of
 AS1 and AS2 to get around learning the good habits of AS3 ( explicit
 classes, inheritance, etc.).

 Dynamically adding attributes like this makes you open to runtime failure,
 something that extending classes helps to protect you from.

 I know - I get tempted by the dark side myself..

 Paul
 - Original Message - 
 From: Cor c...@chello.nl
 To: 'Flash Coders List' flashcoders@chattyfig.figleaf.com
 Sent: Sunday, January 25, 2009 1:44 PM
 Subject: RE: [Flashcoders] Adding a property to an AS3-component


 About the array, that works fine!!
 When you are into classes, that is preferable!

 If you want an example of how I do it with an array, let me know.

 HTH
 Cor

 -Original Message-
 From: flashcoders-boun...@chattyfig.figleaf.com
 [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of jonathan
 howe
 Sent: zondag 25 januari 2009 14:33
 To: Flash Coders List
 Subject: Re: [Flashcoders] Adding a property to an AS3-component

 Seems like Cor's Array solution would make it through the compiler but
 would
 still throw a runtime error, right? I would much more strongly recommend
 the
 extending solution that Dave suggests.

 On Sat, Jan 24, 2009 at 12:14 PM, Dave Watts dwa...@figleaf.com wrote:

  is it actually possible to add a new property
  to an AS3-component, like button?

 In AS3, classes will only allow this if they're dynamic classes, and
 most classes aren't dynamic. You could, however, write a new class to
 extend Button.

 Dave Watts, CTO, Fig Leaf Software
 http://www.figleaf.com/

 Fig Leaf Software provides the highest caliber vendor-authorized
 instruction at our training centers in Washington DC, Atlanta,
 Chicago, Baltimore, Northern Virginia, or on-site at your location.
 Visit http://training.figleaf.com/ for more information!
  ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders




 -- 
 -jonathan howe
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
 No virus found in this incoming message.
 Checked by AVG - http://www.avg.com
 Version: 8.0.176 / Virus Database: 270.10.13/1914 - Release Date:
 24-1-2009
 20:40

 ___
 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

 No virus found in this incoming message.
 Checked by AVG - http://www.avg.com
 Version: 8.0.176 / Virus Database: 270.10.13/1914 - Release Date: 
 24-1-2009
 20:40

 ___
 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

No virus found in this incoming message.
Checked by AVG - http://www.avg.com 
Version: 8.0.176 / Virus Database: 270.10.13/1914 - Release Date: 24-1-2009
20:40

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com

Re: [Flashcoders] Adding a property to an AS3-component

2009-01-25 Thread Muzak

Ofcourse that works, you're using plain MovieClips, which are dynamic.
This has nothing to do with the use of an Array.
The original question was how to do that with Button components, which you 
can't since they're not dynamic.

As already mentioned, extend the required class and add the property/properties 
you need.


But I thought the questioner was not in to that, so maybe a bad habit is a
better solution, then none.


Afraid I disagree.. especially when passing them on to others it becomes super 
bad.

regards,
Muzak



- Original Message - 
From: Cor c...@chello.nl

To: 'Flash Coders List' flashcoders@chattyfig.figleaf.com
Sent: Sunday, January 25, 2009 3:11 PM
Subject: RE: [Flashcoders] Adding a property to an AS3-component



Here is the example:

1. create an new movieclip and put a rectangle in as background
2. on top (or higher layer) put a dynamic textfield, give it an instance
name of tf
3. give the movieclip in the library a linkage MyButton
4. paste this code in the first and only frame on the Main timeline!:

//BEGIN CODE
//create array for buttonlabels
var arrButtonsLabels:Array = [One, Two, Three, Four, Five, Six,
Seven];
var arrButtons = [];
var amount:int = arrButtonsLabels.length;

//Using one loop to do it all
for (var i=0; iamount; i++) {
var b:MyButton = new MyButton();
b.tf.text = arrButtonsLabels[i];
//position buttons
b.x = Math.round(stage.stageWidth-(amount*b.width))/2 + i* b.width;
b.y = stage.stageHeight-b.height;
//set the name to its index
b.name = i;
//prevent listener to react when items within the movieclip, like
the tf, are clicked
b.mouseChildren =false;
//show nice hand on mouse over
b.buttonMode = true;
//listen to me...
b.addEventListener(MouseEvent.CLICK, b_Clicked);
b.addEventListener(MouseEvent.MOUSE_OVER, b_Moused);
arrButtons.push(b);
//show on displaylist (=stage)
addChild(b);
}

function b_Clicked(e:MouseEvent):void {
for(var i:int = 0; i amount; i++){
trace(arrButtons[i].myNewProp);
}
}

function b_Moused(e:MouseEvent):void {
var idx:int = arrButtons.indexOf(e.target);
arrButtons[idx].myNewProp = The button + arrButtonsLabels[idx] +
is moused.; 
}


//END CODE

5. Test Movie and look at Output panel


HTH
Cor




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


RE: [Flashcoders] Adding a property to an AS3-component

2009-01-25 Thread Cor
M OK, my bad.

Cor

-Original Message-
From: flashcoders-boun...@chattyfig.figleaf.com
[mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Muzak
Sent: zondag 25 januari 2009 19:36
To: Flash Coders List
Subject: Re: [Flashcoders] Adding a property to an AS3-component

Ofcourse that works, you're using plain MovieClips, which are dynamic.
This has nothing to do with the use of an Array.
The original question was how to do that with Button components, which you
can't since they're not dynamic.

As already mentioned, extend the required class and add the
property/properties you need.

 But I thought the questioner was not in to that, so maybe a bad habit is a
 better solution, then none.

Afraid I disagree.. especially when passing them on to others it becomes
super bad.

regards,
Muzak



- Original Message - 
From: Cor c...@chello.nl
To: 'Flash Coders List' flashcoders@chattyfig.figleaf.com
Sent: Sunday, January 25, 2009 3:11 PM
Subject: RE: [Flashcoders] Adding a property to an AS3-component


 Here is the example:
 
 1. create an new movieclip and put a rectangle in as background
 2. on top (or higher layer) put a dynamic textfield, give it an instance
 name of tf
 3. give the movieclip in the library a linkage MyButton
 4. paste this code in the first and only frame on the Main timeline!:
 
 //BEGIN CODE
 //create array for buttonlabels
 var arrButtonsLabels:Array = [One, Two, Three, Four, Five,
Six,
 Seven];
 var arrButtons = [];
 var amount:int = arrButtonsLabels.length;
 
 //Using one loop to do it all
 for (var i=0; iamount; i++) {
 var b:MyButton = new MyButton();
 b.tf.text = arrButtonsLabels[i];
 //position buttons
 b.x = Math.round(stage.stageWidth-(amount*b.width))/2 + i* b.width;
 b.y = stage.stageHeight-b.height;
 //set the name to its index
 b.name = i;
 //prevent listener to react when items within the movieclip, like
 the tf, are clicked
 b.mouseChildren =false;
 //show nice hand on mouse over
 b.buttonMode = true;
 //listen to me...
 b.addEventListener(MouseEvent.CLICK, b_Clicked);
 b.addEventListener(MouseEvent.MOUSE_OVER, b_Moused);
 arrButtons.push(b);
 //show on displaylist (=stage)
 addChild(b);
 }
 
 function b_Clicked(e:MouseEvent):void {
 for(var i:int = 0; i amount; i++){
 trace(arrButtons[i].myNewProp);
 }
 }
 
 function b_Moused(e:MouseEvent):void {
 var idx:int = arrButtons.indexOf(e.target);
 arrButtons[idx].myNewProp = The button + arrButtonsLabels[idx] +
 is moused.; 
 }
 
 //END CODE
 
 5. Test Movie and look at Output panel
 
 
 HTH
 Cor
 
 

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

No virus found in this incoming message.
Checked by AVG - http://www.avg.com 
Version: 8.0.176 / Virus Database: 270.10.13/1914 - Release Date: 24-1-2009
20:40

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


[Flashcoders] Adding a property to an AS3-component

2009-01-24 Thread Alexander Farber
Hello,

is it actually possible to add a new property
to an AS3-component, like button? I try:

  import fl.controls.Button;

  var button:Button = new Button();
  button['old_item'] = 42;
  //button.old_item = 42;
  addChild(button);

but get the run-time error:

  ReferenceError: Error #1056: Cannot create property old_item on
fl.controls.Button.
at Untitled_fla::MainTimeline/frame1()

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


RE: [Flashcoders] Adding a property to an AS3-component

2009-01-24 Thread Cor
You can edit the components class.

But I always put my objects in arrays.
So you can do this:
var arrButtons:Array = [];
var button:Button = new Button();
arrButtons.push(button);
  arrButtons[0].old_item = 42;
  addChild(button);

HTH
Cor

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


Re: [Flashcoders] Adding a property to an AS3-component

2009-01-24 Thread Dave Watts
 is it actually possible to add a new property
 to an AS3-component, like button?

In AS3, classes will only allow this if they're dynamic classes, and
most classes aren't dynamic. You could, however, write a new class to
extend Button.

Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/

Fig Leaf Software provides the highest caliber vendor-authorized
instruction at our training centers in Washington DC, Atlanta,
Chicago, Baltimore, Northern Virginia, or on-site at your location.
Visit http://training.figleaf.com/ for more information!
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders