Created
February 7, 2011 00:34
-
-
Save getflourish/813862 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package | |
{ | |
import flash.display.Bitmap; | |
import flash.display.BitmapData; | |
import flash.display.Sprite; | |
import flash.events.Event; | |
import flash.events.ProgressEvent; | |
import flash.utils.Timer; | |
import flash.events.TimerEvent; | |
public class Main extends Sprite | |
{ | |
var image:ImageLoader; | |
var imageFrameCounter:Number = 1; | |
var images:Array; | |
var imagesToLoad:Number = 4; | |
var path:String = "takePhotos/01-0"; | |
public function Main() | |
{ | |
image = new ImageLoader(); | |
image.addEventListener(Event.COMPLETE, onImageLoaded); | |
image.addEventListener(ProgressEvent.PROGRESS, onImageLoading); | |
addChild(image); | |
images = []; | |
loadImage(); | |
// AS3 | |
var myTimer:Timer = new Timer(1000, 0); // 1 second | |
myTimer.addEventListener(TimerEvent.TIMER, onTimer); | |
myTimer.start(); | |
} | |
private function loadImage ():void | |
{ | |
image.alpha = 0; | |
image.loadImage(path + imagesToLoad + ".jpg"); | |
} | |
public function onImageLoaded(event:Event) | |
{ | |
// Hier könnte man TweenLite benutzen um das Bild einzublenden | |
trace("loaded"); | |
var bitmap:Bitmap; | |
var bitmapData:BitmapData; | |
bitmapData = new BitmapData(image.width, image.height); | |
bitmapData.draw(image); | |
bitmap = new Bitmap(bitmapData); | |
images.push(bitmap); | |
imagesToLoad--; | |
if (imagesToLoad > 0) loadImage(); | |
} | |
public function onImageLoading(event:ProgressEvent) | |
{ | |
// Hier könnte man einen Preloader anzeigen (bytesTotal geht nur lokal) | |
} | |
public function onTimer(event:TimerEvent) | |
{ | |
image.alpha = 1; | |
if (imageFrameCounter < 3) { | |
imageFrameCounter++; | |
} else { | |
imageFrameCounter = 0; | |
} | |
while (image.numChildren > 0) { | |
image.removeChildAt(0); | |
} | |
trace(imageFrameCounter); | |
image.addChild(images[imageFrameCounter]); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment