show dimension of flv in text field - actionscript-3

Below is my basic code, im loading a flv video using flvplayback.
i need the features of flvplayback compulsorily.
I have finished loading flv video sucessfully.
Now im stuckup with showing the source video files original dimension in a text field.
How should proceed further from here. Please guide me......
stage.displayState = StageDisplayState.FULL_SCREEN;
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
import fl.video.*;
stop();
var rmys01:FLVPlayback = new FLVPlayback();
rmys01.source = "rhym01.flv";
rmys01.skin = "MinimaFlatCustomColorPlayBackSeekCounterVolMute.swf";
rmys01.autoPlay = true;
rmys01.fullScreenTakeOver = false;
rmys01.scaleMode = "maintainAspectRatio";
rmys01.setSize((stage.stageWidth/1.03), (stage.stageHeight/1.03));
rmys01.x = (stage.stageWidth/2) - (rmys01.width/2);
rmys01.y = (stage.stageHeight/1.1) - (rmys01.height/1.1);
addChild(rmys01);
setChildIndex(rmys01,1);

Did you set client for the NetStream? Because, all work ok.
Here is an example:
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
var client: Object = {};
client.onMetaData = function(data:Object):void{
//Display width and height
var textField: TextField = new TextField();
textField.autoSize = TextFieldAutoSize.LEFT;
textField.defaultTextFormat = new TextFormat("Arial", 28);
textField.text = "Width: " + data.width + ", Height: " + data.height;
addChild(textField);
}
ns.client = client;
ns.play("path/to/Video");
var myVideo:Video = new Video();
myVideo.attachNetStream(ns);
addChild(myVideo);
For debugging purposes place trace (trace("There is MetaData!");) to the onMetaData handler, check, if it triggers.
For FLVPlayback, you should subscribe for VideoEvent.READY:
rmys01.addEventListener(VideoEvent.READY, onReady);
function onReady(e:VideoEvent):void {
trace("READY");
var flvPlayback:FLVPlayback = e.target as FLVPlayback;
var metaData:Object = flvPlayback.metadata as Object;
trace("height: "+metaData.height);
trace("width: "+metaData.width);
trace("duration: "+metaData.duration);
}
If you are coding in Flash IDE, there will be a problem with VideoEvent, so you should use fully qualified class (fl.video.VideoEvent), if not, IDE will try resolve it to the flash.events.VideoEvent:
rmys01.addEventListener(fl.video.VideoEvent.READY, onReady);
function onReady(e:fl.video.VideoEvent):void {
//Handler code
}

Related

Convert Actionscript 3 to Actionscript 2

I have an problem to convert AS3 to AS2
Here is my AS3 code
submit.addEventListener("mouseDown", sendData);
function sendData(evt:Event)
{
//for those using PHP
var students:URLRequest = new URLRequest("http://localhost/phpflash/new_student.php");
students.method = URLRequestMethod.POST;
var posts:URLVariables = new URLVariables();
posts.Fullname = Fullname.text;
students.data = posts;
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.load(students);
}
Like #VC.One said, you must learn AS3, AS2 was dropped and actually Flash CC does not support it.
I do not code in AS2 since many, many years. So this code could contain some errors:
submit.onMouseDown = sendData;
function sendData():Void
{
var vars:LoadVars = new LoadVars();
vars.Fullname = Fullname.text;
var target:Object = new Object();
target.onLoad = function(){
trace("vars sended");
}
vars.sendAndLoad("http://localhost/phpflash/new_student.php", target, "POST");
}

play a external flv video

Hello please someone can help me with this ...
I want to play a external flv video ("../sync/video/video.flv"), but in case the video is missing or when there is a (StreamNotFound) error
I want to play automatically another flv video.
case "NetStream.Play.StreamNotFound":
ns.play("../sync/filler/video2.flv");
but it doesn't work ....
here is the full code :
var vid:Video;
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
var customClient:Object = new Object();
customClient.onMetaData = metaDataHandler;
ns.client = customClient;
ns.play("../sync/video/video.flv");
vid = new Video();
vid.attachNetStream(ns);
addChild(vid);
function netStatusF(e:NetStatusEvent):void
{
switch (e.info.code)
{
case "NetStream.Play.StreamNotFound" :
ns.play("../sync/filler/video2.flv");
break;
}
}
function metaDataHandler(infoObject:Object):void
{
vid.width = infoObject.width;
vid.height = infoObject.height;
}
You have just to add a NetStatusEvent.NET_STATUS event listener to your NetStream object :
ns.addEventListener(NetStatusEvent.NET_STATUS, netStatusF);
Then you have to assure that your second video file exist, otherwise you'll have a looping problem.
Hope that can help.

How do I know the length of the video (external FLV video)?

How do I know the length of the video (external FLV video)?
I have tried several ways but the result is 0.
videonya.addEventListener(fl.video.VideoEvent.READY, onFlvPlayback_READY);
function onFlvPlayback_READY(event:fl.video.VideoEvent):void
{
var metaDataObj:Object = videonya.metadata as Object;
trace("metaDataObj.duration: "+metaDataObj.duration);
}
The standard way of playing video and accessing metadata is this:
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
ns.client = this;
ns.play("video.flv");
var vid:Video = new Video();
vid.attachNetStream(ns);
addChild(vid);
function onMetaData(infoObject:Object):void
{
var key:String;
for (key in infoObject)
{
trace(key + ": " + infoObject[key]);
}
}
This will trace out all of the metadata codes including duration. If you just want the duration: trace(infoObject.duration); inside the onMetaData(infoObject) function, of course.

Load external swf into bytearray with adobe flash

How can I load external swf into bytearray with adobe flash AS3..
Here is my code..
var my_url1:URLRequest = new URLRequest("SWF/Lesson1.swf");
my_url1.method = URLRequestMethod.GET;
my_url1.contentType = "application/x-shockwave-flash";
var urlloader:URLLoader = new URLLoader(my_url1);
var myByteArray:ByteArray = new ByteArray();
urlloader.data = myByteArray;
It not works well. But it isn't give any error. How can I fix this problem?
You should listen for COMPLETE event and set the data format to BINARY:
var my_url1:URLRequest = new URLRequest("SWF/Lesson1.swf");
var urlloader:URLLoader = new URLLoader(my_url1);
urlloader.dataFormat = URLLoaderDataFormat.BINARY;
urlloader.addEventListener(Event.COMPLETE, function(event:Event):void
{
var myByteArray:ByteArray = URLLoader(event.target).data as ByteArray;
trace(myByteArray.length);
});

Display XML content in Flash movie as Text

Inside a Flash Movie (Actionscript 3) I need to display the content of a XML file.
I am passing the url of the file as a parameter. So I am using the following:
var file : XML;
var url = loaderInfo.parameters.url;
var loader = new URLLoader();
loader.addEventListener(Event.COMPLETE, onLoadComplete);
loader.load(new URLRequest(url));
function onLoadComplete(e:Event){
file = new XML(e.target.data);
} // OnLoadComplete
How can I display the entire content of the XML file, as text, in the Flash Movie?
Probably the content will be big so I would like to have scroll bars.
Thank You,
Miguel
try this for example.
//... previous code
loader.load(new URLRequest(url));
var myTextBox:TextField = new TextField();
myTextBox.width = 200;
myTextBox.height = 150;
myTextBox.multiline = true;
myTextBox.wordWrap = true;
myTextBox.background = true;
myTextBox.border = true;
addChild(myTextBox);
function onLoadComplete(e:Event){
file = new XML(e.target.data);
myTextBox.text = file.toString();
}