将MovieClip添加到stageChild和rootChild但仍然不可见,修改索引也不起作用

时间:2021-08-28 18:54:06

I am new to action script and working with .fla file add an indicator to my audio recorder, The following is the code for my Main class initializer, which earlier used to record sound with no mic feedback, then I decided to mess with it by adding a movieClip to display feedback

我是动作脚本的新手,并使用.fla文件为我的录音机添加一个指示器,以下是我的Main类初始化器的代码,之前用于录制没有麦克风反馈的声音,然后我决定把它弄乱了添加movieClip以显示反馈

    public function Main()
    {
        Security.allowDomain("*");
            try {
                addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
                addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
                drawStartPlayButton();
                drawStopPlayButton();
                drawStartButton();
                drawStopButton();
                this.micIndicator = new ActivityBar(this.stage, this);
                this.setChildIndex(this.micIndicator, 0);
                recorder.thisStage = this.stage;
                recorder.thisActivity = this.micIndicator;
                start_play_sound_button.addEventListener(MouseEvent.CLICK, onPrepare);
                addChild(start_play_sound_button);
                addChild(micIndicator); 
                start_record_button.addEventListener(MouseEvent.CLICK, onStart);
                addChild(start_record_button);
                stop_record_button.addEventListener(MouseEvent.CLICK, onStop);
                addChild(stop_record_button);
                recorder.thisActivity = micIndicator;
                micIndicator.stop();
                micIndicator.x = 0;
                micIndicator.y = 0;
                this.addChild(micIndicator);
                trace("added to stage");
                if (checkJavaScriptReady()) {
                } else {
                    var readyTimer:Timer = new Timer(100, 0);
                    readyTimer.addEventListener(TimerEvent.TIMER, timerHandler);
                    readyTimer.start();
                }
            } catch (error:SecurityError) {
                //ExternalInterface.call("sendToJavaScript", error.message);
            } catch (error:Error) {
                //ExternalInterface.call("sendToJavaScript", error.message);
            }       
    }

Now my ActivityBar is extends MovieClip

现在我的ActivityBar扩展了MovieClip

package org.bytearray.micrecorder {

package org.bytearray.micrecorder {

public class ActivityBar extends MovieClip {


    public function ActivityBar(stage:Stage, parent:Sprite) {
        super();
        this.name = "micIndicator";
        this.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
        stage.addChild(this);
    }

    public function onAddedToStage(e:Event):void {
        this.removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
        this.width = 150;
        this.height = 30;
        this.gotoAndStop(1);
    }
    public function goToFrame(e:Event):void {
        trace("calling goToFrame");
    }
}

}

The ActivityBar is supposed display a .fla movie file with 58 frames in it. The buttons are drawn in the current state, but activity despite being initialized and added to stage, doesn't display

ActivityBar应该显示一个包含58帧的.fla电影文件。按钮以当前状态绘制,但是尽管已初始化并添加到舞台,但不会显示活动

  1. I am using FlashDevelop with flex SDK to develop this code
  2. 我正在使用FlashDevelop和flex SDK来开发此代码

  3. The buttons are drawn, but when I setChildIndex(micIndicator) higher, the output is blank
  4. 按钮被绘制,但是当我将setChildIndex(micIndicator)设置得更高时,输出为空白

  5. There is error in playing MovieClip standalone,
  6. MovieClip独立播放时出错,

  7. The height and width of movie wont change even in constructer
  8. 电影的高度和宽度即使在构造中也不会改变

Why can't I display MovieClip, when I see the published swf of .fla file, I can see that ActivityBar is included in classes, so Its linked correctly.

为什么我不能显示MovieClip,当我看到已发布的.fla文件的swf时,我可以看到ActivityBar包含在类中,因此它正确链接。

What is the right way to do this? Is there some tutorial I can refer too, this is my first action script project.

这样做的正确方法是什么?是否有一些我可以参考的教程,这是我的第一个动作脚本项目。

    public function stage_EnterFrame(e:Event)
    {   
        var num:Number = _microphone.activityLevel;
        trace("in the stage_entrance");
        trace(thisStage.getChildByName("micIndicator"));
        trace("===========================");
        thisActivity.play();
        if (thisStage.getChildByName("micIndicator") == null) {
            trace("no recorder movie clip");
            thisStage.addChild(thisActivity);
        }
        trace(thisActivity.currentFrame);
        thisActivity.gotoAndStop(uint((num/100)*29));
    }

The function above goes to frame corresponding to mic level.

上述功能转到对应麦克风级别的帧。

1 个解决方案

#1


There is nothing wrong with the linkage. Will try to hint you...

这种联系没有错。会试着暗示你......

public function ActivityBar(stage:Stage, parent:Sprite) {
    super();
    this.name = "micIndicator";
    this.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
    stage.addChild(this); //<-----
}

Q: Where are you adding the child to?

问:你把孩子加在哪里?

A: stage

this.micIndicator = new ActivityBar(this.stage, this);
this.setChildIndex(this.micIndicator, 0);

Q: What object are you calling setChildIndex() on?

问:你在调用setChildIndex()的对象是什么?

A: instance of Main

答:Main的实例

Q: Is stage the same as the instance of Main?

问:舞台是否与Main的实例相同?

A: No

Q: Can you use instance_of_main.setChildIndex(...) and expect it will rearrange the index of the child that belongs to stage?

问:你能使用instance_of_main.setChildIndex(...)并期望它会重新排列属于舞台的孩子的索引吗?

A: No

Q: Aaaaand, do you know why you are not thrown a runtime error there? Despite the fact that you should see one as you are calling setChildIndex with a child that is not the child of main?

问:Aaaaand,你知道为什么你没有抛出运行时错误吗?尽管您应该看到一个,因为您正在调用setChildIndex,而该子节点不是main的子节点?

A: Cos you are using a try/catch block - it has ABSOLUTELY no place there as there is no code there that could throw you an error that you should catch.

A:你正在使用try / catch块 - 它绝对没有位置,因为那里没有代码可以抛出你应该捕获的错误。

Got it? ;) Also bytearray.org is not your domain, why would you use it as a package name?

得到它了? ;)同样,bytearray.org不是您的域名,为什么要将它用作包名?

PS: Your main (document) class should extend either Sprite or MovieClip.

PS:你的主(文档)类应该扩展Sprite或MovieClip。

#1


There is nothing wrong with the linkage. Will try to hint you...

这种联系没有错。会试着暗示你......

public function ActivityBar(stage:Stage, parent:Sprite) {
    super();
    this.name = "micIndicator";
    this.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
    stage.addChild(this); //<-----
}

Q: Where are you adding the child to?

问:你把孩子加在哪里?

A: stage

this.micIndicator = new ActivityBar(this.stage, this);
this.setChildIndex(this.micIndicator, 0);

Q: What object are you calling setChildIndex() on?

问:你在调用setChildIndex()的对象是什么?

A: instance of Main

答:Main的实例

Q: Is stage the same as the instance of Main?

问:舞台是否与Main的实例相同?

A: No

Q: Can you use instance_of_main.setChildIndex(...) and expect it will rearrange the index of the child that belongs to stage?

问:你能使用instance_of_main.setChildIndex(...)并期望它会重新排列属于舞台的孩子的索引吗?

A: No

Q: Aaaaand, do you know why you are not thrown a runtime error there? Despite the fact that you should see one as you are calling setChildIndex with a child that is not the child of main?

问:Aaaaand,你知道为什么你没有抛出运行时错误吗?尽管您应该看到一个,因为您正在调用setChildIndex,而该子节点不是main的子节点?

A: Cos you are using a try/catch block - it has ABSOLUTELY no place there as there is no code there that could throw you an error that you should catch.

A:你正在使用try / catch块 - 它绝对没有位置,因为那里没有代码可以抛出你应该捕获的错误。

Got it? ;) Also bytearray.org is not your domain, why would you use it as a package name?

得到它了? ;)同样,bytearray.org不是您的域名,为什么要将它用作包名?

PS: Your main (document) class should extend either Sprite or MovieClip.

PS:你的主(文档)类应该扩展Sprite或MovieClip。