RE: [flexcoders] Register a ChangeEvent listener on a static property

2005-05-25 Thread Richard Butler
Laurent,

Your class User must extend UIObject to inherit the method
addEventListener(), unless you create the method yourself...

Cheers
Rich

-Original Message-
From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Laurent Cornelis
Sent: 25 May 2005 13:21
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Register a ChangeEvent listener on a static
property


Hello,

I have a question: is there a way to register a changeEvent listener on 
a static property ?

For example :

class ModelLocator
{
  [ChangeEvent(userChanged)]
  public static var user : User;
}


class AnotherClass
{

   public function AnotherClass() {
 ModelLocator.user.addEventListener(userChanged, this);
   }

   ...

}

But here, I have this error : There is no method with the name 
'addEventListener'.

Regards,

Laurent Cornelis


 
Yahoo! Groups Links



 





 
Yahoo! Groups Links

* To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/

* To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]

* Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
 




RE: [flexcoders] Register a ChangeEvent listener on a static property

2005-05-25 Thread Alistair McLeod
Hi Lauren,

I think you're getting things mixed up. Your code should be something like
this (incomplete and untested):

class ModelLocator
{

  static function initialize() : Boolean 
  {
EventDispatcher.initialize( ModelLocator.prototype );

return true;
  }

  static var mixIn : Boolean = ModelLocator.initialize();

  private static var _user : User;

  [ChangeEvent(userChanged)]
  public static function get user() : User
  {
return _user;
  }

  public static function set user( user : User ) : Void
  {
_user = user;
  }
}


class AnotherClass
{

  public function AnotherClass() 
  {
ModelLocator.addEventListener( userChanged, this );
  }

  ...

}

Theres quite a lot going on in there, search the archives for the static
initialization (you can alternatively just use EventDispatcher.initialize in
a constructor), or read this article about mixins:
http://www.macromedia.com/support/documentation/en/flex/1/mixin/index.html

You should probably also use the Delegate class in your addEventListener.

Cheers,

Ali

--
Alistair McLeod
Development Director
iteration::two
[EMAIL PROTECTED]
 
Office:  +44 (0)131 338 6108
 
This e-mail and any associated attachments transmitted with it may contain
confidential information and must not be copied, or disclosed, or used by
anyone other than the intended recipient(s). If you are not the intended
recipient(s) please destroy this e-mail, and any copies of it, immediately.
 
Please also note that while software systems have been used to try to ensure
that this e-mail has been swept for viruses, iteration::two do not accept
responsibility for any damage or loss caused in respect of any viruses
transmitted by the e-mail. Please ensure your own checks are carried out
before any attachments are opened.
 

-Original Message-
From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Laurent Cornelis
Sent: 25 May 2005 13:21
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Register a ChangeEvent listener on a static property

Hello,

I have a question: is there a way to register a changeEvent listener on a
static property ?

For example :

class ModelLocator
{
  [ChangeEvent(userChanged)]
  public static var user : User;
}


class AnotherClass
{

   public function AnotherClass() {
 ModelLocator.user.addEventListener(userChanged, this);
   }

   ...

}

But here, I have this error : There is no method with the name
'addEventListener'.

Regards,

Laurent Cornelis


 
Yahoo! Groups Links



 



 
Yahoo! Groups Links

* To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/

* To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]

* Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
 




RE: [flexcoders] Register a ChangeEvent listener on a static property

2005-05-25 Thread Erik Westra
Another way is just to use object.watch on the property:

ModelLocator.watch(user, _changeFunction);


Greetz Erik
 

-Original Message-
From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Alistair McLeod
Sent: woensdag 25 mei 2005 14:37
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Register a ChangeEvent listener on a static
property

Hi Lauren,

I think you're getting things mixed up. Your code should be something
like this (incomplete and untested):

class ModelLocator
{

  static function initialize() : Boolean
  {
EventDispatcher.initialize( ModelLocator.prototype );

return true;
  }

  static var mixIn : Boolean = ModelLocator.initialize();

  private static var _user : User;

  [ChangeEvent(userChanged)]
  public static function get user() : User
  {
return _user;
  }

  public static function set user( user : User ) : Void
  {
_user = user;
  }
}


class AnotherClass
{

  public function AnotherClass()
  {
ModelLocator.addEventListener( userChanged, this );
  }

  ...

}

Theres quite a lot going on in there, search the archives for the static
initialization (you can alternatively just use
EventDispatcher.initialize in a constructor), or read this article about
mixins:
http://www.macromedia.com/support/documentation/en/flex/1/mixin/index.ht
ml

You should probably also use the Delegate class in your
addEventListener.

Cheers,

Ali



 
Yahoo! Groups Links

* To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/

* To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]

* Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/