kritivasas shukla
kritivasas shukla

Reputation: 1

added MovieClip to stageChild and rootChild but still not visible, modifying index doesn't work as well

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

    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

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

  1. I am using FlashDevelop with flex SDK to develop this code
  2. The buttons are drawn, but when I setChildIndex(micIndicator) higher, the output is blank
  3. There is error in playing MovieClip standalone,
  4. The height and width of movie wont change even in constructer

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.

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.

Upvotes: 0

Views: 45

Answers (1)

Fygo
Fygo

Reputation: 4665

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?

A: instance of Main

Q: Is stage the same as the instance of 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?

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?

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.

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

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

Upvotes: 1

Related Questions