Re: [Flashcoders] survival off eventlisteners on class instance redeclaration?

2007-06-02 Thread eka

Hello :)

The event listener is registered in a collection (array or other data
object) in the instance ( you use the event model of the AS3 framework in
Flex ? or the event model in the mx AS2 library ?)

If you destroy the instance your registration is canceled because the
collection is a property of the instance.

PS : you can use the event model in AS2 or AS3 or SSAS(JS) of my openSource
framework VEGAS : http://code.google.com/p/vegas/wiki/VegasTutorialsEvents

To install VEGAS : http://code.google.com/p/vegas/wiki/InstallVEGASwithSVN

EKA+ :)



2007/6/1, Latcho [EMAIL PROTECTED]:


Hi list,

IfI attach e new instance of a class to a
*var myClass*=new friendlyClass()

and then attach an eventlistener to it
classHello.*addEventLister*(greeting,sayHello)

now say that, after a while I want to overwrite the myClass variable
with a new and fresh instance of the same
*myClass*=new friendlyClass()

now my question: will the eventlistener still work or do I have to
redeclare it again ?

Thanks,
Stijn aka Latcho



___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


RE: [Flashcoders] Flash CS3 Prof copy: missing Tree component.

2007-06-02 Thread Randy Tinfow

 Adobe has put the axe to the tree component and many other components 
 requiring you to use Flex if you want to use them.

Which is the prod that finally has me looking seriously at Silverlight this 
weekend.  We have money and projects set aside for our first forays into CS3, 
but this makes me pause.

RT
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Re: [Flashcoders] Flash CS3 Prof copy: missing Tree component.

2007-06-02 Thread Rene Skou

Hi

You have to choose AS 2.0 inorder to use the tree component if you use AS
3.0 som components are missing

2007/6/1, Ung, Seng [EMAIL PROTECTED]:


Has anyone noticed that the tree component is missing from the CS3 Web
Premium prof. copy after the installation? Is there a link from Adobe
site for us to download the tree component?
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com





--
Med venlig hilsen / Best regards
Rene Skou Jensen
--
Joomla video guides
Next generation learning videos
Showing how to use joomla and 3nd
part software.
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


RE: [Flashcoders] Flash CS3 Prof copy: missing Tree component.

2007-06-02 Thread Randy Tinfow
 You have to choose AS 2.0 inorder to use the tree component 
 if you use AS 3.0 som components are missing

Exactly.

Unfortunately, those components are indispensable to us.  We use them
literally every day.

RT
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


[Flashcoders] AS 2 Delegate question

2007-06-02 Thread Stefano Nappa

Hi, a question.


I'm talking about AS 2.





Inside a method of a class I've:





btnCollection.onRollOver = function() {


// here this is the button


var t = Number(this._name.substr(1, 1));


//


Mouse.hide();


//


cRef.cursor._visible = true;


startDrag(cRef.cursor, true);


//


cRef.setRotation(cRef.curPos[t]);


};





btnCollection is previously created (in the same method), this way:





for (i=0; ibtns; i++) {


var btnCollection = targetLevel['c'+i+'_btn'];


}





cRef is previously created this way:


var cRef = this; // it stores a reference to the class.




The var t registers a number contained in a button name (I use that
number to perform various tasks).





This is perfectly working, but now I want to use the Delegate class.





So, I did the following:





btnCollection.onRollOver = Delegate.create(this,
btnRollOver(btnCollection));





after having built this method:





private function btnRollOver(whichBtn) {


var t = Number(whichBtn._name.substr(1, 1));


//


Mouse.hide();


//


cursor._visible = true;


startDrag(cursor, true);


//


setRotation(curPos[t]);


}





nothing works like before. 


That is: I probably easily get the class reference but I've lost the
reference to the single button...




I even tried (with no results):

1. btnCollection.onRollOver = Delegate.create(this,
btnRollOver, btnCollection);

2. changing btnCollection to be a class variable (not a local one);




