Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 设置movieClip宽度和高度失败_Actionscript 3 - Fatal编程技术网

Actionscript 3 设置movieClip宽度和高度失败

Actionscript 3 设置movieClip宽度和高度失败,actionscript-3,Actionscript 3,这里有个奇怪的问题——希望我犯了一个非常愚蠢的错误 在AIR项目中,我使用SWFLoader的实例在自定义类(MovieClip的子类)中加载local.swf。当Event.COMPLETE事件发生时,将调用下面的方法。没有什么特别的事情发生 问题是,当我在该方法中设置自定义类的宽度和高度时,有时需要,有时不需要。下面是控制台输出,用于动态加载其中一些。我使用的是虚拟值(100)。加载的SWF完全相同,每个SWF都已成功加载,但我的自定义类的一个实例反映了设置的维度,而另一个实例则没有

这里有个奇怪的问题——希望我犯了一个非常愚蠢的错误

在AIR项目中,我使用
SWFLoader
的实例在自定义类(MovieClip的子类)中加载local.swf。当
Event.COMPLETE
事件发生时,将调用下面的方法。没有什么特别的事情发生

问题是,当我在该方法中设置自定义类的宽度和高度时,有时需要,有时不需要。下面是控制台输出,用于动态加载其中一些。我使用的是虚拟值(100)。加载的SWF完全相同,每个SWF都已成功加载,但我的自定义类的一个实例反映了设置的维度,而另一个实例则没有

     swf 20 50
     this: instance1120
     width: 100 height: 100
     x: 100 y: 100
     rotation: 0


     swf 20 50
     this: instance1122
     width: 0 height: 250
     x: 100 y: 100
     rotation: 0

这可能会帮助您:

在更改其父项的宽度之前,应确保已正确添加swf子项

我想试试这样的东西:

    protected function btn_completeHandler(event:Event):void
    {
        eventBtn.removeEventListener(Event.COMPLETE, btn_completeHandler);

        if(_source.type == "swf"){
            swf = eventBtn.content as MovieClip;

            trace("swf", swf.width, swf.height);

            this.removeChildren();
            swf.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
            this.addChild(swf);

            swf.x = -swf.width/2;
            swf.y = -swf.height/2;
        }
    }

    private function onAddedToStage(e:Event):void
    {
        this.removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
        this.x = 100;
        this.y = 100;
        this.width = 100;
        this.height = 100;
        this.rotation = 0;

        trace("this:", this.name);
        trace("width:", this.width, "height:", this.height);
        trace("x:", this.x, "y:", this.y);
        trace("rotation:", this.rotation);

        trace("\n");
    }
    protected function btn_completeHandler(event:Event):void
    {
        eventBtn.removeEventListener(Event.COMPLETE, btn_completeHandler);

        if(_source.type == "swf"){
            swf = eventBtn.content as MovieClip;

            trace("swf", swf.width, swf.height);

            this.removeChildren();
            swf.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
            this.addChild(swf);

            swf.x = -swf.width/2;
            swf.y = -swf.height/2;
        }
    }

    private function onAddedToStage(e:Event):void
    {
        this.removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
        this.x = 100;
        this.y = 100;
        this.width = 100;
        this.height = 100;
        this.rotation = 0;

        trace("this:", this.name);
        trace("width:", this.width, "height:", this.height);
        trace("x:", this.x, "y:", this.y);
        trace("rotation:", this.rotation);

        trace("\n");
    }