Re: [flexcoders]How would you rewrite this isset PHP condition in AS3?

2009-01-19 Thread Sam Lai
The hasOwnProperty method available in all objects does exactly this.

http://livedocs.adobe.com/flex/3/langref/Object.html#hasOwnProperty()

Why it is called hasOwnProperty rather than hasProperty I have no idea.

2009/1/19 dorkie dork from dorktown dorkiedorkfromdorkt...@gmail.com:
 late night... thanks

 On Sun, Jan 18, 2009 at 10:05 AM, Ralf Bokelberg ralf.bokelb...@gmail.com
 wrote:

 doesn't try catch help here? If no error is thrown, isset returns true

 ralf

 On Sun, Jan 18, 2009 at 1:46 PM, dorkie dork from dorktown
 dorkiedorkfromdorkt...@gmail.com wrote:
  I have a PHP statement that I am trying to write in AS3. So far it
  errors
  out because the properties do not exist on it yet. How would/should I
  rewrite this for AS3? Here is the statement:
 
  // at the time this is run this.language_data is an object with 2
  properties
  // the STYLES property does not exist yet and it generates a
  // TypeError: Error #1010: A term is undefined and has no properties.
  if (isset(this.language_data['STYLES']['BRACKETS'][0])) {
 
  ddfd
 
 

 


Re: [flexcoders]How would you rewrite this isset PHP condition in AS3?

2009-01-19 Thread dorkie dork from dorktown
i use hasOwnProperty in the function i posted but i can only use it to check
immediate properties. it doesn't support nested properties, for example

var obj:Object = new Object();
obj.apple = new Object();
obj.apple.color = red;

// hasOwnProperty doesn't support nested properties
var b1:Boolean = obj.hasOwnProperty(apple.color); // returns false
var b2:Boolean = obj.hasOwnProperty(banana.color); // returns false
var b3:* = typeof(obj.apple.color); // returns string
var b4:* = typeof(obj.banana.color); // Error #1010: A term is undefined and
has no properties.



On Mon, Jan 19, 2009 at 10:20 AM, Sam Lai samuel@gmail.com wrote:

   The hasOwnProperty method available in all objects does exactly this.

 http://livedocs.adobe.com/flex/3/langref/Object.html#hasOwnProperty()

 Why it is called hasOwnProperty rather than hasProperty I have no idea.

 2009/1/19 dorkie dork from dorktown 
 dorkiedorkfromdorkt...@gmail.comdorkiedorkfromdorktown%40gmail.com
 :

  late night... thanks
 
  On Sun, Jan 18, 2009 at 10:05 AM, Ralf Bokelberg 
 ralf.bokelb...@gmail.com ralf.bokelberg%40gmail.com
  wrote:
 
  doesn't try catch help here? If no error is thrown, isset returns true
 
  ralf
 
  On Sun, Jan 18, 2009 at 1:46 PM, dorkie dork from dorktown
  dorkiedorkfromdorkt...@gmail.com dorkiedorkfromdorktown%40gmail.com
 wrote:
   I have a PHP statement that I am trying to write in AS3. So far it
   errors
   out because the properties do not exist on it yet. How would/should I
   rewrite this for AS3? Here is the statement:
  
   // at the time this is run this.language_data is an object with 2
   properties
   // the STYLES property does not exist yet and it generates a
   // TypeError: Error #1010: A term is undefined and has no properties.
   if (isset(this.language_data['STYLES']['BRACKETS'][0])) {
  
   ddfd
  
  
 
 
  



Re: [flexcoders]How would you rewrite this isset PHP condition in AS3?

2009-01-19 Thread Sam Lai
Oh. My bad - should read the entire thread first before posting.

I had a similar need, and ended up doing it in a loop like you did,
mainly because from the languages I've used before, exceptions tend to
be 'expensive' in terms of computation time. Not sure what the case is
with AS3.

2009/1/20 dorkie dork from dorktown dorkiedorkfromdorkt...@gmail.com:
 i use hasOwnProperty in the function i posted but i can only use it to check
 immediate properties. it doesn't support nested properties, for example

 var obj:Object = new Object();
 obj.apple = new Object();
 obj.apple.color = red;

 // hasOwnProperty doesn't support nested properties
 var b1:Boolean = obj.hasOwnProperty(apple.color); // returns false
 var b2:Boolean = obj.hasOwnProperty(banana.color); // returns false
 var b3:* = typeof(obj.apple.color); // returns string
 var b4:* = typeof(obj.banana.color); // Error #1010: A term is undefined and
 has no properties.



 On Mon, Jan 19, 2009 at 10:20 AM, Sam Lai samuel@gmail.com wrote:

 The hasOwnProperty method available in all objects does exactly this.

 http://livedocs.adobe.com/flex/3/langref/Object.html#hasOwnProperty()

 Why it is called hasOwnProperty rather than hasProperty I have no idea.

 2009/1/19 dorkie dork from dorktown dorkiedorkfromdorkt...@gmail.com:

  late night... thanks
 
  On Sun, Jan 18, 2009 at 10:05 AM, Ralf Bokelberg
  ralf.bokelb...@gmail.com
  wrote:
 
  doesn't try catch help here? If no error is thrown, isset returns true
 
  ralf
 
  On Sun, Jan 18, 2009 at 1:46 PM, dorkie dork from dorktown
  dorkiedorkfromdorkt...@gmail.com wrote:
   I have a PHP statement that I am trying to write in AS3. So far it
   errors
   out because the properties do not exist on it yet. How would/should I
   rewrite this for AS3? Here is the statement:
  
   // at the time this is run this.language_data is an object with 2
   properties
   // the STYLES property does not exist yet and it generates a
   // TypeError: Error #1010: A term is undefined and has no properties.
   if (isset(this.language_data['STYLES']['BRACKETS'][0])) {
  
   ddfd
  
  
 
 

 


[flexcoders]How would you rewrite this isset PHP condition in AS3?

2009-01-18 Thread dorkie dork from dorktown
I have a PHP statement that I am trying to write in AS3. So far it errors
out because the properties do not exist on it yet. How would/should I
rewrite this for AS3? Here is the statement:

// at the time this is run this.language_data is an object with 2
properties
// the STYLES property does not exist yet and it generates a
// TypeError: Error #1010: A term is undefined and has no properties.
if (isset(this.language_data['STYLES']['BRACKETS'][0])) {

ddfd


Re: [flexcoders]How would you rewrite this isset PHP condition in AS3?

2009-01-18 Thread dorkie dork from dorktown
I don't like to know if there is an easier way to do this so I wrote this
function to check if a object or the requested properties exist on the
object.


// call it like this
isset_drilldown(this.language_data,'STYLES','BRACKETS',0);


// Determine whether a variable set via a drill down through the properties
// instead of this: isset(this.language_data['STYLES']['BRACKETS'][0])
// you would use this:
isset_drilldown(this.language_data,'STYLES','BRACKETS',0)
// parameters are - object [, property[, ...]]
public function isset_drilldown(variable:*, ...properties):Boolean {
if (variable!=null  variable!=undefined) {
var length:int = properties.length;

if (properties.length0) {
var reference:* = variable;

for (var i:int=0; ilength; i++) {
var property:String = properties[i];
if (Object(reference).hasOwnProperty(property)) {
reference = reference[property];
}
else {
return false;
}
}
}
return true;
}
else {
return false;
}
}

On Sun, Jan 18, 2009 at 5:46 AM, dorkie dork from dorktown 
dorkiedorkfromdorkt...@gmail.com wrote:

 I have a PHP statement that I am trying to write in AS3. So far it errors
 out because the properties do not exist on it yet. How would/should I
 rewrite this for AS3? Here is the statement:

 // at the time this is run this.language_data is an object with 2
 properties
 // the STYLES property does not exist yet and it generates a
 // TypeError: Error #1010: A term is undefined and has no properties.
 if (isset(this.language_data['STYLES']['BRACKETS'][0])) {

 ddfd



Re: [flexcoders]How would you rewrite this isset PHP condition in AS3?

2009-01-18 Thread dorkie dork from dorktown
er sorry for the php references. i am knee deep in translating php code. :P

On Sun, Jan 18, 2009 at 7:39 AM, dorkie dork from dorktown 
dorkiedorkfromdorkt...@gmail.com wrote:

 I don't like to know if there is an easier way to do this so I wrote this
 function to check if a object or the requested properties exist on the
 object.


 // call it like this
 isset_drilldown(this.language_data,'STYLES','BRACKETS',0);


 // Determine whether a variable set via a drill down through the properties
 // instead of this: isset(this.language_data['STYLES']['BRACKETS'][0])
 // you would use this:
 isset_drilldown(this.language_data,'STYLES','BRACKETS',0)
 // parameters are - object [, property[, ...]]
 public function isset_drilldown(variable:*, ...properties):Boolean {
 if (variable!=null  variable!=undefined) {
 var length:int = properties.length;

 if (properties.length0) {
 var reference:* = variable;

 for (var i:int=0; ilength; i++) {
 var property:String = properties[i];
 if (Object(reference).hasOwnProperty(property)) {
 reference = reference[property];
 }
 else {
 return false;
 }
 }
 }
 return true;
 }
 else {
 return false;

 }
 }

 On Sun, Jan 18, 2009 at 5:46 AM, dorkie dork from dorktown 
 dorkiedorkfromdorkt...@gmail.com wrote:

 I have a PHP statement that I am trying to write in AS3. So far it errors
 out because the properties do not exist on it yet. How would/should I
 rewrite this for AS3? Here is the statement:

 // at the time this is run this.language_data is an object with 2
 properties
 // the STYLES property does not exist yet and it generates a
 // TypeError: Error #1010: A term is undefined and has no properties.
 if (isset(this.language_data['STYLES']['BRACKETS'][0])) {

 ddfd





Re: [flexcoders]How would you rewrite this isset PHP condition in AS3?

2009-01-18 Thread Ralf Bokelberg
doesn't try catch help here? If no error is thrown, isset returns true

ralf

On Sun, Jan 18, 2009 at 1:46 PM, dorkie dork from dorktown
dorkiedorkfromdorkt...@gmail.com wrote:
 I have a PHP statement that I am trying to write in AS3. So far it errors
 out because the properties do not exist on it yet. How would/should I
 rewrite this for AS3? Here is the statement:

 // at the time this is run this.language_data is an object with 2
 properties
 // the STYLES property does not exist yet and it generates a
 // TypeError: Error #1010: A term is undefined and has no properties.
 if (isset(this.language_data['STYLES']['BRACKETS'][0])) {

 ddfd

 


Re: [flexcoders]How would you rewrite this isset PHP condition in AS3?

2009-01-18 Thread dorkie dork from dorktown
late night... thanks

On Sun, Jan 18, 2009 at 10:05 AM, Ralf Bokelberg
ralf.bokelb...@gmail.comwrote:

   doesn't try catch help here? If no error is thrown, isset returns true

 ralf


 On Sun, Jan 18, 2009 at 1:46 PM, dorkie dork from dorktown
 dorkiedorkfromdorkt...@gmail.com dorkiedorkfromdorktown%40gmail.com
 wrote:
  I have a PHP statement that I am trying to write in AS3. So far it errors
  out because the properties do not exist on it yet. How would/should I
  rewrite this for AS3? Here is the statement:
 
  // at the time this is run this.language_data is an object with 2
  properties
  // the STYLES property does not exist yet and it generates a
  // TypeError: Error #1010: A term is undefined and has no properties.
  if (isset(this.language_data['STYLES']['BRACKETS'][0])) {
 
  ddfd