Please, can you help me better understand this issue? What am I doing wrong?





Thanks!







___ 
L'email della prossima generazione? Puoi averla con la nuova Yahoo! Mail: 
http://it.docs.yahoo.com/nowyoucan.html
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Re: [Flashcoders] AS 2 Delegate question

2007-06-02 Thread Ruy Adorno
Well, what I understand about the Delegate class, is that you can´t send 
any parameter through the Delegate.create method, any parameter you want 
to pass, must be send by the event.


btnCollection.onRollOver = Delegate.create(this, btnRollOver);


In this case the delegate will send to the btnRollOver function only 
the parameters of the event onRollOver.
You will have to find another way to solve this problem... maybe extend 
the MovieClip class, or maybe it could be better to not use the delegate.


I hope this could help.
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Re: [Flashcoders] Best Practices question...

2007-06-02 Thread Ron Wheeler

It is called encapsulation.
No one should know how a class does its magic. The external classes are 
programmed to the interface (methods)(preferably to an interface class 
rather than directly to the implementation) , they are not allowed to 
peek inside.


What if you find a better way to persist the data or change your coding 
standards for variable names?


If you have allowed/encouraged others to access your classes' properties 
directly, their code will now fail to function.
How do you know who to warn or what other classes are at risk;  your 
code has no links to who calls it.


Using getters and setter for anything other than Inversion of Control is 
probably not a good thing either for the same reason and do not normally 
appear in the Interface class. If they do, you are committed to 
respecting their names as long as you support the interface.


Maybe OK to ignore encapsulation if you are a one man show building 
small demo apps but if you are building something serious with a team or 
building something that others will use and maintain you have to be careful.


It is a good practice to get into so that when you build something 
significant, you already have the coding practices that will make people 
respect your work.



Ron

Steven Sacks wrote:
And since we're talking best practices, you don't 

 have any public instance variables anyhow, hmm? :)

I don't know what best practice you're referring to that claims that 
you shouldn't have public instance variables.


The Wikipedia says NEED CITATION.

Which I will promptly ignore as rubbish.  ;)
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com



___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Re: [Flashcoders] Flash CS3 Prof copy: missing Tree component and Web Service.

2007-06-02 Thread Austin Kottke
You know what's funny about the web service component missing from flash 
cs3?


It's actually in the help documentation as part of flash 9 CS 3:


Web services



Adobe® Flash® CS3 Professional includes the WebServiceConnector 
component that lets you connect to remote web services, send and receive 
data, and bind results to components. This lets Flash developers quickly 
create Rich Internet Applications without having to write a single line 
of ActionScript.


You can consume remote web services by using WebServiceClasses, which 
can require writing complex ActionScript.



Yet it's nowhere to be found in flash cs3 professional. Personally I 
dont care about the component as much as I do

the classes themselves.

Adobe?


Randy Tinfow wrote:
You have to choose AS 2.0 inorder to use the tree component 
if you use AS 3.0 som components are missing



Exactly.

Unfortunately, those components are indispensable to us.  We use them
literally every day.

RT
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

  


___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Re: [Flashcoders] Flash CS3 Prof copy: missing Tree component andWeb Service.

2007-06-02 Thread Muzak
If you open/create an ActionScript 2.0 document, the WebServiceConnector and 
all other Data components are still available. Those 
are the same ones as in the Flash 8 IDE.

The complaint is that there's no AS3 version of the Data components and some UI 
Components (like the Tree)

regards,
Muzak

