Created
August 19, 2013 15:22
-
-
Save danielkhan/6270343 to your computer and use it in GitHub Desktop.
banner with streaming video
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import flash.events.MouseEvent; | |
var sUrl:String = "http://<VIDEO_URI>"; | |
var metaObj:Object = new Object(); | |
var connection:NetConnection = new NetConnection(); | |
var stream:NetStream; | |
connection.connect(null); | |
stream = new NetStream(connection); | |
stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler); | |
var video:Video = new Video(); | |
var st:SoundTransform = stream.soundTransform; | |
var oldvolume = st.volume; | |
var mc:MovieClip = new MovieClip(); | |
stream.client = metaObj; | |
metaObj.onMetaData = onMetaData; | |
// MC | |
video.attachNetStream(stream); | |
this.mute(); | |
mc.addChild(video); | |
mc.buttonMode = true; | |
mc.useHandCursor = true; | |
mc.addEventListener(MouseEvent.ROLL_OVER, ev_unmute); | |
mc.addEventListener(MouseEvent.ROLL_OUT, ev_mute); | |
mc.addEventListener(MouseEvent.MOUSE_UP, onClick); | |
stage.addChild(mc); | |
stream.play(sUrl); | |
video.x = 0; | |
video.y = 0; | |
function onMetaData(data:Object):void { | |
video.width= data.width; | |
video.height = data.height; | |
} | |
function netStatusHandler(e:NetStatusEvent){ | |
if (e.info.code == "NetStream.Buffer.Empty") { | |
stream.seek(0); | |
} | |
}; | |
function ev_unmute(event:MouseEvent):void { | |
this.unmute(); | |
} | |
function ev_mute(event:MouseEvent):void { | |
this.mute(); | |
} | |
function mute() { | |
var oldvolume = st.volume; | |
st.volume = 0; | |
stream.soundTransform = st; | |
} | |
function unmute() { | |
st.volume = oldvolume; | |
stream.soundTransform = st; | |
} | |
function onClick(e:MouseEvent):void { | |
var click_url:String = root.loaderInfo.parameters.clickTag; | |
if(click_url) { | |
this.mute(); | |
navigateToURL(new URLRequest(click_url), '_blank'); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment