My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/**
* Hi-ReS! BitmapDataSequence v1.1
* Copyright (c) 2008 Mr.doob @ hi-res.net
*
* Released under MIT license:
* http://www.opensource.org/licenses/mit-license.php
*
* How to use:
*
* var video:BitmapDataSequence = BitmapDataSequence( "flvinaswf.swf", 320, 340, 30 );
* addChild(video);
*
* version log:
*
* 08.03.22 1.1 Mr.doob + Now you can set the size of the video
* 08.03.18 1.0 Mr.doob + First version
**/

package net.hires.utils.display
{

import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Loader;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Matrix;
import flash.net.URLRequest;
import flash.utils.setTimeout;

public class BitmapDataSequence extends Sprite
{
private var file :String;
private var finalSize :Object = { width:0, height:0 };
private var originalSize:Object = { width:0, height:0 };
private var bdheight :Number;
private var fps :Number;
private var totalFrames :Number;

private var bitmap :Bitmap;
private var mc :MovieClip;
private var loader :Loader;
private var bdArray :Array;

private var frame :Number;

public function BitmapDataSequence(file:String, width:Number = 0, height:Number = 0, fps:Number = 0):void
{
this.file = file;
this.fps = (fps) ? fps : 30;
this.finalSize.width = (width) ? width : 0;
this.finalSize.height = (height) ? height : 0;

loader = new Loader();
bdArray = new Array();
bitmap = new Bitmap();
addChild(bitmap);

load();
}

private function nextFrame():void
{
bitmap.bitmapData = bdArray[frame];
frame ++;
frame %= totalFrames-1;
setTimeout(nextFrame, 1000 / fps);
}

private function load():void
{
loader.load(new URLRequest(file));
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
}

private function onLoadComplete(e:Event):void
{
mc = e.target.content;

originalSize.width = mc.width;
originalSize.height = mc.height;

if (!finalSize.width)
{
finalSize.width = mc.width;
finalSize.height = mc.height;
}

totalFrames = mc.totalFrames;
frame = 1;
convert();
}

private function convert():void
{
if (frame == totalFrames)
{
nextFrame();
return;
}

mc.gotoAndStop(frame);

var mtr:Matrix = new Matrix();

mtr.scale(finalSize.width / originalSize.width, finalSize.height / originalSize.height);

var bd:BitmapData = new BitmapData(finalSize.width, finalSize.height, true, 0x00000000);
bd.draw(mc, mtr);

bdArray.push(bd);
frame++;

convert();
}

}

}

Change log

r85 by i...@mrdoob.com on Mar 21, 2008   Diff
[No log message]
Go to: 
Project members, sign in to write a code review

Older revisions

r84 by i...@mrdoob.com on Mar 21, 2008   Diff
@BitmapDataSequence.as
- Added resizing support
r80 by i...@mrdoob.com on Mar 17, 2008   Diff
@net.hires.utils
- BitmapDataSequence.as
All revisions of this file

File info

Size: 2830 bytes, 120 lines
Powered by Google Project Hosting