further notes on XML
open the movie to see the last test
http://swf.wonderfl.net/swf/usercode/d/d0/d0fa/d0fa0d755cffa73ade4d2f7e2d5203b8c51e3f80.swf
♥1 |
Line 26 |
Modified 2011-10-03 07:55:05 |
MIT License
archived:2017-03-20 14:38:50
ActionScript3 source code
/**
* Copyright wh0 ( http://wonderfl.net/user/wh0 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/tOH3
*/
package {
import flash.external.ExternalInterface;
import com.actionscriptbible.Example;
public class FlashTest extends Example {
public function FlashTest() {
var tag:XML = <tag foo="ffff" bar="2 + 4" />;
var obj:Object = {ffff: 'foo'};
// attribute values are not strings
trace(tag.@foo is String); // false
// sometimes you can use them as keys
trace(tag.@foo in obj); // true
trace(obj[tag.@foo]); // foo
// sometimes you can't
try {
delete obj[tag.@foo];
} catch (e:Error) {
trace(e); // TypeError: Error #1119
// 1119 isn't even a legitimate runtime error code...
// http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/runtimeErrors.html
}
// delete, why you gotta be like that?
delete obj[tag.@foo.toString()];
trace(tag.@foo in obj); // false
// P. S., sending XML stuff through ExternalInterface doesn't, like, escape it or whatever
// allow script access to see this test
try {
ExternalInterface.call('alert', tag.@bar); // 6
ExternalInterface.call('alert', tag.@bar.toString()); // 2 + 4
} catch (e:Error) {
trace(e); // sandbox violation when viewing in Wonderfl
}
}
}
}