- Original Message - 
From: Austin Kottke [EMAIL PROTECTED]
To: flashcoders@chattyfig.figleaf.com
Sent: Saturday, June 02, 2007 7:45 PM
Subject: Re: [Flashcoders] Flash CS3 Prof copy: missing Tree component andWeb 
Service.


 You know what's funny about the web service component missing from flash cs3?

 It's actually in the help documentation as part of flash 9 CS 3:


 Web services



 Adobe Flash CS3 Professional includes the WebServiceConnector component that 
 lets you connect to remote web services, send and 
 receive data, and bind results to components. This lets Flash developers 
 quickly create Rich Internet Applications without having 
 to write a single line of ActionScript.

 You can consume remote web services by using WebServiceClasses, which can 
 require writing complex ActionScript.


 Yet it's nowhere to be found in flash cs3 professional. Personally I dont 
 care about the component as much as I do
 the classes themselves.

 Adobe?


___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


RE: [Flashcoders] AS 2 Delegate question

2007-06-02 Thread Merrill, Jason
 In this case the delegate will send to the btnRollOver 
function only the parameters of the event onRollOver.
You will have to find another way to solve this problem... 
maybe extend the MovieClip class, or maybe it could be better 
to not use the delegate.

Actually, you can do it this way:

import mx.utils.Delegate

var myDel:Object = myButton.onRelease = Delegate.create(this,
myFunction);
myDel.myVariable = Hello World;  

function myFunction()
{
trace(arguments.caller.myVariable)
}

Jason Merrill
Bank of America  
GTO Learning  Leadership Development
eTools  Multimedia Team

___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Re: [Flashcoders] AS 2 Delegate question

2007-06-02 Thread Alain Rousseau
Or you could use another Delegate class. There is the Proxy class I 
believe (can't remember who did it)  and the one I use the most is the 
one on dynamicflash.com

http://dynamicflash.com/2005/05/delegate-version-101/

You can pass parameters in the Delegate call


myButton.onRelease = Delegate.create(this, myFunction, param1, param2, ...);



Merrill, Jason wrote:
In this case the delegate will send to the btnRollOver 
function only the parameters of the event onRollOver.
You will have to find another way to solve this problem... 
maybe extend the MovieClip class, or maybe it could be better 
to not use the delegate.
  


Actually, you can do it this way:

import mx.utils.Delegate

var myDel:Object = myButton.onRelease = Delegate.create(this,
myFunction);
myDel.myVariable = Hello World;  


function myFunction()
{
trace(arguments.caller.myVariable)
}

Jason Merrill
Bank of America  
GTO Learning  Leadership Development

eTools  Multimedia Team

___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


  

___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Re: [Flashcoders] AS 2 Delegate question

2007-06-02 Thread Muzak
Create a custom Button component that has public methods and properties that 
you can access.
Have your custom Button dispatch a click event, just like the v2 Button 
component does.

Others might suggest to use a Proxy class that lets you pass extra parameters, 
I'd suggest not to do so.

Simply create your own Button and you'll have all the power you need.

regards,
Muzak

- Original Message - 
From: Stefano Nappa [EMAIL PROTECTED]
To: flashcoders@chattyfig.figleaf.com
Sent: Saturday, June 02, 2007 5:33 PM
Subject: [Flashcoders] AS 2 Delegate question



 Hi, a question.


 I'm talking about AS 2.

 Inside a method of a class I've:



 btnCollection.onRollOver = Delegate.create(this, btnRollOver(btnCollection));
 after having built this method:

 private function btnRollOver(whichBtn) {
var t = Number(whichBtn._name.substr(1, 1));
//
Mouse.hide();
//
cursor._visible = true;
startDrag(cursor, true);
//
setRotation(curPos[t]);
}


 nothing works like before.


 That is: I probably easily get the class reference but I've lost the
 reference to the single button...

 I even tried (with no results):

 1. btnCollection.onRollOver = Delegate.create(this,
 btnRollOver, btnCollection);

 2. changing btnCollection to be a class variable (not a local one);

 Please, can you help me better understand this issue? What am I doing wrong?

 Thanks!


___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


RE: [Flashcoders] AS 2 Delegate question

2007-06-02 Thread Jesse Graupmann
Muzak,

You bring this up every time proxy is mentioned. Do you mind sharing an
actual code example that is just as quick and easy? 

Hasta,
Jesse


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Muzak
Sent: Saturday, June 02, 2007 2:53 PM
To: flashcoders@chattyfig.figleaf.com
Subject: Re: [Flashcoders] AS 2 Delegate question

Create a custom Button component that has public methods and properties that
you can access.
Have your custom Button dispatch a click event, just like the v2 Button
component does.

Others might suggest to use a Proxy class that lets you pass extra
parameters, I'd suggest not to do so.

Simply create your own Button and you'll have all the power you need.

regards,
Muzak

- Original Message - 
From: Stefano Nappa [EMAIL PROTECTED]
To: flashcoders@chattyfig.figleaf.com
Sent: Saturday, June 02, 2007 5:33 PM
Subject: [Flashcoders] AS 2 Delegate question



 Hi, a question.


 I'm talking about AS 2.

 Inside a method of a class I've:



 btnCollection.onRollOver = Delegate.create(this,
btnRollOver(btnCollection));
 after having built this method:

 private function btnRollOver(whichBtn) {
var t = Number(whichBtn._name.substr(1, 1));
//
Mouse.hide();
//
cursor._visible = true;
startDrag(cursor, true);
//
setRotation(curPos[t]);
}


 nothing works like before.


 That is: I probably easily get the class reference but I've lost the
 reference to the single button...

 I even tried (with no results):

 1. btnCollection.onRollOver = Delegate.create(this,
 btnRollOver, btnCollection);

 2. changing btnCollection to be a class variable (not a local one);

 Please, can you help me better understand this issue? What am I doing
wrong?

 Thanks!


___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Re: [Flashcoders] AS 2 Delegate question

2007-06-02 Thread Muzak
This isn't about quick and easy, but about encapsulation, OOP and best 
practices.
Quick and easy also often means quick and dirty ;-)

