Video class in Actionscript 3

February 10th, 2009

Hi again for all, well think you creating a simple video player in max one minute.  ”Yes, We Can”.  Using  the videoPlayer class from asDataLibs. The videoPlayer is a simple way to make your video player or video gallery using less time than the normal process. Bellow some features:

• Support HD (h.264)
• Play and Pause button together;
• Mute button;
• Seek bar and loaded bar;
• Time played and total time of video.

In final of this post you will see the link to download the sample video player and the source code demonstrated in this article. See the sample of video Bellow.

(Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player.)
video by Flasher Magazine

Create the video is so simple like show these actionscript line ahead:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package
{
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import com.dLibs.video.videoPlayer;
 
	public class main extends MovieClip
	{
		private var videoObject:videoPlayer;
		private var videoURL:String = "http://adobe.edgeboss.net/download/adobe/adobetv/flasher_magazine/issue_1/issue1.mp4";
		private var videoWidth:uint = 700;
		private var videoHeight:uint = 400;
		private var videoStart:Boolean = false;
 
		public function main():void
		{
			videoObject = new videoPlayer(videoURL,700,400,false);
			videoObject.addBuffer 		= newBuffer;
			videoObject.addPlayPause 	= playPause;
			videoObject.addMuteSound 	= muteIcon;
			videoObject.addDuration 	= seekControll.theTime;
			videoObject.addSeek 		= {progress:seekControll.seekProgress, loader:seekControll.seekLoader};
			newVideo.addChild(videoObject);
 
			// @ Change status of playPause Button
 
			playPause.addEventListener(MouseEvent.CLICK, changePlayPause);
		}
 
		private function changePlayPause(m:MouseEvent):void
		{
			if ( m.currentTarget.currentFrame == 1 ) 	{ m.currentTarget.nextFrame(); }
			else 										{ m.currentTarget.prevFrame(); }
		}
	}
}

In resume the videoPlayer object receive three variables:
• URL of video, width and height of video.
By default this video will play when buffer is full, but can change it sending ‘false’ withe the fourth variable that is if the video will start or not on load buffer complete. Other optional variable is buffer time. The complete object is:

new videoPlayer(videoURL:String,videoWidth:uint, videoHeight:uint, videoStart:Boolean = true, videoBuffer:uint = 10)

Now you can put the playpause button, mute button and seek too:

19
20
21
22
23
videoObject.addBuffer 		= newBuffer;
videoObject.addPlayPause 	= playPause;
videoObject.addMuteSound 	= muteIcon;
videoObject.addDuration 	= seekControll.theTime;
videoObject.addSeek 		= {progress:seekControll.seekProgress, loader:seekControll.seekLoader};

After that you need add this object in your stage and now see your video into Flash using Actionscript 3 easy.

Download the sample and source here.

Read too:

5 Responses to “Video class in Actionscript 3”

  1. Diogo Lean Says:

    I also made an as3 video class, but yous class looks cleaner..
    check out:
    http://www.blog.diogolean.com/

  2. mark los Says:

    Can you resize the video object once it has been created and while it is playing?
    I havent been able to find the attribute to set
    width does not work.

  3. Pablo Davi Says:

    If you download the repository will se a new class path: novesfora. Inside novesfora have other folder ‘video’ and have two classes, the base classe is VideoPlayer.as and with this you can resize your video, width or height, all the time.

    Create your videoPlayer object and set the config data
    var video:VideoPlayer = new VideoPlayer();
    video.config(width,height);

    Its easy. Tryit

  4. SAMSUNG 46 LCD HDTV Says:

    Oh yea, what a great evil plan to get followers. And I like it ;)

  5. Bruno Says:

    Worst. Teaser. Evar.

Leave a Reply