EU Flag
[SWF (width="465",height="465",backgroundColor="0x000000",frameRate="60")]
// forked from fakestar0826's forked from: forked from: code on 2008-12-18
// forked from hacker_9p8x8mco's forked from: code on 2008-12-18
package{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.display.GradientType;
import flash.filters.DisplacementMapFilter;
import flash.events.Event;
import flash.geom.Point;
import flash.text.TextField;
import flash.text.TextFormat;
import net.hires.debug.Stats;
import flash.display.BlendMode;
import flash.events.MouseEvent;
[SWF (width="465",height="465",backgroundColor="0xffffff",frameRate="60")]
public class HelloFlag extends Sprite{
private var stats:Stats;
private var flag:ImageLoader;
private var stageW:int, stageH:int;
public function HelloFlag(){
stageW = 500;
stageH = 500;
flag = new ImageLoader(init);
flag.x=-5;
flag.y=-5;
/*flag.graphics.beginFill(0xffffff);
flag.graphics.drawRect(0,0,stageW ,stageH);
flag.graphics.endFill();*/
addChild(flag);
var tf:TextField = new TextField();
tf.text = "Loading...";
tf.autoSize = "left";
tf.setTextFormat(new TextFormat("_self",48,0x000000));
tf.x = (400 - tf.width) / 2;
tf.y = (300 - tf.height) / 2;
tf.selectable = false;
flag.addChild(tf);
}
public function init(e:Event=null):void {
var bmpd:BitmapData = new BitmapData(flag.width,flag.height);
var bmpdisplace:Bitmap = new Bitmap(bmpd);
addChild(bmpdisplace);
bmpdisplace.blendMode = BlendMode.HARDLIGHT;
bmpdisplace.alpha=1.0;
var v:Number = 0;
stats = new Stats();
stats.visible = false;
addChild(stats);
stage.addEventListener(Event.ENTER_FRAME,function():void{
bmpd.perlinNoise(bmpd.width,bmpd.height,2,3,false,true,7,true,[new Point(v,0),new Point(v,0)]);
flag.filters = [new DisplacementMapFilter(bmpd,new Point(0,0),1,1,30,30,"color")];
v += 15;
});
stage.addEventListener(MouseEvent.CLICK,function():void{
stats.visible = stats.visible?false:true;
});
addChild(new FullScreenButton());
}
}
}
import flash.display.Sprite;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.events.*;
import flash.net.*;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.system.LoaderContext;
import flash.geom.Rectangle;
import flash.geom.Matrix;
class ImageLoader extends Sprite {
private var loader:Loader = new Loader( );
private var bd: BitmapData;
private var SIZE:int = 470;
private var loaderA:Loader;
private var loaderB:Loader;
private var bitmap:Bitmap;
private var stageW:int, stageH:int;
private var callBack: Function;
public function ImageLoader(gcallBack:Function) {
callBack=gcallBack;
init();
}
private static const URL:String = "http://www.textually.org/tv/archives/images/set3/Eu_flag_7.png" //"http://www.aanewsletter.ie/edition/5/img/european-union-flag.gif" //"http://www.lessabots.net/images/EU_Flag.jpg"
private function init():void
{
loaderA = new Loader();
loaderA.contentLoaderInfo.addEventListener(Event.INIT, initHandler);
loaderA.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, function():void { } );
loaderA.load(new URLRequest(URL), new LoaderContext(true));
}
private function initHandler(event:Event):void
{
loaderB = new Loader();
loaderB.contentLoaderInfo.addEventListener(Event.INIT, init2);
loaderB.loadBytes(loaderA.contentLoaderInfo.bytes);
}
private function init2(event:Event):void
{
var loader:Loader = event.currentTarget.loader;
stageW = stage.width;
stageH = stage.height;
//SIZE=stageH;
var scale:Number = 0;
if (loader.width < loader.height) scale = SIZE / loader.height;
else scale = SIZE / loader.height;
var bd:BitmapData = new BitmapData(scale * loader.width, scale * loader.height, false);
bd.draw(loader, new Matrix(scale,0,0,scale,-100,0));
if (bitmap) removeChild(bitmap);
bitmap = new Bitmap(bd);
this.addChild(bitmap);
callBack();
}
}
import flash.display.Sprite;
import flash.display.StageDisplayState;
import flash.events.Event;
import flash.events.FullScreenEvent;
import flash.events.MouseEvent;
// import flash.text.TextField;
// import flash.text.TextFieldAutoSize;
class FullScreenButton extends Sprite
{
// private var textField:TextField;
private var button:Sprite;
private var margin:Number = 10;
public function FullScreenButton():void
{
addEventListener(Event.ADDED_TO_STAGE, setup);
}
private function setup(event:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE, setup);
createFullScreenButton();
/* textField = new TextField();
textField.textColor = 0xffffff
textField.autoSize = TextFieldAutoSize.LEFT;
textField.text = "FullScreenEvent";
textField.selectable = false;
textField.alpha = 0;
stage.addChild(textField);*/
stage.addEventListener(FullScreenEvent.FULL_SCREEN, fullScreenEventHandler);
}
private function createFullScreenButton():void
{
button = new Sprite();
button.graphics.beginFill(0xf4f4f4);
button.graphics.lineStyle(1, 0xb1b1b1);
button.graphics.drawRect(0, 0, 34, 24);
button.graphics.lineStyle();
button.graphics.beginFill(0x4d4d4d);
button.graphics.drawRoundRect(7, 5, 21, 14, 3);
button.graphics.beginFill(0xc1c1c1);
button.graphics.drawRoundRect(8, 6, 10, 6, 2);
button.graphics.endFill();
button.x = stage.stageWidth - button.width - margin;
button.y = stage.stageHeight - button.height - margin;
button.buttonMode = true;
button.addEventListener(MouseEvent.CLICK, function():void
{
if (stage.displayState == StageDisplayState.NORMAL){
visible=false;
stage.displayState = StageDisplayState.FULL_SCREEN;
}
else {
visible=true;
stage.displayState = StageDisplayState.NORMAL;
}
});
addChild(button);
}
public function resize():void
{
button.x = stage.stageWidth - button.width - margin;
button.y = stage.stageHeight - button.height - margin;
}
private function fullScreenEventHandler(event:FullScreenEvent):void
{
if (event.fullScreen)
{
// textField.alpha = 1;
}
else
{
// textField.alpha = 0;
}
}
}