• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 365
  • Last Modified:

flex tree check property of selected itm

I have a function which handles the click of an item in tree, I want to check if the item that has been selected contains a specific property

the obj variable has all the xml from the selected item and down but the property check does not seem to work, how exactly do I fix this?
private function clickedItem(event:ListEvent):void
	{	
		var parentArray:Array = new Array();
		var obj:Object = id_myTree.selectedItem;
		
		if(!(obj.(hasOwnProperty("@myProperty") && @myProperty== "true")))
		{
			Alert.show("Valid");
		}

}

Open in new window

0
NewtonianB
Asked:
NewtonianB
3 Solutions
 
asaivanCommented:
Well, your code is kind of weird.  

obj.(hasOwnProperty("@myProperty") is wrong

first, it should be written obj.(hasOwnProperty("@myProperty")), with two closing parenthesis.  But even so, that statement will evaluate to something like obj.true or obj.false.  Which isn't really what you're looking for.

Because it's an object, you can just put the property name there, like obj.myProperty.

I would suggest you set a break point just after that line of code, run your debugger, and then check the debug variables window to see that object obj, and be able to get the exact property reference you're looking for.  I don't think @myProperty is going to give it to you.
0
 
sunsonmaheshCommented:
Hi NewtonianB,

if u already have  xml and want check attribute exist or not,please check follwing url,

http://stackoverflow.com/questions/149206/best-way-to-determine-whether-a-xml-attribute-exists-in-flex

--mahe
0
 
vindys80Commented:
Hi,

I think its just a small mistake that you directly trying @myProperty == "true" instead of item.@myProperty == "true".

Thanks,
Vindys
var item:Object = Tree(evt.currentTarget).selectedItem;
                if( item.name().toString() == "item" ){
                	if( item.hasOwnProperty("@myProperty") && item.@myProperty == "true"){
                		trace( "myProperty" ); 
                	}
                }

Open in new window

0
 
NewtonianBAuthor Commented:
fantastic vindy thank you!
0

Featured Post

2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

Tackle projects and never again get stuck behind a technical roadblock.
Join Now