Here's a stripped down version of a custom button.

import mx.events.EventDispatcher;
import mx.utils.Delegate;

class com.muzakdeezign.samples.MyButton extends MovieClip {
 // decorate class with EventDispatcher
 private static var dispatcherInit = 
EventDispatcher.initialize(com.muzakdeezign.samples.MyButton.prototype);

 // declare EvenDispatcher methods
 public var addEventListener:Function;
 public var removeEventListener:Function;
 public var dispatchEvent:Function;

 private var back_mc:MovieClip;

 private var __index:Number;

 function MyButton() {
  this.init();
 }

 private function init():Void {
  this.back_mc.onRelease = Delegate.create(this, this.backReleaseHandler);
 }

 private function backReleaseHandler():Void {
  this.dispatchEvent({type:click});
 }

 private function setIndex():Void {
 }

 function get index():Number {
  return this.__index;
 }
 function set index(val:Number):Void {
  this.__index = val;
  this.setIndex();
 }

}

Here's a screencast making the above:
http://muzakdeezign.com/flashcoders/create_component/MyButton.html

regards,
Muzak


- Original Message - 
From: Jesse Graupmann [EMAIL PROTECTED]
To: flashcoders@chattyfig.figleaf.com
Sent: Sunday, June 03, 2007 1:43 AM
Subject: RE: [Flashcoders] AS 2 Delegate question


 Muzak,

 You bring this up every time proxy is mentioned. Do you mind sharing an
 actual code example that is just as quick and easy?

 Hasta,
 Jesse


___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


RE: [Flashcoders] AS 2 Delegate question

2007-06-02 Thread Jesse Graupmann
Ha! That's rad. 

I guess the trick is writing a Flash app to write the bulk of the code...
Got links to any of those? 

;)


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Muzak
Sent: Saturday, June 02, 2007 5:54 PM
To: flashcoders@chattyfig.figleaf.com
Subject: Re: [Flashcoders] AS 2 Delegate question

This isn't about quick and easy, but about encapsulation, OOP and best
practices.
Quick and easy also often means quick and dirty ;-)

Here's a stripped down version of a custom button.

import mx.events.EventDispatcher;
import mx.utils.Delegate;

class com.muzakdeezign.samples.MyButton extends MovieClip {
 // decorate class with EventDispatcher
 private static var dispatcherInit =
EventDispatcher.initialize(com.muzakdeezign.samples.MyButton.prototype);

 // declare EvenDispatcher methods
 public var addEventListener:Function;
 public var removeEventListener:Function;
 public var dispatchEvent:Function;

 private var back_mc:MovieClip;

 private var __index:Number;

 function MyButton() {
  this.init();
 }

 private function init():Void {
  this.back_mc.onRelease = Delegate.create(this, this.backReleaseHandler);
 }

 private function backReleaseHandler():Void {
  this.dispatchEvent({type:click});
 }

 private function setIndex():Void {
 }

 function get index():Number {
  return this.__index;
 }
 function set index(val:Number):Void {
  this.__index = val;
  this.setIndex();
 }

}

Here's a screencast making the above:
http://muzakdeezign.com/flashcoders/create_component/MyButton.html

regards,
Muzak


- Original Message - 
From: Jesse Graupmann [EMAIL PROTECTED]
To: flashcoders@chattyfig.figleaf.com
Sent: Sunday, June 03, 2007 1:43 AM
Subject: RE: [Flashcoders] AS 2 Delegate question


 Muzak,

 You bring this up every time proxy is mentioned. Do you mind sharing an
 actual code example that is just as quick and easy?

 Hasta,
 Jesse


___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Re: [Flashcoders] AS 2 Delegate question

2007-06-02 Thread Muzak
Don't know of anything like this available out there, doesn't mean there isn't.
What you saw is part of a larger app that spits out a complete ARP application 
and actually writes .as files to disk (you now saw me 
copy/paisting the code into Flash).

regards,
Muzak

- Original Message - 
From: Jesse Graupmann [EMAIL PROTECTED]
To: flashcoders@chattyfig.figleaf.com
Sent: Sunday, June 03, 2007 3:22 AM
Subject: RE: [Flashcoders] AS 2 Delegate question


 Ha! That's rad.

 I guess the trick is writing a Flash app to write the bulk of the code...
 Got links to any of those?

 ;)


 -Original Message-
 From: [EMAIL PROTECTED]
 [mailto:[EMAIL PROTECTED] On Behalf Of Muzak
 Sent: Saturday, June 02, 2007 5:54 PM
 To: flashcoders@chattyfig.figleaf.com
 Subject: Re: [Flashcoders] AS 2 Delegate question

 This isn't about quick and easy, but about encapsulation, OOP and best
 practices.
 Quick and easy also often means quick and dirty ;-)

 Here's a stripped down version of a custom button.

 import mx.events.EventDispatcher;
 import mx.utils.Delegate;

 class com.muzakdeezign.samples.MyButton extends MovieClip {
 // decorate class with EventDispatcher
 private static var dispatcherInit =
 EventDispatcher.initialize(com.muzakdeezign.samples.MyButton.prototype);

 // declare EvenDispatcher methods
 public var addEventListener:Function;
 public var removeEventListener:Function;
 public var dispatchEvent:Function;

 private var back_mc:MovieClip;

 private var __index:Number;

 function MyButton() {
  this.init();
 }

 private function init():Void {
  this.back_mc.onRelease = Delegate.create(this, this.backReleaseHandler);
 }

 private function backReleaseHandler():Void {
  this.dispatchEvent({type:click});
 }

 private function setIndex():Void {
 }

 function get index():Number {
  return this.__index;
 }
 function set index(val:Number):Void {
  this.__index = val;
  this.setIndex();
 }

 }

 Here's a screencast making the above:
 http://muzakdeezign.com/flashcoders/create_component/MyButton.html

 regards,
 Muzak




___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


RE: [Flashcoders] AS 2 Delegate question

2007-06-02 Thread Jesse Graupmann
So is this still out of the question... 



