[flexcoders] Re: AS - adding dynamic properties to an object

2005-04-04 Thread viraf_bankwalla


While I can do an object.propertyName in AS to create the property 
with a known name, I do not know the property name till runtime 
(specified in the dataset that I receive), and did not know how to 
create the property at runtime.

The object to which I am adding the property is one of my classes, 
so I have control over it.

Thanks.




--- In flexcoders@yahoogroups.com, Harris Reynolds [EMAIL PROTECTED] 
wrote:
 In AS you always have the option of taking advantage
 of the dynamic type system and just adding properties
 to an untyped object on the fly.  What is the type of
 the object?  Is that an option?
 
 ~harris
 
 --- viraf_bankwalla [EMAIL PROTECTED] wrote:
  
  Hi,
  
  How do I add dynamic properties to an obect ?  These
  properties are 
  received over the HTTPService request.
  
  Thanks
  
  
  
  
  
 
 __
 Do You Yahoo!?
 Tired of spam?  Yahoo! Mail has the best spam protection around 
 http://mail.yahoo.com





 
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] Re: AS - adding dynamic properties to an object

2005-04-04 Thread Manish Jethani

On Apr 5, 2005 1:20 AM, viraf_bankwalla [EMAIL PROTECTED] wrote:

 While I can do an object.propertyName in AS to create the property
 with a known name, I do not know the property name till runtime
 (specified in the dataset that I receive), and did not know how to
 create the property at runtime.

Ah, ah, ah... :)  it's all possible in ActionScript.

 var propertyName:String = getPropertyNameFromSomewhere();
 myObject[propertyName] = propertyValue;

propertyName much be a String.

Manish


 
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/
 





[flexcoders] Re: AS - adding dynamic properties to an object

2005-04-04 Thread viraf_bankwalla


Thanks - the example below would have worked if I had knowledge of the 
property name when I wrote the code.  This is not the case (the 
property name is retrieved with a service request).

The solution that I found was to use the associative array syntax - 

obj[propertyName] = yy;

Now the next question is that how do I specify that propertyName is 
of a given type - say Date or Number.

Thanks.




--- In flexcoders@yahoogroups.com, Manish Jethani 
[EMAIL PROTECTED] wrote:
 On Apr 5, 2005 1:08 AM, viraf_bankwalla [EMAIL PROTECTED] wrote:
 
  How do I add dynamic properties to an obect ?  These properties are
  received over the HTTPService request.
 
 If you have an instance of a dynamic class, you can just stick them
 onto the object.
 
  var o:Object = new Object(); // dynamic object
  o.newProperty = default value; // stick a new property onto it
 
 Pretty much it.
 
 Manish





 
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] Re: AS - adding dynamic properties to an object

2005-04-04 Thread Ben Elmore

A quick way to do it (ugly admittedly) is to use the 'instanceof' or
'typeof' operator.

if ( obj[propertyName] instanceof Date )

You might need to cast into number or date before you check the instance of
to see if it is valid.





-Original Message-
From: viraf_bankwalla [mailto:[EMAIL PROTECTED] 
Sent: Monday, April 04, 2005 10:06 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: AS - adding dynamic properties to an object




Thanks - the example below would have worked if I had knowledge of the 
property name when I wrote the code.  This is not the case (the 
property name is retrieved with a service request).

The solution that I found was to use the associative array syntax - 

obj[propertyName] = yy;

Now the next question is that how do I specify that propertyName is 
of a given type - say Date or Number.

Thanks.




--- In flexcoders@yahoogroups.com, Manish Jethani 
[EMAIL PROTECTED] wrote:
 On Apr 5, 2005 1:08 AM, viraf_bankwalla [EMAIL PROTECTED] wrote:
 
  How do I add dynamic properties to an obect ?  These properties are 
  received over the HTTPService request.
 
 If you have an instance of a dynamic class, you can just stick them 
 onto the object.
 
  var o:Object = new Object(); // dynamic object
  o.newProperty = default value; // stick a new property onto it
 
 Pretty much it.
 
 Manish





 
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] Re: AS - adding dynamic properties to an object

2005-04-04 Thread JesterXL

A rundown of them all:

Who's on here?
-
function showProps(o:Object):Void
{
for(var p in o)
{
trace(-);
trace(p + :  + o[p]);
trace(typeof:  + typeof(o[p]));
trace(is a String:  + (o[p] instanceof String));
trace(is a Number:  + (o[p] instanceof Number));
trace(is a Array:  + (o[p] instanceof Array));
trace(is a Boolean:  + (o[p] instanceof Boolean));
trace(is a Date:  + (o[p] instanceof Date));
}
}

Obviously there are more data types.

You know the type (not recommended):

var val:String = o[p];

You coerce the type (recommended, but expect weird results):

var val:MyClass = MyClass(o[p]);

Keep in mind, the above works differently since some intrinsic datatypes 
have special constructors; String(something) actually converts it to a 
String, and Date's overloaded with a few different ways of making them.

...obviously, interfaces are typically the best way, since you can typecast 
'em (I think, I did it with a CollectionItr):

var myA:Iterator = Interator(reallyARecordSet);

Or something to that effect.

- Original Message - 
From: Ben Elmore [EMAIL PROTECTED]
To: flexcoders@yahoogroups.com
Sent: Monday, April 04, 2005 10:15 PM
Subject: RE: [flexcoders] Re: AS - adding dynamic properties to an object



A quick way to do it (ugly admittedly) is to use the 'instanceof' or
'typeof' operator.

if ( obj[propertyName] instanceof Date )

You might need to cast into number or date before you check the instance of
to see if it is valid.





-Original Message-
From: viraf_bankwalla [mailto:[EMAIL PROTECTED]
Sent: Monday, April 04, 2005 10:06 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: AS - adding dynamic properties to an object




Thanks - the example below would have worked if I had knowledge of the
property name when I wrote the code.  This is not the case (the
property name is retrieved with a service request).

The solution that I found was to use the associative array syntax -

obj[propertyName] = yy;

Now the next question is that how do I specify that propertyName is
of a given type - say Date or Number.

Thanks.




--- In flexcoders@yahoogroups.com, Manish Jethani
[EMAIL PROTECTED] wrote:
 On Apr 5, 2005 1:08 AM, viraf_bankwalla [EMAIL PROTECTED] wrote:

  How do I add dynamic properties to an obect ?  These properties are
  received over the HTTPService request.

 If you have an instance of a dynamic class, you can just stick them
 onto the object.

  var o:Object = new Object(); // dynamic object
  o.newProperty = default value; // stick a new property onto it

 Pretty much it.

 Manish






Yahoo! Groups Links












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] Re: AS - adding dynamic properties to an object

2005-04-04 Thread Ben Elmore

Is this the answer to the age old question of 'Who's on first?' :)

