ActionScript 3.0 Design Patterns

(Chris Devlin) #1

348 | Chapter 9: Template Method Pattern


addChild(vidNow);
ns.addEventListener(NetStatusEvent.NET_STATUS, stopClear);


//MetaData check
var dummy:Object=new Object( );
ns.client=dummy;
dummy.onMetaData=getMeta;
}


//Clear the video and duration text when video is over
function stopClear(event:NetStatusEvent):void
{
if (event.info.code=="NetStream.Play.Stop")
{
vidNow.clear( );
durText.text="";
}
}


//Show the
function getMeta(mdata:Object):void
{
durText=new TextField( );
this.addChild(durText);
durText.text="Duration:"+mdata.duration;
durText.x=((550/2)-(durText.width/2));
durText.y=300;
}
}
}


Example 9-12. PlayTune.as


package
{
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.net.URLRequest;


public class PlayTune
{
private var channelNow:SoundChannel;


public function PlayTune(tuneNow:String)
{
tuneNow+=".mp3";
var playMe:URLRequest=new URLRequest(tuneNow);
var soundMedia:Sound=new Sound( );
soundMedia.load(playMe);
channelNow=soundMedia.play( );
}
}
}


Example 9-11. PlayVideo.as (continued)

Free download pdf