Flex – What does this ActionScript syntax mean? (Return to the inline syntax)

I am a Java programmer and now need to deal with Flex/ActionScript projects. I got an example of ITreeDataDesriptor using Flex 3 Cookbook, but there is a line of ActionScript code that is difficult to understand. I would be very grateful if anyone could explain this further.

public function getData(node:Object, model:Object=null):Object
{
if (node ​​is Office) {
return {children:{label:node.name, label:node.address}};
}
}

The part I don’t understand is “{children:{label:node.name,label:node.address}}”. Office is just a value object containing two String properties: name and address.

The following return expression (modified from the question)…

return {children:{label:node.name, body:node.address}}

…is functionally equivalent to this code…

 var obj:Object = new Object();
obj.children = new Object();
obj.children.label = node.name;
obj.children.body = node.address ;
return obj;

The anonymous object returned in the problem code complicates the problem because it defines the attribute twice. In this case, use the first declaration and ignore the subsequent Statement. No compile-time or runtime errors are thrown.

I am a Java programmer and now need to deal with Flex/ActionScript projects. I got one using Flex 3 Cookbook’s ITreeDataDesriptor example, but there is a line of action script code that is difficult to understand. If anyone can explain this further, I would be grateful.

public function getData( node:Object, model:Object=null):Object
{
if (node ​​is Office) {
return {children:{label:node.name, label:node.address}} ;
}
}

The part I don’t understand is “{children:{label:node.name,label:node.address}}”. Office is just one containing two The value object of the String attribute: name and address.

The following return expression (modified from the question)……

< /p>

return {children:{label:node.name, body:node.address}}

…is functionally equivalent to this code…

var obj:Object = new Object();
obj.children = new Object();
obj.children.label = node.name;
obj.children. body = node.address;
return obj;

The anonymous object returned in the problem code complicates the problem because it defines the attribute twice. In this case, use the first Statement, and ignore subsequent statements. No compile-time or runtime errors are thrown.

Leave a Comment

Your email address will not be published.