7

コンポーネントのスキンをライブラリ内の別のスキンに置き換える機能を備えた一連の Flash コンポーネントを構築しています。

現在、アプリケーションの実行後にライブラリにアクセスできますが、ライブ プレビュー中はアクセスできません。ライブ プレビュー モード (ドラッグできるモード) で実行中にコンポーネントがライブラリにアクセスできるかどうかを知りたいです。ステージの周りのコンポーネントを変更し、[コンポーネント パラメータ] ウィンドウでそのプロパティを変更します)

Here is a simplified code that just looks to see if there is a symbol of the name specified and than instantiates it and adds it as a child.

package 
{
    import fl.core.UIComponent;
    import flash.display.MovieClip;
    import flash.system.ApplicationDomain;

    /**
     * ...
     * @author Roy Lazarovich
     */
    public class CompTest extends UIComponent 
    {
        private var customfile  :String;

        public function CompTest()
        {

        }

        override protected function configUI():void
        {

        }

        override protected function draw():void
        {
            super.draw();
        }

        private function setCustomFile():void
        {
            if (ApplicationDomain.currentDomain.hasDefinition(customfile))
            {
                var c:Class = Class(ApplicationDomain.currentDomain.getDefinition(customfile));
                var mc:MovieClip = new c();
                addChild(mc);
            }
        }

        [Inspectable(name = "_Custom File", defaultValue = "")]
        public function set _customfile(value:String):void
        {
            customfile = value;
            setCustomFile();

            drawNow();
        }

    }

}

ありがとう!

4

2 に答える 2

0

これは、configUI で適用し、描画しない限り、LivePreview で機能します。

public class EditableBitmap extends UIComponent 
{
    protected var placeholder:String = "None";
    protected var bitmap:Bitmap;
    protected var scale:Number = 1;

    [Inspectable(name = "Placeholder", type = String, defaultValue="None")]
    public function set Placeholder($value:String):void 
    { 
        placeholder = $value;
        configUI();
    }
    public function get Placeholder():String { return placeholder; }

    public function EditableBitmap() 
    {
        //Console.Debug("NEW EditableBitmap");
        super();
    }

    override protected function configUI():void 
    {
        //Console.Debug("EditableBitmap configUI: " + width);
        if (!isNaN(width))
        {
            wDim = width;
            hDim = height;
            graphics.clear();
            graphics.beginFill(0x000000, 0.1);
            graphics.drawRect(0, 0, wDim, hDim);
        }
        if (placeholder != "None" && placeholder != "")
        {
            var asset:Class = getDefinitionByName(placeholder) as Class;
            var data:BitmapData = new asset() as BitmapData;
            bitmap = new Bitmap(data);
        }
        super.configUI();
    }

    override protected function draw():void 
    {
        if (bitmap)
        {
            addChild(bitmap);
            bitmap.x = off_x * scale;
            bitmap.y = off_y * scale;
            bitmap.scaleX = bitmap.scaleY = scale;
        } 
    }
}

注:コンポーネントを編集している FLA で作業している場合、ビットマップは一貫性のないライブラリからのみ表示されます。うまくいくこともあれば、うまくいかないこともあります。しかし、SWC をエクスポートしてからコンポーネントを別のムービーにインポートすると、LivePreview でも実行時でも常に機能します。

更新 シンボルがコンポーネントに既に埋め込まれていない限り、これはCS6では機能しないようです.SWC SWCに1つの画像を埋め込んでから、宛先ファイル。これはうまくいきませんでしたが、これを行う方法を教えてくれました:

ここに画像の説明を入力

そのため、少し面倒ですが、次の方法でこれを回避できます。

1) コンポーネント SWC 内のプロパティごとにダミー アセットを作成します。2) コンポーネントをデプロイするファイルでカスタム クラスを使用してこれをオーバーライドする

... これらはすべて、価値があるよりも面倒かもしれませんが、問題の解決策を提供するはずです。

于 2012-08-26T15:27:58.750 に答える
0

この状況を解決するためにあなたがすでに何を試みたのか、私にはよくわかりません。しかし、うまくいけば、これが役立つかもしれません。

ライブラリ内の MovieClip を右クリックし、Linkage を選択してクラス名を付けます。私のモノ。

あなたのコードでは、

newMyThing = new MyThing();
this.addChild(newMyThing);
trace("tada!");

解決策に役立つか、解決に近づくことを願っています。

于 2012-08-10T23:38:09.410 に答える