Skip to content

Instantly share code, notes, and snippets.

@acidsound
Created April 2, 2013 17:47
Show Gist options
  • Save acidsound/5294460 to your computer and use it in GitHub Desktop.
Save acidsound/5294460 to your computer and use it in GitHub Desktop.
as3 에서 m4a 파일을 로드하는 예제
package {
import flash.display.MovieClip;
import flash.net.NetStream;
import flash.net.NetConnection;
import flash.events.NetStatusEvent;
import flash.events.AsyncErrorEvent;
import flash.events.Event;
import flash.events.MouseEvent;
public class Main extends MovieClip {
private var _connection:NetConnection=new NetConnection();
private var _netStream:NetStream=null;
public function Main() {
// constructor code
addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
pushButton.addEventListener(MouseEvent.CLICK, onClickPushButton);
}
private function onClickPushButton(e:Event) {
this._netStream.play("./m4a/01_001.m4a");
}
private function onAddedToStage(e:Event) {
trace("on added");
this._connection.close();
this._connection=new NetConnection();
this._connection.addEventListener(NetStatusEvent.NET_STATUS, this.netStatusHandler);
this._connection.addEventListener(AsyncErrorEvent.ASYNC_ERROR, this.asyncErrorHandler);
this._connection.connect(null);
//stream_ns.play("01_001.m4a");
}
private function netStatusHandler(event:NetStatusEvent) {
trace(event.info.code);
switch (event.info.code) {
case "NetConnection.Connect.Success":
this.requestAudio();
break;
}
}
private function requestAudio():void {
if(this._netStream!==null)
this._netStream.close();
this._netStream=new NetStream(this._connection);
this._netStream.addEventListener(NetStatusEvent.NET_STATUS, this.netStatusHandler);
this._netStream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, this.asyncErrorHandler);
this._netStream.checkPolicyFile=false;
}
private function asyncErrorHandler(event:AsyncErrorEvent) {
trace(event);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment