I've been struggling with how I can build mxml from the displaylist created within an application. For example, create a number of components on a canvas, then click a button to get a formatted xml document, in mxml, of the canvas and its properties.
我一直在努力学习如何从应用程序中创建的displaylist构建mxml。例如,在画布上创建许多组件,然后单击按钮以获取画布及其属性的格式化xml文档(mxml)。
Is there a simple method for this?
有一个简单的方法吗?
Many thanks for any help...
非常感谢任何帮助......
2 个解决方案
#1
There is no simple method for this for sure.
对此肯定没有简单的方法。
Edit: The reasonong behind this is that mxml is actually translated into actionscript, and then compiled. So, flash player know absolutely nothing about mxml and it's existance.
编辑:这背后的理由是mxml实际上被翻译成actionscript,然后编译。所以,flash播放器对mxml一无所知,而且它存在。
#2
It would help to know a little more background on this, like why you would need to do this. As far as I know there isnt an easy or built-in way to do this.
了解更多关于此的背景知识会有所帮助,例如为什么你需要这样做。据我所知,没有一种简单或内置的方法可以做到这一点。
heres a direction that might help:
这是一个可能有帮助的方向:
-
Embed PlainText mxml template files for each type of DisplayObject your app is going to support. ( template files where each property has a variable to swap with string interpolation ex:mx:HRule height="{$hRuleHeight}" width="${hRuleWidth}"/
为您的应用程序支持的每种类型的DisplayObject嵌入PlainText mxml模板文件。 (模板文件,其中每个属性都有一个变量与字符串插值交换ex:mx:HRule height =“{$ hRuleHeight}”width =“$ {hRuleWidth}”/
-
Everytime an Object is edited/created save the imformation---when it comes time to generate the mxml sort each saved item and take the properties and parse the templates with them. AS3 doesnt support string interpolation, below is an implementation here if you dont have one yourself.
每次编辑/创建对象时保存信息 - 当生成mxml时,每个保存的项目都会生成并获取属性并使用它们解析模板。 AS3不支持字符串插值,下面是一个实现,如果你自己没有。
usage:
var example:StringInterpolation=new StringInterpolation();
example.setKeyAndValue('${id}','foo');
example.setKeyAndValue('${baseurl}','http://testing123');
trace(example.eval('<table width="480" border="0" cellpadding="0" cellspacing="0"><tr><td colspan="3"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="480" height="270"><param name="movie" value="http://testing123/player/Take180Player.swf?xmlLocation=/s/bx/http://testing123}&links=true" />'));
/*outputs:<table width="480" border="0" cellpadding="0" cellspacing="0"><tr><td colspan="3"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="480" height="270"><param name="movie" value="http://testing123/player/Take180Player.swf?xmlLocation=/s/bx/http://testing123&links=true" /> */
src:
//
package com.philipbroadway.utils
{
public class StringInterpolation extends Object
{
internal var _keys:Array;
internal var _values:Array;
internal var _result:String;
internal var i:uint;
/**
*
*
*/
public function StringInterpolation()
{
_keys=[];
_values=[];
}
/**
*
* @param key:String a variable name
* @param value:String a value to replace when the key is found during eval
*
*/
public function setKeyAndValue(key:String,value:String):void
{
var metacharacters:Array=[];
metacharacters.push(new RegExp(/\$/));
metacharacters.push(new RegExp(/\{/));
metacharacters.push(new RegExp(/\}/));
metacharacters.push(new RegExp(/\^/));
metacharacters.push(new RegExp(/\./));
metacharacters.push(new RegExp(/\*/));
metacharacters.push(new RegExp(/\+/));
var replacements:Array=[];
replacements.push(new String('\\$'));
replacements.push(new String('\\{'));
replacements.push(new String('\\}'));
replacements.push(new String('\\^'));
replacements.push(new String('\\.'));
replacements.push(new String('\\*'));
replacements.push(new String('\\+'));
for(i=0;i<metacharacters.length;i++)
{
key=key.replace(metacharacters[i],replacements[i]);
}
_keys.push(key);
_values.push(value);
}
/**
*
* @param value:String to be interpolated
* @return String interpolated
*
*/
public function eval(value:String):String
{
_result=value;
for(i=0;i<_keys.length;i++)
{
var regEx:RegExp=new RegExp(_keys[i],'g');
_result=_result.replace(regEx,_values[i]);
}
return _result;
}
/**
*
*
*/
public function reset():void
{
_keys=[];
_values=[];
}
}
}
#1
There is no simple method for this for sure.
对此肯定没有简单的方法。
Edit: The reasonong behind this is that mxml is actually translated into actionscript, and then compiled. So, flash player know absolutely nothing about mxml and it's existance.
编辑:这背后的理由是mxml实际上被翻译成actionscript,然后编译。所以,flash播放器对mxml一无所知,而且它存在。
#2
It would help to know a little more background on this, like why you would need to do this. As far as I know there isnt an easy or built-in way to do this.
了解更多关于此的背景知识会有所帮助,例如为什么你需要这样做。据我所知,没有一种简单或内置的方法可以做到这一点。
heres a direction that might help:
这是一个可能有帮助的方向:
-
Embed PlainText mxml template files for each type of DisplayObject your app is going to support. ( template files where each property has a variable to swap with string interpolation ex:mx:HRule height="{$hRuleHeight}" width="${hRuleWidth}"/
为您的应用程序支持的每种类型的DisplayObject嵌入PlainText mxml模板文件。 (模板文件,其中每个属性都有一个变量与字符串插值交换ex:mx:HRule height =“{$ hRuleHeight}”width =“$ {hRuleWidth}”/
-
Everytime an Object is edited/created save the imformation---when it comes time to generate the mxml sort each saved item and take the properties and parse the templates with them. AS3 doesnt support string interpolation, below is an implementation here if you dont have one yourself.
每次编辑/创建对象时保存信息 - 当生成mxml时,每个保存的项目都会生成并获取属性并使用它们解析模板。 AS3不支持字符串插值,下面是一个实现,如果你自己没有。
usage:
var example:StringInterpolation=new StringInterpolation();
example.setKeyAndValue('${id}','foo');
example.setKeyAndValue('${baseurl}','http://testing123');
trace(example.eval('<table width="480" border="0" cellpadding="0" cellspacing="0"><tr><td colspan="3"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="480" height="270"><param name="movie" value="http://testing123/player/Take180Player.swf?xmlLocation=/s/bx/http://testing123}&links=true" />'));
/*outputs:<table width="480" border="0" cellpadding="0" cellspacing="0"><tr><td colspan="3"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="480" height="270"><param name="movie" value="http://testing123/player/Take180Player.swf?xmlLocation=/s/bx/http://testing123&links=true" /> */
src:
//
package com.philipbroadway.utils
{
public class StringInterpolation extends Object
{
internal var _keys:Array;
internal var _values:Array;
internal var _result:String;
internal var i:uint;
/**
*
*
*/
public function StringInterpolation()
{
_keys=[];
_values=[];
}
/**
*
* @param key:String a variable name
* @param value:String a value to replace when the key is found during eval
*
*/
public function setKeyAndValue(key:String,value:String):void
{
var metacharacters:Array=[];
metacharacters.push(new RegExp(/\$/));
metacharacters.push(new RegExp(/\{/));
metacharacters.push(new RegExp(/\}/));
metacharacters.push(new RegExp(/\^/));
metacharacters.push(new RegExp(/\./));
metacharacters.push(new RegExp(/\*/));
metacharacters.push(new RegExp(/\+/));
var replacements:Array=[];
replacements.push(new String('\\$'));
replacements.push(new String('\\{'));
replacements.push(new String('\\}'));
replacements.push(new String('\\^'));
replacements.push(new String('\\.'));
replacements.push(new String('\\*'));
replacements.push(new String('\\+'));
for(i=0;i<metacharacters.length;i++)
{
key=key.replace(metacharacters[i],replacements[i]);
}
_keys.push(key);
_values.push(value);
}
/**
*
* @param value:String to be interpolated
* @return String interpolated
*
*/
public function eval(value:String):String
{
_result=value;
for(i=0;i<_keys.length;i++)
{
var regEx:RegExp=new RegExp(_keys[i],'g');
_result=_result.replace(regEx,_values[i]);
}
return _result;
}
/**
*
*
*/
public function reset():void
{
_keys=[];
_values=[];
}
}
}