Volume Control : Controls « Graphics « Flash / Flex / ActionScript






Volume Control

 
package{
   import flash.display.*;
   import flash.events.*;
   
    public class Main extends Sprite {
        public var volume:Number = 1.0;
        
        public function Main(  ){
            addEventListener(MouseEvent.CLICK, onClick);
            draw(  );
        }
        
        public function onClick(event:MouseEvent):void
        {
            // When user clicks the bar, set the volume
            volume = event.localX / 100;
            draw(  );
            dispatchEvent(new Event(Event.CHANGE));
        }
        
        private function draw(  ):void {
            // Draw a bar and the current volume position
            graphics.beginFill(0xcccccc);
            graphics.drawRect(0, 0, 102, 16);
            graphics.endFill(  );
            
            graphics.beginFill(0x000000);
            graphics.drawRect(volume * 100, 0, 2, 16);
        }
    }
}

        








Related examples in the same category

1.Panel Control
2.Draw the Play/Pause graphic
3.Creating an Item Renderer