///
/// IN FLA
///

var box = this.attachMovie ( 'box', 'box',  this.getNextHighestDepth() );

jgButton.initializeMovieClip ( box );
box.data = 'this is my data';

box.showEvents( 'onPress', 'onRollOver' );
box.addEventListener ( 'onPress', mx.utils.Delegate.create( this,
onButtonEventHandler ) );
box.addEventListener ( 'onRollOver', mx.utils.Delegate.create( this,
onButtonEventHandler ) );
function onButtonEventHandler ( evt:Object ) 
{ 
trace( newline );
trace ( 'target: ' + evt.target ) 
trace ( 'type: ' + evt.type ) 
trace ( 'data: ' + evt.target.data ) 
}


///
/// IN jgButton.as
///



class jgButton extends MovieClip
{
private static var EventDispatcherDependancy  =
mx.events.EventDispatcher.initialize( jgButton.prototype );
private static var jgButtonTypes:Object = {
onRollOut: 0,
onRollOver: 0,
onPress: 0,
onRelease: 0,
onReleaseOutside: 0,
onDragOut: 0,
onDragOver: 0
};
private var addEventListener:Function;
private var removeEventListener:Function;
private var dispatchEvent:Function;
private var dispatchQueue:Function;

public function jgButton (){}


///  STATIC  ///


public static function initializeMovieClip ( mc:MovieClip ):Void
{
// replace MovieClip class with jgButton class
mc.__proto__ = jgButton.prototype;
}



///  PUBLIC  ///

///
/// LISTENERS
///

public function showEvents (  )
{
if ( arguments.length == 0 )
{
//
//  SHOW ALL
//
for ( var type in jgButtonTypes )
{
if ( !jgButtonTypes [ type ] )
{
jgButtonTypes [ type ] = 1;
this [ type ] = jgButtonEvent ( type
);
}
}
}
else
{
for ( var i in arguments )
{
var type:String = arguments[ i ];

if ( !jgButtonTypes [ type ] )
{
jgButtonTypes [ type ] = 1;
this [ type ] = jgButtonEvent ( type
);
}
}
}
}

public function hideEvents ( )
{
if ( arguments.length == 0 )
{
//
//  DELETE ALL
//
for ( var type in jgButtonTypes )
{
if ( jgButtonTypes [ type ] )
{
jgButtonTypes [ type ] = 0;
delete this [ type ];
}
}
}
else
{
for ( var i in arguments )
{
var type:String = arguments [ i ];

if ( jgButtonTypes [ type ] )
{
jgButtonTypes [ type] = 0;
delete this [ type ];
}
}
}
}



///  PRIVATE  ///


///
/// EVENT FUNCTION
///

private function jgButtonEvent ( type:String )
{
return function()
{
var evt = {};
evt.type = type;
evt.target = this;
this.dispatchEvent ( evt );
}
}
}





_

Jesse Graupmann
www.jessegraupmann.com 
www.justgooddesign.com/blog/ 
_



-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Muzak
Sent: Saturday, June 02, 2007 5:54 PM
To: flashcoders@chattyfig.figleaf.com
Subject: Re: [Flashcoders] AS 2 Delegate question

This isn't about quick and easy, but about encapsulation, OOP and best
practices.
Quick and easy also often means quick and dirty ;-)

Here's a stripped down version of a custom button.

import mx.events.EventDispatcher;
import mx.utils.Delegate;

class 

Re: [Flashcoders] AS 2 Delegate question

2007-06-02 Thread Muzak
The EventDispatcher methods need to be public

 public var addEventListener:Function;
 public var removeEventListener:Function;
 public var dispatchEvent:Function;

And I usually set the events on the Class itself, but use a child movieclip 
(which you could see in the screencast).
Someone (not necessarily you) could set events from outside the instance, 
messing up your component.

var box = this.attachMovie ( 'box', 'box',  this.getNextHighestDepth());
box.onPress = Delegate.create(this, boxPressHandler);

