1

アプリケーション内で作成されたディスプレイリストからmxmlを構築する方法に苦労してきました。たとえば、キャンバス上にいくつかのコンポーネントを作成し、ボタンをクリックして、キャンバスとそのプロパティのフォーマットされたxmlドキュメントをmxmlで取得します。

これには簡単な方法がありますか?

助けてくれてありがとう...

4

2 に答える 2

1

確かにこれには簡単な方法はありません。

編集:これの背後にある理由は、mxmlが実際にアクションスクリプトに変換されてからコンパイルされることです。したがって、Flash Player は mxml とその存在についてまったく知りません。

于 2009-06-15T14:53:00.353 に答える
0

なぜこれを行う必要があるのか​​など、これについてもう少し背景を知っておくと役立ちます。私の知る限り、これを行うための簡単な方法や組み込みの方法はありません。

役立つかもしれない指示をここに示します:

  • アプリがサポートする DisplayObject のタイプごとに、PlainText mxml テンプレート ファイルを埋め込みます。(各プロパティに文字列補間と交換する変数があるテンプレート ファイル ex:m:HRule height="{$hRuleHeight}" width="${hRuleWidth}"/

  • オブジェクトが編集/作成されるたびに、情報を保存します。mxml を生成するときは、保存された各アイテムをソートし、プロパティを取得してテンプレートを解析します。AS3 は文字列補間をサポートしていません。以下は、自分で実装していない場合の実装です。

利用方法:

        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" /> */

ソース:

///

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=[];                
        }
    }
}
于 2009-06-15T15:13:50.770 に答える