ActionScript 3 AS3 |解决依赖关系
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 AS3 |解决依赖关系相关的知识,希望对你有一定的参考价值。
function ResolveDependency( value:String, data:XMLList ):String {
var pattern:RegExp = /\{([a-zA-Z]([\w\_\-])*)(([\.][a-zA-Z]([\w\_\-])*)*([\.](@?)[a-zA-Z]([\w\_\-])*))?\}/g;
var patternNodes:RegExp = /([a-zA-Z]([\w\_\-])*)(([\.][a-zA-Z]([\w\_\-])*)*([\.](@?)[a-zA-Z]([\w\_\-])*))?/g;
var patternAttribute:RegExp = /\@/;
var list:Array;
var node:XMLList;
var vnode:String;
var attribute:String = null;
var lnode:Array = value.match( pattern );
if ( lnode != null && lnode.length > 0 ) {
for ( var a:uint = 0; a < lnode.length; a++ ) {
node = data;
vnode = String( lnode[a] );
list = String( vnode.match( patternNodes )[0] ).split( "." );
if ( String( list[ list.length - 1 ] ).search( patternAttribute ) > -1 ) {
attribute = String( list.pop() ).replace( patternAttribute, "" );
}
for ( var b:uint = 0; b < list.length; b++ ) {
if ( node.hasOwnProperty( list[b] ) ) {
node = node.child( list[b] );
} else if ( b > 0 && ! node.hasOwnProperty( list[b] ) ) {
return null;
}
}
if( attribute != null ) {
value = value.replace( vnode, node.attribute( attribute ) );
}else{
value = value.replace( vnode, node.text() );
}
}
return value;
}
return value;
}
//Example:
var _data:XMLList = new XMLList("<xml><node><value id=\"url\">www.kirikacode.com</value></node></xml>");
trace( ResolveDependency( "http://{node.value}", _data ) );
trace( ResolveDependency( "Type: {node.value.@id}", _data ) );
以上是关于ActionScript 3 AS3 |解决依赖关系的主要内容,如果未能解决你的问题,请参考以下文章
ActionScript 3 AS3:弹出窗口拦截器解决方法
ActionScript 3 使用TLFTextField时AS3 Bug访问FlashVars(解决方法)
ActionScript 3 AS3 SWFtrospection(as3swf)
ActionScript 3 AS3 TextField和StyleSheet示例(在ActionScript中创建)
[ActionScript 3.0] AS3.0 水面波纹效果
ActionScript 3 AS3:使用SWFObject2和AS3传递变量