as文件:src\com\fxcomponents\controls\fxslider:
package com.fxcomponents.controls.fxslider
{
import mx.controls.Button;
import mx.core.mx_internal;use namespace mx_internal;public class FXSliderThumb extends Button
{
public function FXSliderThumb()
{
super();
stickyHighlighting = true;
}
override protected function measure():void
{
super.measure(); measuredWidth = 9;
measuredHeight = 9;
}
}
}
src\com\fxcomponents\controls\fxvideo:
1.
package com.fxcomponents.controls.fxvideo
{
import flash.display.Shape;
import flash.events.MouseEvent;import mx.core.UIComponent;public class Button extends UIComponent
{
public function Button()
{
super();
}
private var panelAlpha:Number = 0;
protected var icon:Shape;
private var _iconColor:uint = 0xffffff;
public function set iconColor(value:uint):void
{
_iconColor = value;
}
public function get iconColor():uint
{
return _iconColor;
}
override public function get measuredWidth():Number
{
return 21;
}
override public function get measuredHeight():Number
{
return 21;
}
override protected function createChildren():void
{
super.createChildren();
icon = new Shape();
addChild(icon);
}
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
addEventListener(MouseEvent.ROLL_OVER, onRollOver);
addEventListener(MouseEvent.ROLL_OUT, onRollOut);
graphics.clear();
graphics.beginFill(_iconColor, panelAlpha);
graphics.drawRect(0, 0, unscaledWidth, unscaledWidth);
}
private function onRollOver(event:MouseEvent):void
{
panelAlpha = .1;
invalidateDisplayList();
}
private function onRollOut(event:MouseEvent):void
{
panelAlpha = 0;
invalidateDisplayList();
}
}
}2。
package com.fxcomponents.controls.fxvideo
{
import flash.display.Shape;
import flash.events.MouseEvent;import com.fxcomponents.controls.fxvideo.Button;public class PlayPauseButton extends Button
{
public function PlayPauseButton()
{
super();
}
private var _state:String = "pause";
public function set state(value:String):void
{
_state = value;
invalidateDisplayList();
}
public function get state():String
{
return _state;
}
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
icon.graphics.clear();
icon.graphics.beginFill(iconColor);
if(_state == "play")
{
var x:uint = 0;
var y:uint = 0;
var w:int = 1;
var h:int = 9;
for(; h>0; h -= 2)
icon.graphics.drawRect(x++, y++, w, h);
}
if(_state == "pause")
{
icon.graphics.drawRect(0, 0, 3, 7);
icon.graphics.drawRect(4, 0, 3, 7);
}
icon.x = (unscaledHeight - icon.width)/2;
icon.y = (unscaledHeight - icon.height)/2;
}
}
}3.
package com.fxcomponents.controls.fxvideo
{
public class StopButton extends Button
{
public function StopButton()
{
super();
}
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
icon.graphics.clear();
icon.graphics.beginFill(iconColor);
icon.graphics.drawRect(0, 0, 7, 7);
icon.x = (unscaledWidth - icon.width)/2;
icon.y = (unscaledHeight - icon.height)/2;
}
}
}
4.
package com.fxcomponents.controls.fxvideo
{
public class VolumeButton extends Button
{
public function VolumeButton()
{
super();
}
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
icon.graphics.clear();
icon.graphics.beginFill(iconColor, 1);
icon.graphics.drawRect(0, 2, 2, 5);
icon.graphics.drawRect(3, 2, 1, 5);
icon.graphics.drawRect(4, 1, 1, 7);
icon.graphics.drawRect(5, 0, 1, 9);
icon.x = Math.round((unscaledWidth - icon.width)/2);
icon.y = Math.round((unscaledHeight - icon.height)/2);
}
}
}
package com.fxcomponents.controls.fxslider
{
import mx.controls.Button;
import mx.core.mx_internal;use namespace mx_internal;public class FXSliderThumb extends Button
{
public function FXSliderThumb()
{
super();
stickyHighlighting = true;
}
override protected function measure():void
{
super.measure(); measuredWidth = 9;
measuredHeight = 9;
}
}
}
src\com\fxcomponents\controls\fxvideo:
1.
package com.fxcomponents.controls.fxvideo
{
import flash.display.Shape;
import flash.events.MouseEvent;import mx.core.UIComponent;public class Button extends UIComponent
{
public function Button()
{
super();
}
private var panelAlpha:Number = 0;
protected var icon:Shape;
private var _iconColor:uint = 0xffffff;
public function set iconColor(value:uint):void
{
_iconColor = value;
}
public function get iconColor():uint
{
return _iconColor;
}
override public function get measuredWidth():Number
{
return 21;
}
override public function get measuredHeight():Number
{
return 21;
}
override protected function createChildren():void
{
super.createChildren();
icon = new Shape();
addChild(icon);
}
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
addEventListener(MouseEvent.ROLL_OVER, onRollOver);
addEventListener(MouseEvent.ROLL_OUT, onRollOut);
graphics.clear();
graphics.beginFill(_iconColor, panelAlpha);
graphics.drawRect(0, 0, unscaledWidth, unscaledWidth);
}
private function onRollOver(event:MouseEvent):void
{
panelAlpha = .1;
invalidateDisplayList();
}
private function onRollOut(event:MouseEvent):void
{
panelAlpha = 0;
invalidateDisplayList();
}
}
}2。
package com.fxcomponents.controls.fxvideo
{
import flash.display.Shape;
import flash.events.MouseEvent;import com.fxcomponents.controls.fxvideo.Button;public class PlayPauseButton extends Button
{
public function PlayPauseButton()
{
super();
}
private var _state:String = "pause";
public function set state(value:String):void
{
_state = value;
invalidateDisplayList();
}
public function get state():String
{
return _state;
}
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
icon.graphics.clear();
icon.graphics.beginFill(iconColor);
if(_state == "play")
{
var x:uint = 0;
var y:uint = 0;
var w:int = 1;
var h:int = 9;
for(; h>0; h -= 2)
icon.graphics.drawRect(x++, y++, w, h);
}
if(_state == "pause")
{
icon.graphics.drawRect(0, 0, 3, 7);
icon.graphics.drawRect(4, 0, 3, 7);
}
icon.x = (unscaledHeight - icon.width)/2;
icon.y = (unscaledHeight - icon.height)/2;
}
}
}3.
package com.fxcomponents.controls.fxvideo
{
public class StopButton extends Button
{
public function StopButton()
{
super();
}
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
icon.graphics.clear();
icon.graphics.beginFill(iconColor);
icon.graphics.drawRect(0, 0, 7, 7);
icon.x = (unscaledWidth - icon.width)/2;
icon.y = (unscaledHeight - icon.height)/2;
}
}
}
4.
package com.fxcomponents.controls.fxvideo
{
public class VolumeButton extends Button
{
public function VolumeButton()
{
super();
}
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
icon.graphics.clear();
icon.graphics.beginFill(iconColor, 1);
icon.graphics.drawRect(0, 2, 2, 5);
icon.graphics.drawRect(3, 2, 1, 5);
icon.graphics.drawRect(4, 1, 1, 7);
icon.graphics.drawRect(5, 0, 1, 9);
icon.x = Math.round((unscaledWidth - icon.width)/2);
icon.y = Math.round((unscaledHeight - icon.height)/2);
}
}
}
{
import com.fxcomponents.skins.SliderProgressSkin;import flash.display.DisplayObject;
import flash.display.Graphics;import mx.core.IFlexDisplayObject;
import mx.styles.ISimpleStyleClient;[Style(name="progressColor", type="uint", format="Color", inherit="no")]
[Style(name="progressSkin", type="Class", inherit="no")]public class FXProgressSlider extends FXSlider
{
public function FXProgressSlider()
{
super();
}
private var skinClass:Class;
private var progressBar:IFlexDisplayObject;
private var _progress:Number = 20;
public function set progress(value:Number):void
{
_progress = value;
invalidateDisplayList();
}
override protected function createChildren():void
{
super.createChildren();
if(!getStyle("progressColor"))
setStyle("progressColor", 0x999999);
if(!getStyle("progressSkin"))
setStyle("progressSkin", SliderProgressSkin);
if (!progressBar)
{
skinClass = getStyle("progressSkin");
progressBar = new skinClass();
if (progressBar is ISimpleStyleClient)
ISimpleStyleClient(progressBar).styleName = this; addChildAt(DisplayObject(progressBar), 1);
}
}
override protected function commitProperties():void
{
super.commitProperties();
}
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
var w:Number;
var buggyArea:Number = unscaledWidth / maximum * 10;
progressBar.setActualSize(Math.round(_progress*unscaledWidth/100), unscaledHeight);
var g:Graphics = bound.graphics;
g.clear();
g.beginFill(0xffaaaa, 0);
(_progress == 100) ? w = unscaledWidth : w = Math.max(_progress*unscaledWidth/100 - buggyArea, 0)
g.drawRect(0, 0, w, unscaledHeight);
}
}
}
package com.fxcomponents.controls
{
import com.fxcomponents.controls.fxslider.FXSliderThumb;
import com.fxcomponents.skins.SliderThumbSkin;
import com.fxcomponents.skins.SliderTrackSkin;import flash.display.DisplayObject;
import flash.display.Graphics;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.geom.Point;import mx.core.IFlexDisplayObject;
import mx.core.UIComponent;
import mx.core.mx_internal;
import mx.effects.Move;
import mx.events.SliderEvent;
import mx.events.TweenEvent;
import mx.styles.ISimpleStyleClient;
import mx.styles.StyleProxy;use namespace mx_internal;[Event(name="change", type="mx.events.SliderEvent")]
[Event(name="thumbDrag", type="mx.events.SliderEvent")]
[Event(name="thumbPress", type="mx.events.SliderEvent")]
[Event(name="thumbRelease", type="mx.events.SliderEvent")][Style(name="thumbColor", type="uint", format="Color", inherit="no")]
[Style(name="thumbOutlineColor", type="uint", format="Color", inherit="no")]
[Style(name="thumbSkin", type="Class", inherit="no", states="up, over, down, disabled")]
[Style(name="thumbUpSkin", type="Class", inherit="no")]
[Style(name="thumbOverSkin", type="Class", inherit="no")]
[Style(name="thumbDownSkin", type="Class", inherit="no")]
[Style(name="thumbDisabledSkin", type="Class", inherit="no")]
[Style(name="trackSkin", type="Class", inherit="no")]
[Style(name="trackHighlightSkin", type="Class", inherit="no")]
[Style(name="trackColor", type="uint", format="Color", inherit="no")]public class FXSlider extends UIComponent
{
public function FXSlider()
{
super();
}
private var g:Graphics;
private var e:SliderEvent;
private var skinClass:Class;
private var xOffset:Number;
private var thumbIsPressed:Boolean = false;
private var moveTween:Move;
/** display objects */
protected var track:IFlexDisplayObject;
protected var highlight:IFlexDisplayObject;
protected var bound:Sprite;
protected var thumb:FXSliderThumb;
/** style */
private var thumbSkin:Class;
private var trackSkin:Class;
private var trackHighlightSkin:Class;
private var trackColor:uint;
/** properties */
private var _maximum:Number = 100;
public function get maximum():Number
{
return _maximum;
}
public function set maximum(value:Number):void
{
_maximum = value;
invalidateProperties();
invalidateDisplayList();
}
private var _value:Number = 0;
private var valueChanged:Boolean = false;
public function set value(value:Number):void
{
_value = value;
valueChanged = true;
invalidateProperties();
invalidateDisplayList();
}
public function get value():Number
{
return (thumb.x - thumb.width/2)/((unscaledWidth - thumb.width)/100)*(maximum/100);
}
/** */
private function get boundMin():Number
{
return thumb.width/2
}
private function get boundMax():Number
{
return Math.max(thumb.width/2, bound.width - thumb.width/2) ;
}
/**
* Creates any child components of the component. For example, the
* ComboBox control contains a TextInput control and a Button control
* as child components.
*/
override protected function createChildren():void
{
super.createChildren();
thumbSkin = getStyle("thumbSkin");
if(!thumbSkin)
thumbSkin = com.fxcomponents.skins.SliderThumbSkin;
trackSkin = getStyle("trackSkin");
if(!trackSkin)
trackSkin = com.fxcomponents.skins.SliderTrackSkin;
trackHighlightSkin = getStyle("trackHighlightSkin");
if(!trackHighlightSkin)
trackHighlightSkin = com.fxcomponents.skins.SliderHighlightSkin;
if(!getStyle("thumbSkin"))
setStyle("thumbSkin", SliderThumbSkin);
if(!getStyle("trackColor"))
setStyle("trackColor", 0xaaaaaa);
if(!getStyle("thumbColor"))
setStyle("thumbColor", 0xcccccc);
if(!getStyle("thumbOutlineColor"))
setStyle("thumbOutlineColor", 0x555555);
systemManager.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
if (!track)
{
skinClass = trackSkin;
track = new skinClass(); if (track is ISimpleStyleClient)
ISimpleStyleClient(track).styleName = this; addChild(DisplayObject(track));
}
if (!highlight)
{
skinClass = trackHighlightSkin;
highlight = new skinClass(); if (track is ISimpleStyleClient)
ISimpleStyleClient(highlight).styleName = this; addChild(DisplayObject(highlight));
}
bound = new Sprite();
addChild(bound);
bound.addEventListener(MouseEvent.MOUSE_DOWN, bound_onMouseDown);
thumb = new FXSliderThumb();
addChild(thumb);
thumb.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
moveTween = new Move(thumb);
moveTween.addEventListener(TweenEvent.TWEEN_UPDATE, onTweenUpdate);
moveTween.addEventListener(TweenEvent.TWEEN_END, onTweenEnd);
moveTween.duration = 300;
}
/**
* Commits any changes to component properties, either to make the
* changes occur at the same time, or to ensure that properties are set in
* a specific order.
*/
override protected function commitProperties():void
{
super.commitProperties();
thumb.styleName = new StyleProxy(this, null);
thumb.skinName = "thumbSkin";
}
/**
* Sizes and positions the children of the component on the screen based on
* all previous property and style settings, and draws any skins or graphic
* elements used by the component. The parent container for the component
* determines the size of the component itself.
*/
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
if(valueChanged)
{
thumb.x = thumb.width/2 + Math.round((_value/_maximum)*(unscaledWidth - thumb.width));
valueChanged = false;
}
// draw
var x:int;
var y:int;
var w:int;
var h:int;
w = Math.round(unscaledHeight/2)*2;
h = unscaledHeight;
thumb.setActualSize(w, h);
g = bound.graphics;
g.clear();
g.beginFill(0xffaaaa, 0);
g.drawRect(0, 0, unscaledWidth, unscaledHeight);
// position
thumb.x = Math.max(thumb.width/2, thumb.x);
// size
track.setActualSize(unscaledWidth, unscaledHeight);
highlight.setActualSize(thumb.x, unscaledHeight);
}
override protected function measure():void
{
super.measure();
measuredWidth = 200;
measuredHeight = 13;
}
/** event handlers */
private function onMouseDown(event:MouseEvent):void
{
systemManager.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove, true);
xOffset = event.localX;
thumbIsPressed = true;
e = new SliderEvent(SliderEvent.THUMB_PRESS);
e.value = value;
dispatchEvent(e);
}
private function onMouseUp(event:MouseEvent):void
{
systemManager.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove, true);
if(thumbIsPressed)
{
e = new SliderEvent(SliderEvent.THUMB_RELEASE);
e.value = value;
dispatchEvent(e);
e = new SliderEvent(SliderEvent.CHANGE);
e.value = value;
dispatchEvent(e);
thumbIsPressed = false;
}
}
private function onMouseMove(event:MouseEvent):void
{
var pt:Point = new Point(event.stageX, event.stageY);
pt = globalToLocal(pt);
thumb.x = Math.min(Math.max(pt.x - xOffset, boundMin), boundMax);
e = new SliderEvent(SliderEvent.THUMB_DRAG);
e.value = value;
dispatchEvent(e);
invalidateDisplayList();
}
private function bound_onMouseDown(event:MouseEvent):void
{
moveTween.xTo = Math.min(Math.max(event.localX, boundMin), boundMax);
moveTween.play()
}
private function onTweenUpdate(event:TweenEvent):void
{
invalidateDisplayList();
}
private function onTweenEnd(event:TweenEvent):void
{
e = new SliderEvent(SliderEvent.CHANGE);
e.value = value;
dispatchEvent(e);
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:controls="com.fxcomponents.controls.*"
backgroundColor="#444444" themeColor="#628CAF" backgroundGradientAlphas="{[0, 0]}" viewSourceURL="srcview/index.html">
<mx:Script>
<![CDATA[
[Bindable]
private var source:String = "http://www.fxcomponents.com/flash/flv/Babel_trailer.flv";
]]>
</mx:Script>
<controls:FXVideo width="480" height="360" source="{source}" autoPlay="false" bufferTime="10" />
</mx:Application>
{
import com.fxcomponents.controls.fxvideo.PlayPauseButton;
import com.fxcomponents.controls.fxvideo.StopButton;
import com.fxcomponents.controls.fxvideo.VolumeButton;import flash.events.ContextMenuEvent;
import flash.events.MouseEvent;
import flash.events.ProgressEvent;
import flash.net.URLRequest;
import flash.net.navigateToURL;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.ui.ContextMenu;
import flash.ui.ContextMenuBuiltInItems;
import flash.ui.ContextMenuItem;import mx.controls.VideoDisplay;
import mx.core.UIComponent;
import mx.events.MetadataEvent;
import mx.events.SliderEvent;
import mx.events.VideoEvent;/**
* The color of the control bar.
*
* @default 0x555555
*/[Style(name="backColor", type="uint", format="Color")]/**
* The color of the buttons on the control bar.
*
* @default 0xeeeeee
*/[Style(name="frontColor", type="uint", format="Color")]/**
* The height of the control bar. Odd values look better.
*
* @default 21
*/[Style(name="controlBarHeight", type="Number")]/**
* The name of the font used in the timer.
*
* @default "Verdana"
*/
[Style(name="timerFontName", type="String", inherit="no")]/**
* The size of the font used in the timer.
*
* @default 9
*/[Style(name="timerFontSize", type="Number")]/**
* The FXVideo control lets you play an FLV file in a Flex application.
* It supports progressive download over HTTP, streaming from the Flash Media
* Server, and streaming from a Camera object.
*
* @mxml
*
* <p>The <code><controls:FXVideo></code> tag inherits all the tag
* attributes of its superclass, and adds the following tag attributes:</p>
*
* <pre>
* <controls:FXVideo
*
* <b>Styles</b>
* backColor="0x555555"
* frontColor="0xeeeeee"
* controlBarHeight="21"
* timerFontName="Verdana"
* timerFontSize="9"
*
* />
* </pre>
*
*/public class FXVideo extends VideoDisplay
{
/**
* Constructor.
*/
public function FXVideo()
{
super();
textFormat = new TextFormat();
var newContextMenu:ContextMenu;
newContextMenu = new ContextMenu();
newContextMenu.hideBuiltInItems();
var defaultItems:ContextMenuBuiltInItems = newContextMenu.builtInItems;
defaultItems.print = true;
var item:ContextMenuItem = new ContextMenuItem("About FX Video Player");
item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, onMenuItemSelect);
newContextMenu.customItems.push(item);
contextMenu = newContextMenu;
}
private var textFormat:TextFormat;
private var thumbHookedToPlayhead:Boolean = true;
private var volumeBeforeMute:Number = 0;
private var loadProgress:Number = 0;
private var flo:Boolean = true;
/** display objects */
private var controlBar:UIComponent;
private var playheadSlider:FXProgressSlider;
private var volumeSlider:FXSlider;
private var videoArea:UIComponent;
private var ppButton:PlayPauseButton;
private var stopButton:StopButton;
private var volumeButton:VolumeButton;
private var timerTextField:TextField;
/** style */
private var frontColor:uint;
private var backColor:uint;
private var controlBarHeight:uint;
private var timerFontName:String;
private var timerFontSize:Number;
/** properties */
private var _adjustVolumeOnScroll:Boolean = true;
/**
* Specifies whether the volume should adjust when users
* scroll over the video.
*
* @default true
*/
public function set adjustVolumeOnScroll(value:Boolean):void
{
_adjustVolumeOnScroll = value;
}
/**
* @private
*/
public function get adjustVolumeOnScroll():Boolean
{
return _adjustVolumeOnScroll;
}
/** */
private var _playPressed:Boolean;
private function set playPressed(value:Boolean):void
{
_playPressed = value;
(value) ? ppButton.state = "pause" : ppButton.state = "play"
}
private function get playPressed():Boolean
{
return _playPressed;
}
/**
* Creates any child components of the component. For example, the
* ComboBox control contains a TextInput control and a Button control
* as child components.
*/
override protected function createChildren():void
{
super.createChildren();
frontColor = getStyle("frontColor");
if(!frontColor)
frontColor = 0xcccccc;
backColor = getStyle("backColor");
if(!backColor)
backColor = 0x555555;
controlBarHeight = getStyle("controlBarHeight");
if(!controlBarHeight)
controlBarHeight = 21;
timerFontName = getStyle("timerFontName");
if(!timerFontName)
timerFontName = "Verdana";
timerFontSize = getStyle("timerFontSize");
if(!timerFontSize)
timerFontSize = 9;
addEventListener(MetadataEvent.METADATA_RECEIVED, onMetadataReceived);
addEventListener(MouseEvent.MOUSE_WHEEL, onMouseWheel);
addEventListener(ProgressEvent.PROGRESS, onProgress);
addEventListener(VideoEvent.PLAYHEAD_UPDATE, onPlayheadUpdate);
addEventListener(VideoEvent.STATE_CHANGE, onStateChange);
addEventListener(VideoEvent.REWIND, onRewind);
addEventListener(VideoEvent.COMPLETE, onComplete);
addEventListener(VideoEvent.READY, onReady);
videoArea = new UIComponent();
addChild(videoArea);
videoArea.addEventListener(MouseEvent.CLICK, pp_onClick);
controlBar = new UIComponent();
addChild(controlBar);
playheadSlider = new FXProgressSlider();
controlBar.addChild(playheadSlider);
playheadSlider.addEventListener(SliderEvent.CHANGE, playhead_onChange);
playheadSlider.addEventListener(SliderEvent.THUMB_PRESS, onThumbPress);
playheadSlider.addEventListener(SliderEvent.THUMB_RELEASE, onThumbRelease);
playheadSlider.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
playheadSlider.addEventListener(SliderEvent.THUMB_DRAG, onThumbDrag);
volumeSlider = new FXSlider();
controlBar.addChild(volumeSlider);
volumeSlider.addEventListener(SliderEvent.CHANGE, volume_onChange);
ppButton = new PlayPauseButton();
controlBar.addChild(ppButton);
ppButton.addEventListener(MouseEvent.CLICK, pp_onClick);
stopButton = new StopButton();
controlBar.addChild(stopButton);
stopButton.addEventListener(MouseEvent.CLICK, stop_onClick);
volumeButton = new VolumeButton();
controlBar.addChild(volumeButton);
volumeButton.addEventListener(MouseEvent.CLICK, volume_onClick);
timerTextField = new TextField();
controlBar.addChild(timerTextField);
(autoPlay) ? playPressed = true : playPressed = false
}
/**
* Commits any changes to component properties, either to make the
* changes occur at the same time, or to ensure that properties are set in
* a specific order.
*/
override protected function commitProperties():void
{
super.commitProperties();
ppButton.iconColor = frontColor;
stopButton.iconColor = frontColor;
volumeButton.iconColor = frontColor;
playheadSlider.setStyle("thumbColor", frontColor);
playheadSlider.setStyle("thumbOutlineColor", backColor);
volumeSlider.maximum = 1;
volumeSlider.value = volume;
volumeSlider.setStyle("thumbColor", frontColor);
volumeSlider.setStyle("thumbOutlineColor", backColor);
textFormat.color = frontColor;
textFormat.font = timerFontName;
textFormat.size = timerFontSize;
timerTextField.defaultTextFormat = textFormat;
timerTextField.text = "Loading";
timerTextField.selectable = false;
timerTextField.autoSize = TextFieldAutoSize.LEFT;
}
/**
* Sizes and positions the children of the component on the screen based on
* all previous property and style settings, and draws any skins or graphic
* elements used by the component. The parent container for the component
* determines the size of the component itself.
*/
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
var h:uint = controlBarHeight;
// draw
videoArea.graphics.clear();
videoArea.graphics.beginFill(0xffcccc, 0);
videoArea.graphics.drawRect(0, 0, unscaledWidth, unscaledHeight);
controlBar.graphics.clear();
controlBar.graphics.beginFill(backColor);
controlBar.graphics.drawRect(0, 0, unscaledWidth, h);
// size
controlBar.setActualSize(unscaledWidth, h);
ppButton.setActualSize(h, h);
stopButton.setActualSize(h, h);
volumeButton.setActualSize(h, h);
playheadSlider.setActualSize(unscaledWidth - 3*h - 180, 9);
volumeSlider.setActualSize(80, 9);
// position
controlBar.x = 0;
controlBar.y = unscaledHeight;
ppButton.x = 0;
ppButton.y = 0;
stopButton.x = h;
stopButton.y = 0;
playheadSlider.x = stopButton.x + h + 6;
playheadSlider.y = (controlBar.height - playheadSlider.height)/2;
timerTextField.x = playheadSlider.x + playheadSlider.width + 10;
timerTextField.y = (controlBar.height - timerTextField.height)/2;
volumeButton.x = unscaledWidth - volumeSlider.width - 12 - volumeButton.width;
volumeButton.y = 0;
volumeSlider.x = unscaledWidth - volumeSlider.width - 6;
volumeSlider.y = (controlBar.height - volumeSlider.height)/2;;
}
/** MouseEvent */
private function pp_onClick(event:MouseEvent):void
{
if(playPressed)
{
pause();
playPressed = false;
}
else
{
play();
playPressed = true;
}
}
private function stop_onClick(event:MouseEvent):void
{
stop();
playPressed = false;
}
private function volume_onClick(event:MouseEvent):void
{
if(volume == 0)
{
volume = volumeSlider.value = volumeBeforeMute;
}
else
{
volumeBeforeMute = volume;
volume = volumeSlider.value = 0;
}
}
private function onMouseDown(event:MouseEvent):void
{
thumbHookedToPlayhead = false;
}
private function onMouseWheel(event:MouseEvent):void
{
if(!_adjustVolumeOnScroll)
return;
volume += event.delta/Math.abs(event.delta)*.05;
volumeSlider.value = volume
}
/** SliderEvent */
private function onThumbPress(event:SliderEvent):void
{
thumbHookedToPlayhead = false;
}
private function onThumbRelease(event:SliderEvent):void
{
thumbHookedToPlayhead = true;
}
private function onThumbDrag(event:SliderEvent):void
{
timerTextField.text = formatTime(event.value)+" / "+formatTime(totalTime);
}
private function playhead_onChange(event:SliderEvent):void
{
thumbHookedToPlayhead = true;
playheadTime = event.currentTarget.value;
}
private function volume_onChange(event:SliderEvent):void
{
volume = event.currentTarget.value;
}
/** */
private function onRewind(event:VideoEvent):void
{
}
private function onMetadataReceived(event:MetadataEvent):void
{
playheadSlider.maximum = Math.round(totalTime);
play();
updateTimer();
}
private function onPlayheadUpdate(event:VideoEvent):void
{
if(thumbHookedToPlayhead)
{
playheadSlider.value = Math.round(event.playheadTime);
updateTimer();
}
if(flo)
{
thumbHookedToPlayhead = false;
}
if(flo && playheadTime > 0)
{
thumbHookedToPlayhead = true;
stop();
flo = false;
if(_playPressed)
{
play();
}
}
}
private function onStateChange(event:VideoEvent):void
{
//trace("state: "+event.state+" : "+event.stateResponsive);
if(event.state == VideoEvent.CONNECTION_ERROR)
{
timerTextField.text = "Conn Error";
}
}
private function onReady(event:VideoEvent):void
{
play();
}
private function onComplete(event:VideoEvent):void
{
playPressed = false;
}
private function onProgress(event:ProgressEvent):void
{
loadProgress = Math.floor(event.bytesLoaded/event.bytesTotal*100);
var playheadProgress:Number = Math.floor(playheadTime/totalTime*100);
playheadSlider.progress = loadProgress;
}
private function onMenuItemSelect(event:ContextMenuEvent):void
{
navigateToURL(new URLRequest("http://www.fxcomponents.com/?p=29"));
}
/** functions */
private function formatTime(value:int):String
{
var result:String = (value % 60).toString();
if (result.length == 1)
result = Math.floor(value / 60).toString() + ":0" + result;
else
result = Math.floor(value / 60).toString() + ":" + result;
return result;
}
private function formatVolume(value:Number):Number
{
var result:Number = Math.round(value*100);
return result;
}
private function updateTimer():void
{
timerTextField.text = formatTime(playheadTime)+" / "+formatTime(totalTime);
}
}
}
1.////////////////////////////////////////////////////////////////////////////////
//
// ADOBE SYSTEMS INCORPORATED
// Copyright 2004-2006 Adobe Systems Incorporated
// All Rights Reserved.
//
// NOTICE: Adobe permits you to use, modify, and distribute this file
// in accordance with the terms of the license agreement accompanying it.
//
////////////////////////////////////////////////////////////////////////////////package com.fxcomponents.skins
{import mx.skins.Border;/**
* The skin for the track in a Slider.
*/
public class SliderHighlightSkin extends Border
{
//--------------------------------------------------------------------------
//
// Constructor
//
//-------------------------------------------------------------------------- /**
* Constructor.
*/
public function SliderHighlightSkin()
{
super();
} //--------------------------------------------------------------------------
//
// Overridden properties
//
//-------------------------------------------------------------------------- //----------------------------------
// measuredWidth
//---------------------------------- /**
* @private
*/
override public function get measuredWidth():Number
{
return 200;
} //----------------------------------
// measuredHeight
//---------------------------------- /**
* @private
*/
override public function get measuredHeight():Number
{
return 7;
}
//--------------------------------------------------------------------------
//
// Overridden methods
//
//--------------------------------------------------------------------------
/**
* @private
*/
override protected function updateDisplayList(w:Number, h:Number):void
{
super.updateDisplayList(w, h);
var trackColor:Number = getStyle("themeColor");
graphics.clear();
drawRoundRect(0, 0, w, h, 0, trackColor, 1);
}
}}2.////////////////////////////////////////////////////////////////////////////////
//
// ADOBE SYSTEMS INCORPORATED
// Copyright 2004-2006 Adobe Systems Incorporated
// All Rights Reserved.
//
// NOTICE: Adobe permits you to use, modify, and distribute this file
// in accordance with the terms of the license agreement accompanying it.
//
////////////////////////////////////////////////////////////////////////////////package com.fxcomponents.skins
{import mx.skins.Border;/**
* The skin for the track in a Slider.
*/
public class SliderProgressSkin extends Border
{
//--------------------------------------------------------------------------
//
// Constructor
//
//-------------------------------------------------------------------------- /**
* Constructor.
*/
public function SliderProgressSkin()
{
super();
} //--------------------------------------------------------------------------
//
// Overridden properties
//
//-------------------------------------------------------------------------- //----------------------------------
// measuredWidth
//---------------------------------- /**
* @private
*/
override public function get measuredWidth():Number
{
return 200;
} //----------------------------------
// measuredHeight
//---------------------------------- /**
* @private
*/
override public function get measuredHeight():Number
{
return 7;
}
//--------------------------------------------------------------------------
//
// Overridden methods
//
//--------------------------------------------------------------------------
/**
* @private
*/
override protected function updateDisplayList(w:Number, h:Number):void
{
super.updateDisplayList(w, h);
var c:Number = getStyle("progressColor");
graphics.clear();
drawRoundRect(0, 0, w, h, 0, c, 1);
}
}}
////////////////////////////////////////////////////////////////////////////////
//
// ADOBE SYSTEMS INCORPORATED
// Copyright 2004-2007 Adobe Systems Incorporated
// All Rights Reserved.
//
// NOTICE: Adobe permits you to use, modify, and distribute this file
// in accordance with the terms of the license agreement accompanying it.
//
////////////////////////////////////////////////////////////////////////////////package com.fxcomponents.skins
{import flash.display.Graphics;import mx.skins.ProgrammaticSkin;/**
* The skin for all the states of a thumb in a Slider.
*/
public class SliderThumbSkin extends ProgrammaticSkin
{
//--------------------------------------------------------------------------
//
// Constructor
//
//-------------------------------------------------------------------------- /**
* Constructor.
*/
public function SliderThumbSkin()
{
super();
} //--------------------------------------------------------------------------
//
// Overridden properties
//
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
//
// Overridden methods
//
//--------------------------------------------------------------------------
/**
* @private
*/
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
var c:uint = getStyle("thumbColor");
var g:Graphics = graphics;
g.clear();
g.beginFill(getStyle("thumbOutlineColor"), 1);
g.drawRect(-unscaledWidth/2 - 1, -1, unscaledWidth + 2, unscaledHeight + 2);
switch (name)
{
case "upSkin":
{
g.beginFill(c, 1);
break;
}
case "overSkin":
{
g.beginFill(c + 0x111111, 1);
break;
}
case "downSkin":
{
g.beginFill(c + 0x111111, 1);
break;
}
case "disabledSkin":
{
g.beginFill(c, .5);
break;
}
}
g.drawRect(-unscaledWidth/2, 0, unscaledWidth, unscaledHeight);
}
}
}4.
////////////////////////////////////////////////////////////////////////////////
//
// ADOBE SYSTEMS INCORPORATED
// Copyright 2004-2006 Adobe Systems Incorporated
// All Rights Reserved.
//
// NOTICE: Adobe permits you to use, modify, and distribute this file
// in accordance with the terms of the license agreement accompanying it.
//
////////////////////////////////////////////////////////////////////////////////package com.fxcomponents.skins
{import mx.skins.Border;/**
* The skin for the track in a Slider.
*/
public class SliderTrackSkin extends Border
{
//--------------------------------------------------------------------------
//
// Constructor
//
//-------------------------------------------------------------------------- /**
* Constructor.
*/
public function SliderTrackSkin()
{
super();
} //--------------------------------------------------------------------------
//
// Overridden properties
//
//-------------------------------------------------------------------------- //----------------------------------
// measuredWidth
//---------------------------------- /**
* @private
*/
override public function get measuredWidth():Number
{
return 200;
} //----------------------------------
// measuredHeight
//---------------------------------- /**
* @private
*/
override public function get measuredHeight():Number
{
return 7;
}
//--------------------------------------------------------------------------
//
// Overridden methods
//
//--------------------------------------------------------------------------
/**
* @private
*/
override protected function updateDisplayList(w:Number, h:Number):void
{
super.updateDisplayList(w, h);
var trackColor:Number = getStyle("trackColor");
graphics.clear();
drawRoundRect(0, 0, w, h, 0, trackColor, 1);
}
}}
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init();">
<mx:Style>
global{fontSize: 12;}
</mx:Style>
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.SliderEvent;
import mx.events.VideoEvent;
import mx.collections.ArrayCollection;
import mx.rpc.events.ResultEvent;
private var fExt:Array=[".flv",
".swf"];
private var video_width:Number;
private var video_height:Number;
//private var _video:ArrayCollection;
private var isplaying:Boolean=false;
private var playPosition:Number;
private var soundPosition:Number;
private function init():void
{
//
hs.enabled=false;
// stage.displayState = StageDisplayState.FULL_SCREEN;
} private function to_play(event:Event):void
{
//
if (this.file_list.selectedIndex==-1)
{
Alert.show("你沒有選擇播放文件.");
return;
}
var sTemp:String;
var sFile:File;
sFile=File(this.file_list.selectedItem);
sTemp=sFile.nativePath;
//Alert.show(sTemp);
my_video.source=sTemp;
video_width=this.my_video.width;
video_height=this.my_video.height;
hs.enabled=true;
//xml扩展,读取第一个XML第一个文件示例
//my_video.source="videos/"+_video.getItemAt(0).filename;
//trace(_video.getItemAt(0).filename);
if(isplaying){
my_video.pause();
btn_play.label="播放"
}else {
my_video.play();
btn_play.label="暫停"
}
isplaying = !isplaying;
my_video.addEventListener(VideoEvent.PLAYHEAD_UPDATE, progressHandler);
}
private function to_play_2(event:Event):void
{
//
if (this.file_list.selectedIndex==-1)
{
Alert.show("你沒有選擇播放文件.");
return;
}
var sTemp:String;
var sFile:File;
sFile=File(this.file_list.selectedItem);
sTemp=sFile.nativePath;
//Alert.show(sTemp);
my_video.source=sTemp;
video_width=this.my_video.width;
video_height=this.my_video.height;
hs.enabled=true;
btn_play.label="暫停"
isplaying = true;
my_video.addEventListener(VideoEvent.PLAYHEAD_UPDATE, progressHandler);
}
private function do_palyback(event:Event):void
{
var sFileTemp:String;
if (this.rbtn_paly_1.selected)
{
sFileTemp=my_video.source;
this.file_list.selectedIndex+=1;
//if (this.file_list.selectedIndex==this.file_list.rowCount)
// this.file_list.selectedIndex=0;
var sTemp:String;
var sFile:File;
sFile=File(this.file_list.selectedItem);
sTemp=sFile.nativePath;
if (sTemp==sFileTemp)
{
this.file_list.selectedIndex=0;
sFile=File(this.file_list.selectedItem);
sTemp=sFile.nativePath;
}
//Alert.show(sTemp);
my_video.source=sTemp;
video_width=this.my_video.width;
video_height=this.my_video.height;
my_video.play();
}
else
{
this.my_video.play();
}
my_video.addEventListener(VideoEvent.PLAYHEAD_UPDATE, progressHandler);
}
private function video_stop(event:Event):void
{
this.my_video.stop();
btn_play.label="播放"
isplaying = false;
}
private function v_room_big(event:Event):void
{
//
//
//Alert.show(String(this.file_list.rowCount));
}
private function v_room_small(event:Event):void
{
//
}
private function do_pause(event:Event):void
{
//
this.my_video.pause();
//Alert.show(String(video_width)+" 高"+String(video_height));
}
//播放器监听事件,从my_video里不停的得到值然后传输给HSLIDER
private function progressHandler(event:VideoEvent):void
{
hs.value=my_video.playheadTime;
}
//拉动进度条
private function thumbPress(event:SliderEvent):void
{
my_video.pause();
}
//进度条改变后,得到的值赋予PLAYPOSITION;
private function thumbChanges(event:SliderEvent):void
{
if(my_video.playheadTime == -1){
hs.value = 0;
return;
}
playPosition = hs.value;
}
//放开进度条,再把PLAYPOSITION的值发给播放器;
private function thumbRelease(event:SliderEvent):void
{
my_video.playheadTime = playPosition;
if(isplaying){
my_video.play();
}else{
my_video.pause();
}
}
//声音音量控制
private function sound_thumbChanges(event:SliderEvent):void
{
soundPosition = hs_sound.value;
}
private function sound_thumbRelease(event:SliderEvent):void
{
my_video.volume = soundPosition;
}
//格式化时间
private function formatTimes(value:int):String
{
var result:String = (value % 60).toString();
if (result.length == 1){
result = Math.floor(value / 60).toString() + ":0" + result;
} else {
result = Math.floor(value / 60).toString() + ":" + result;
}
return result;
}
]]>