开发者

How do I set the dimensions of a custom component defined in an ActionScript class?

I'm trying to set the height of a vertical bar (activityBar) but it does not appear to do anything. i have tried something similar with the whole component, but setting the dimensions does nothing (even in the mxml used to instantiate the class). Indeed, I've added transparent graphics just to give the component some dimensions

I'm not sure what I'm doing wrong. It's something bad though; my approach seems dire.

FYI: I'm trying to create a mic activity bar that will respond to the mic by simply setting the height of the activityBar child (which seems to me to be more efficient than redrawing the graphics each time).

Thanks for your help!

开发者_开发知识库package components {

  import mx.core.UIComponent;

  public class MicActivityBar extends UIComponent {        
    public var activityBar:UIComponent; 

    // Constructor

    public function MicActivityBar() {

        super();

        this.opaqueBackground = 0xcc4444;

        graphics.beginFill(0xcccccc, 0);

        graphics.drawRect(0,-15,5,30);

        graphics.endFill();// background for bar 

        activityBar = new UIComponent();
        activityBar.graphics.beginFill(0xcccccc, 0.8);
        activityBar.graphics.drawRect(0,-15,5,20);
        activityBar.graphics.endFill();
        activityBar.height=10;

        addChild(activityBar);

    }
  }
}


package components {

  import mx.core.UIComponent;

  public class MicActivityBar extends UIComponent {        
    public var activityBar:UIComponent; 

    private var _w:Number;


    // Constructor

    public function MicActivityBar() {

        super();

        this.opaqueBackground = 0xcc4444;

        graphics.beginFill(0xcccccc, 0);

        graphics.drawRect(0,-15,5,30);

        graphics.endFill();// background for bar 

        activityBar = new UIComponent();
        activityBar.graphics.beginFill(0xcccccc, 0.8);
        activityBar.graphics.drawRect(0,-15,5,20);
        activityBar.graphics.endFill();
        activityBar.height=10;

        addChild(activityBar);

    }

    public function get w():Number {
    return _w;
    }

    public function set w(value:Number):void {
     _w = value;
    }

    override protected function updateDisplayList(unscaledWidth:Number,unscaledHeight:Number):void {
           super.updateDisplayList(unscaledWidth, unscaledHeight);

    this.height=w;
    this.weight=w;
}
}
}

See my updated code above.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