|
-
Accessing a static XML variable from within a switch statement
In the following class
Code:
package
{
public class Factory
{
public static var myXML:XML;
public function Factory()
{
}
public static function staticTest(varName:String)
{
switch(varName)
{
default:
Factory.myXML = <entitydefaults>
<entity id='DRONE' points='100'></entity>
<entity id='BOMBER' points='1000'>
</entity>
</entitydefaults>
var x1 = Factory.myXML.entity.(@id == 'DRONE');
var x2 = Factory.myXML.entity.(@id == 'DRONE');
trace('okay');
}
}
}
}
A break point on the "Okay" line shows that x1 is null but x2 is equal to "<entity id="DRONE" points="100"/>".
If I take the whole block out of the switch statement, both x1 and x2 are equal to the expected xml.
Why?
-
try terminating your inline xml with a semicolon
PHP Code:
</entitydefaults>;
-
Thanks for the suggestion, but that didn't help.
-
try this:
PHP Code:
package
{
public class Factory
{
public static var myXML:XML;
public function Factory()
{
}
public static function staticTest(varName:String)
{
var x1,x2;
switch(varName)
{
default:
Factory.myXML = <entitydefaults>
<entity id='DRONE' points='100'></entity>
<entity id='BOMBER' points='1000'>
</entity>
</entitydefaults>
x1 = Factory.myXML.entity.(@id == 'DRONE');
x2 = Factory.myXML.entity.(@id == 'DRONE');
trace('okay');
}
}
}
}
-
Looks like this is actually one of those rare cases where the bug isn't in the code, it's in the AS3 VM:
http://bugs.adobe.com/jira/browse/ASC-2835
-
Testing of XML attribute
someone else had the same problem with testing for existence of an XML attribute. He thought he could type
Code:
var postNodes:XMLList = my_xml2.viewentry.entrydata.(@category != undefined);
You have to go through the XML to find what your looking for. I came up with this on the timeline.
Code:
var myXML:XML = new XML();
function staticTest(varName:String){;
myXML=XML('<entitydefaults><entity id="DRONE" points="100"></entity><entity id="BOMBER" points="1000"></entity></entitydefaults>');
var xmllistamount:int=myXML.entity.length()-1;
for (var i:int = 0; i<=xmllistamount; i++) {
var varname:String=myXML.entity[i].@id;
switch (varname) {
case 'DRONE' :
trace(myXML.entity[i].@points);
break;
case 'BOMBER' :
trace(myXML.entity[i].@points);
break;
default :
trace('okay');
break;
}
}
}
staticTest('o');
for the origin of the testing for existence of an XML attribute problem go here
-
@justkevin: declaring the variable before the switch (but instantiating in the case... as per the last example i posted) worked for me. and the link you posted says encasing the case statement in curlies is a valid workaround too. but yeah, you're right - it's wierd.
@onenterframe: i think that's a different issue than the one justkevin is experiencing.
Last edited by moagrius; 06-01-2009 at 07:29 PM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|