-Original Message-
From: JesterXL [mailto:[EMAIL PROTECTED] 
Sent: Monday, April 04, 2005 10:35 PM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Re: AS - adding dynamic properties to an object



A rundown of them all:

Who's on here?
-
function showProps(o:Object):Void
{
for(var p in o)
{
trace(-);
trace(p + :  + o[p]);
trace(typeof:  + typeof(o[p]));
trace(is a String:  + (o[p] instanceof String));
trace(is a Number:  + (o[p] instanceof Number));
trace(is a Array:  + (o[p] instanceof Array));
trace(is a Boolean:  + (o[p] instanceof Boolean));
trace(is a Date:  + (o[p] instanceof Date));
}
}

Obviously there are more data types.

You know the type (not recommended):

var val:String = o[p];

You coerce the type (recommended, but expect weird results):

var val:MyClass = MyClass(o[p]);

Keep in mind, the above works differently since some intrinsic datatypes 
have special constructors; String(something) actually converts it to a 
String, and Date's overloaded with a few different ways of making them.

...obviously, interfaces are typically the best way, since you can typecast 
'em (I think, I did it with a CollectionItr):

var myA:Iterator = Interator(reallyARecordSet);

Or something to that effect.

- Original Message - 
From: Ben Elmore [EMAIL PROTECTED]
To: flexcoders@yahoogroups.com
Sent: Monday, April 04, 2005 10:15 PM
Subject: RE: [flexcoders] Re: AS - adding dynamic properties to an object



A quick way to do it (ugly admittedly) is to use the 'instanceof' or
'typeof' operator.

if ( obj[propertyName] instanceof Date )

You might need to cast into number or date before you check the instance of
to see if it is valid.





-Original Message-
From: viraf_bankwalla [mailto:[EMAIL PROTECTED]
Sent: Monday, April 04, 2005 10:06 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: AS - adding dynamic properties to an object




Thanks - the example below would have worked if I had knowledge of the
property name when I wrote the code.  This is not the case (the property
name is retrieved with a service request).

The solution that I found was to use the associative array syntax -

obj[propertyName] = yy;

Now the next question is that how do I specify that propertyName is of a
given type - say Date or Number.

Thanks.




--- In flexcoders@yahoogroups.com, Manish Jethani [EMAIL PROTECTED]
wrote:
 On Apr 5, 2005 1:08 AM, viraf_bankwalla [EMAIL PROTECTED] wrote:

  How do I add dynamic properties to an obect ?  These properties are 
  received over the HTTPService request.

 If you have an instance of a dynamic class, you can just stick them 
 onto the object.

  var o:Object = new Object(); // dynamic object
  o.newProperty = default value; // stick a new property onto it

 Pretty much it.

 Manish






Yahoo! Groups Links












Yahoo! Groups Links








 
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] Re: AS - adding dynamic properties to an object

2005-04-04 Thread JesterXL

interface Abbot
{
public function question():Function;
}

class First
{
public function question():Function
{
return question;
}
}

import IAbbot;
import First;
var firstBase:IAbbot = new First();

function whosOnFirst()
{
 while(true)
{
var answer:Function = firstBase.question();
trace(Answer:  + answer());
}
}
whosOnFirst();

// Warning, this crashed Flash for me, hehe!

- Original Message - 
From: Ben Elmore [EMAIL PROTECTED]
To: flexcoders@yahoogroups.com
Sent: Monday, April 04, 2005 10:38 PM
Subject: RE: [flexcoders] Re: AS - adding dynamic properties to an object



Is this the answer to the age old question of 'Who's on first?' :)

-Original Message-
From: JesterXL [mailto:[EMAIL PROTECTED]
Sent: Monday, April 04, 2005 10:35 PM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Re: AS - adding dynamic properties to an object



A rundown of them all:

Who's on here?
-
function showProps(o:Object):Void
{
for(var p in o)
{
trace(-);
trace(p + :  + o[p]);
trace(typeof:  + typeof(o[p]));
trace(is a String:  + (o[p] instanceof String));
trace(is a Number:  + (o[p] instanceof Number));
trace(is a Array:  + (o[p] instanceof Array));
trace(is a Boolean:  + (o[p] instanceof Boolean));
trace(is a Date:  + (o[p] instanceof Date));
}
}

Obviously there are more data types.

You know the type (not recommended):

var val:String = o[p];

You coerce the type (recommended, but expect weird results):

var val:MyClass = MyClass(o[p]);

Keep in mind, the above works differently since some intrinsic datatypes
have special constructors; String(something) actually converts it to a
String, and Date's overloaded with a few different ways of making them.

...obviously, interfaces are typically the best way, since you can typecast
'em (I think, I did it with a CollectionItr):

var myA:Iterator = Interator(reallyARecordSet);

Or something to that effect.

- Original Message - 
From: Ben Elmore [EMAIL PROTECTED]
To: flexcoders@yahoogroups.com
Sent: Monday, April 04, 2005 10:15 PM
Subject: RE: [flexcoders] Re: AS - adding dynamic properties to an object



A quick way to do it (ugly admittedly) is to use the 'instanceof' or
'typeof' operator.

if ( obj[propertyName] instanceof Date )

You might need to cast into number or date before you check the instance of
to see if it is valid.





-Original Message-
From: viraf_bankwalla [mailto:[EMAIL PROTECTED]
Sent: Monday, April 04, 2005 10:06 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: AS - adding dynamic properties to an object




Thanks - the example below would have worked if I had knowledge of the
property name when I wrote the code.  This is not the case (the property
name is retrieved with a service request).

The solution that I found was to use the associative array syntax -

obj[propertyName] = yy;

Now the next question is that how do I specify that propertyName is of a
given type - say Date or Number.

Thanks.




--- In flexcoders@yahoogroups.com, Manish Jethani [EMAIL PROTECTED]
wrote:
 On Apr 5, 2005 1:08 AM, viraf_bankwalla [EMAIL PROTECTED] wrote:

  How do I add dynamic properties to an obect ?  These properties are
  received over the HTTPService request.

 If you have an instance of a dynamic class, you can just stick them
 onto the object.

  var o:Object = new Object(); // dynamic object
  o.newProperty = default value; // stick a new property onto it

 Pretty much it.

 Manish






Yahoo! Groups Links












Yahoo! Groups Links









Yahoo! Groups Links












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/