It's no big deal if you will be the only one who will ever use the component. 
You'll just have to remember not to use any of the 
MovieClip events from outside the instance.
I know it sounds silly, because that's why you created the class in the first 
place, but when you distribute alot of components it's 
kinda out of your hands ;-)

You'd be surprised how many people drag a Button Component from the components 
panel on stage and then go:

myButton.onRelease = function(){}

rather than using addEventListener(click, handler);

regards,
Muzak

- Original Message - 
From: Jesse Graupmann [EMAIL PROTECTED]
To: flashcoders@chattyfig.figleaf.com
Sent: Sunday, June 03, 2007 5:52 AM
Subject: RE: [Flashcoders] AS 2 Delegate question


 So is this still out of the question...



 ///
 /// IN FLA
 ///

 var box = this.attachMovie ( 'box', 'box',  this.getNextHighestDepth() );

 jgButton.initializeMovieClip ( box );
 box.data = 'this is my data';

 box.showEvents( 'onPress', 'onRollOver' );
 box.addEventListener ( 'onPress', mx.utils.Delegate.create( this,
 onButtonEventHandler ) );
 box.addEventListener ( 'onRollOver', mx.utils.Delegate.create( this,
 onButtonEventHandler ) );
 function onButtonEventHandler ( evt:Object )
 {
 trace( newline );
 trace ( 'target: ' + evt.target )
 trace ( 'type: ' + evt.type )
 trace ( 'data: ' + evt.target.data )
 }


 ///
 /// IN jgButton.as
 ///



 class jgButton extends MovieClip
 {
 private static var EventDispatcherDependancy  =
 mx.events.EventDispatcher.initialize( jgButton.prototype );
 private static var jgButtonTypes:Object = {
 onRollOut: 0,
 onRollOver: 0,
 onPress: 0,
 onRelease: 0,
 onReleaseOutside: 0,
 onDragOut: 0,
 onDragOver: 0
 };
 private var addEventListener:Function;
 private var removeEventListener:Function;
 private var dispatchEvent:Function;
 private var dispatchQueue:Function;

 public function jgButton (){}


 ///  STATIC  ///


 public static function initializeMovieClip ( mc:MovieClip ):Void
 {
 // replace MovieClip class with jgButton class
 mc.__proto__ = jgButton.prototype;
 }



 ///  PUBLIC  ///

 ///
 /// LISTENERS
 ///

 public function showEvents (  )
 {
 if ( arguments.length == 0 )
 {
 //
 // SHOW ALL
 //
 for ( var type in jgButtonTypes )
 {
 if ( !jgButtonTypes [ type ] )
 {
 jgButtonTypes [ type ] = 1;
 this [ type ] = jgButtonEvent ( type
 );
 }
 }
 }
 else
 {
 for ( var i in arguments )
 {
 var type:String = arguments[ i ];

 if ( !jgButtonTypes [ type ] )
 {
 jgButtonTypes [ type ] = 1;
 this [ type ] = jgButtonEvent ( type
 );
 }
 }
 }
 }

 public function hideEvents ( )
 {
 if ( arguments.length == 0 )
 {
 //
 // DELETE ALL
 //
 for ( var type in jgButtonTypes )
 {
 if ( jgButtonTypes [ type ] )
 {
 jgButtonTypes [ type ] = 0;
 delete this [ type ];
 }
 }
 }
 else
 {
 for ( var i in arguments )
 {
 var type:String = arguments [ i ];

 if ( jgButtonTypes [ type ] )
 {
 jgButtonTypes [ type] = 0;
 delete this [ type ];
 }
 }
 }
 }



 ///  PRIVATE  ///


 ///
 /// EVENT FUNCTION
 ///

 private function jgButtonEvent ( type:String )
 {
 return function()
 {
 var evt = {};
 evt.type = type;
 evt.target = this;
 this.dispatchEvent ( evt );
 }
 }
 }




___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com