Abdulcode

Pages

Jul 29, 2010

Flex : VideoDisplay

VideoDisplay control to play back video files that have been encoded as either Flash Video (FLV) videos or MPEG-4 videos with H.264 encoding. The VideoDisplay control can display both progressive download video and streaming video. A Flex VideoDisplay control can be created with the <mx:VideoDisplay> MXML tag.

The Flex framework comes with only the most basic video controls, which is the video playback control. It doesn’t include a prebuilt video player with play and pause buttons or a volume control. You can easily build your own, simple playback controls, but just be aware that the VideoDisplay control displays only video.

Code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
horizontalAlign="center"
backgroundGradientAlphas="[1.0, 1.0]"
backgroundGradientColors="[#000000, #000000]">

<mx:Script>
<![CDATA[

import mx.events.VideoEvent;

[Bindable]
private var videoStatus:String;

private function callPlayHead(e:VideoEvent):void
{
videoStatus = videoDispID.playheadTime +
" / " + videoDispID.totalTime;
}
]]>
</mx:Script>

<mx:VideoDisplay id="videoDispID"
source="assets/Video Song.flv"
playheadUpdate="callPlayHead(event);"/>

<mx:Label text="Status : {videoStatus}"
color="#4E92A0"
fontWeight="bold"/>

<mx:HBox>
<mx:Button label="Play"
enabled="{videoDispID.playing == false}"
click="videoDispID.play();"/>
<mx:Button label="Pause"
enabled="{videoDispID.playing == true}"
click="videoDispID.pause();"/>
<mx:Button label="Stop"
enabled="{videoDispID.playing == true}"
click="videoDispID.stop();"/>
</mx:HBox>

</mx:Application>

Jul 26, 2010

Function parameters

Pass by Value
function passPrimitives(xParam:int, yParam:int):void
{
xParam++;
yParam++;
trace(xParam, yParam);
}

var xValue:int = 10;
var yValue:int = 15;

trace(xValue, yValue); // 10 15
passPrimitives(xValue, yValue); // 11 16
trace(xValue, yValue); // 10 15

Pass by Reference
function passByRef(objParam:Object):void
{
objParam.x++;
objParam.y++;
trace(objParam.x, objParam.y);
}

var objVar:Object = {x:10, y:15};

trace(objVar.x, objVar.y); // 10 15
passByRef(objVar); // 11 16
trace(objVar.x, objVar.y); // 11 16
The objParam parameter references the same object as the global objVar variable. As you can see from the trace statements in the example, changes to the x and y properties of the objParam object are reflected in the objVar object.

Jul 23, 2010

AS3 : Dynamic classes

A dynamic class defines an object that can be altered at run time by adding or changing properties and methods. A class that is not dynamic, such as the String class, is a sealed class. You cannot add properties or methods to a sealed class at run time.

You create dynamic classes by using the dynamic attribute when you declare a class. For example, the following code creates a dynamic class named "DynamicClass".

Code : /*Main.as*/
package
{
import flash.display.Sprite;

public class Main extends Sprite
{
public function DynamicClassCode()
{
var dClass:DynamicClass = new DynamicClass();

dClass.age = 25; // Dynamically add new variable.
// Dynamically add new Method.
dClass.getDetails = function():void
{
trace(dClass.nama);
trace(dClass.age);
}

dClass.getDetails(); // Method call
}
}
}

dynamic class DynamicClass
{
public var nama:String = "Abdul";
}