fileload and multitouch checker
...
@author umhr
/**
* Copyright umhr ( http://wonderfl.net/user/umhr )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/9oRo
*/
package
{
import flash.display.Sprite;
import flash.events.Event;
/**
* ...
* @author umhr
*/
[SWF(width = 465, height = 465, backgroundColor = 0x000000, frameRate = 60)]
public class WonderflMain extends Sprite
{
public function WonderflMain()
{
init();
}
private function init():void
{
if (stage) onInit();
else addEventListener(Event.ADDED_TO_STAGE, onInit);
}
private function onInit(event:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, onInit);
// entry point
stage.scaleMode = "noScale";
stage.align = "TL";
//stage.displayState = "fullScreen";
addChild(new Canvas());
}
}
}
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
import net.hires.debug.Stats;
/**
* ...
* @author umhr
*/
class Canvas extends Sprite
{
private var _shape:Shape = new Shape();
public function Canvas()
{
init();
}
private function init():void
{
if (stage) onInit();
else addEventListener(Event.ADDED_TO_STAGE, onInit);
}
private function onInit(event:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, onInit);
// entry point
addChild(new Photo());
addChild(new FontClock());
addChild(new Stats());
addChild(new MultiTouchChecker());
}
}
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.filters.DropShadowFilter;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Loader;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.system.LoaderContext;
import flash.system.Security;
class Photo extends Sprite {
private var _credit:TextField = new TextField();
public function Photo() {
init();
}
private function init():void
{
if (stage) onInit();
else addEventListener(Event.ADDED_TO_STAGE, onInit);
}
private function onInit(event:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, onInit);
// entry point
//検索結果のロード
var myURLLoader:URLLoader = new URLLoader();
myURLLoader.addEventListener(Event.COMPLETE, onCompleteXML);
var random:int = Math.random() * 20 + 1;
//var imgmax:int = Math.max(stage.stageWidth, stage.stageHeight);
var xmlURL:String = "http://photos.googleapis.com/data/feed/base/all?alt=rss&isVideo=false&kind=photo&q=sea&imglic=commercial&max-results=3&imgmax=1024&start-index=" + random;
//crossdomain.xml(クロスドメインポリシーファイル)の位置を指定
Security.loadPolicyFile("http://photos.googleapis.com/data/crossdomain.xml"); //*1
myURLLoader.load(new URLRequest(xmlURL));
}
private function onCompleteXML(e:Event):void {
//取得したデータをXML型にする。
var myXML:XML = new XML(e.currentTarget.data); //*2
//XMLを解析
var titleStr:String = myXML.channel.item[0].title; //*3
var linkURL:String = myXML.channel.item[0].link; //*4
//namespaceを設定
default xml namespace = new Namespace("http://search.yahoo.com/mrss/"); //*5
var creditStr:String = myXML.channel.item[0].group.credit; //*6
var imgURL:String = myXML.channel.item[0].group.content.@url; //*7
_credit.autoSize = TextFieldAutoSize.LEFT;
_credit.width = 300;
//_credit.x = 50;
//_credit.y = 50;
_credit.multiline = true;
_credit.text = "Photo by:" + creditStr;
_credit.textColor = 0xFFFFFF;
_credit.background = true;
_credit.backgroundColor = 0x000000;
_credit.visible = false;
addChild(_credit);
//画像のロード
var myLoader:Loader = new Loader();
var myURLRequest:URLRequest = new URLRequest(imgURL);
//クロスドメインポリシーファイルをドキュメントルートから取得
var myLoaderContext:LoaderContext = new LoaderContext(true); //*8
myLoader.load(myURLRequest, myLoaderContext);
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteImg);
}
private function onCompleteImg(event:Event):void {
var myBitmap:Bitmap = event.target.content;
myBitmap.smoothing = true;
var scale:Number = Math.max(stage.stageWidth / myBitmap.width, stage.stageHeight / myBitmap.height);
myBitmap.scaleX = myBitmap.scaleY = scale;
addChildAt(myBitmap, 0);
_credit.x = stage.stageWidth - _credit.width;
_credit.y = stage.stageHeight - _credit.height;
_credit.visible = true;
}
}
import flash.display.Sprite;
import flash.events.TimerEvent;
import flash.text.Font;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.utils.Timer;
/**
* ...
* @author umhr
*/
[SWF(backgroundColor="0xFDFAF9")]
class FontClock extends Sprite {
private var fonts:Array;
public function FontClock():void {
//fontのリストを取得
fonts = Font.enumerateFonts(true);
//1秒に一度onTimerを呼び出す。
var timer:Timer = new Timer(1000,0);
timer.addEventListener(TimerEvent.TIMER,onTimer);
timer.start();
this.mouseEnabled = false;
}
private function onTimer(e:TimerEvent):void{
while (this.numChildren > 0) {
this.removeChildAt(0);
}
var canvasYMD:Sprite = new Sprite();
var canvasTime:Sprite = new Sprite();
//時刻を取得
var date:Date = new Date();
var times:Array = [String(date.getFullYear()),"/",String(date.getMonth()+1),"/",String(date.getDate()),String(date.getHours()),":",String(date.getMinutes()),".",String(date.getSeconds())];
//ランダムを使って、フォントを設定。
for (var i:int = 0; i < times.length; i++) {
var tf:TextField = new TextField();
tf.text = times[i];
var fontNumber:int = Math.floor(fonts.length * Math.random());
tf.selectable = false;
tf.textColor = 0xFFFFFF;
if(i < 5){
tf.setTextFormat(new TextFormat(fonts[fontNumber].fontName, 21));
tf.autoSize = "right";
tf.x = canvasYMD.width;
canvasYMD.addChild(tf);
}else {
tf.setTextFormat(new TextFormat(fonts[fontNumber].fontName, 68));
tf.autoSize = "right";
tf.x = canvasTime.width;
tf.y = canvasYMD.height;
canvasTime.addChild(tf);
}
}
canvasYMD.x = (canvasTime.width - canvasYMD.width) / 2;
canvasTime.addChild(canvasYMD);
//画面真ん中に
canvasTime.x = (stage.stageWidth-canvasTime.width)/2;
canvasTime.y = (stage.stageHeight-canvasTime.height)/2;
this.addChild(canvasTime);
}
}
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.TouchEvent;
import flash.text.TextField;
import flash.ui.Mouse;
import flash.ui.Multitouch;
import flash.ui.MultitouchInputMode;
/**
* ...
* @author umhr
*/
class MultiTouchChecker extends Sprite
{
private var _shapeList:Vector.<Shape> = new Vector.<Shape>();
private var _textField:TextField = new TextField();
public function MultiTouchChecker()
{
init();
}
private function init():void
{
if (stage) onInit();
else addEventListener(Event.ADDED_TO_STAGE, onInit);
}
private function onInit(event:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, onInit);
// entry point
Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
var text:String = "";
text += "maxTouchPoints:" + Multitouch.maxTouchPoints;
text += "\n" + "supportedGestures:" + Multitouch.supportedGestures;
text += "\n" + "supportsGestureEvents:" + Multitouch.supportsGestureEvents;
text += "\n" + "supportsTouchEvents:" + Multitouch.supportsTouchEvents;
_textField.width = 400;
_textField.background = true;
_textField.backgroundColor = 0xFFFFFF;
_textField.selectable = false;
_textField.text = text;
_textField.autoSize = "left";
_textField.y = stage.stageHeight - _textField.height;
addChild(_textField);
stage.addEventListener(TouchEvent.TOUCH_MOVE, stage_touchMove);
if(Multitouch.maxTouchPoints){
Mouse.hide();
var n:int = Multitouch.maxTouchPoints;
for (var i:int = 0; i < n; i++)
{
var shape:Shape = new Shape();
shape.graphics.beginFill(0xFFFFFF * Math.random(), 0.5);
shape.graphics.drawCircle(0, 0, 20);
shape.graphics.endFill();
shape.graphics.beginFill(0x666666, 0.5);
shape.graphics.drawCircle(0, 0, 15);
shape.graphics.endFill();
addChild(shape);
_shapeList[i] = shape;
}
}
}
private function stage_touchMove(event:TouchEvent):void
{
var shape:Shape = _shapeList[event.touchPointID % _shapeList.length];
shape.x = event.localX;
shape.y = event.localY;
}
}