FP10 3D Test 001
...
@author DefaultUser (Tools -> Custom Arguments...)
package
{
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.display.Sprite;
import flash.geom.Point;
import flash.text.TextField;
import flash.net.URLLoader;
import flash.net.URLLoaderDataFormat;
import flash.net.URLRequest;
import flash.text.TextFormat;
import flash.utils.Timer;
import flash.utils.getTimer;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.events.KeyboardEvent;
import flash.events.ProgressEvent;
import flash.system.Security;
[SWF(width="465", height="465", backgroundColor="0xaaaa00", frameRate="0")]
/**
* ...
* @author DefaultUser (Tools -> Custom Arguments...)
*/
public class CharCircle extends Sprite
{
private var _timer:Timer;
private var _frameRate:int = 24;
private var _t:int;
private var _chars:String;
private var _urlLoader:URLLoader;
private var _output:TextField;
private var sp:Sprite;
public function CharCircle()
{
Security.loadPolicyFile('http://www.matzmtok.com/wonderful/crossdomain.xml');
_timer = new Timer(1000 / _frameRate);
_timer.addEventListener(TimerEvent.TIMER, timerHandler);
addEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
_output = new TextField();
_output.x = 10;
_output.y = 10;
_output.width = stage.stageWidth - 10;
_output.height = stage.stageHeight - 10;
addChild(_output);
}
private function print(str:String):void {
_output.appendText(str+"\n");
}
private function addedToStageHandler(e:Event):void
{
print("Added to Stage");
removeEventListener(e.type, arguments.callee);
var req:URLRequest = new URLRequest("http://www.matzmtok.com/wonderfl/font_loader.swf");
_urlLoader = new URLLoader();
_urlLoader.addEventListener(ProgressEvent.PROGRESS, progressHandler);
_urlLoader.addEventListener(Event.OPEN, openHandler);
_urlLoader.addEventListener(Event.COMPLETE, completeHandler);
_urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
_urlLoader.load(req);
}
private function openHandler(e:Event):void
{
print("Loading Start");
}
private function progressHandler(e:ProgressEvent):void
{
var p:Number = Math.round(100 * e.bytesLoaded / e.bytesTotal);
print("Progress " + p + "Loaded");
}
private function completeHandler(e:Event):void
{
print("Font Loader Loaded");
var urlloader:URLLoader = e.target as URLLoader;
var loader:Loader = new Loader();
var info:LoaderInfo;
var cls:Class;
var fl:*;
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(event:Event):void {
info = event.target as LoaderInfo;
cls = info.applicationDomain.getDefinition("ru.etcs.utils.FontLoader") as Class;
if (cls) {
fl = new cls();
fl.load(new URLRequest("http://www.matzmtok.com/wonderfl/fonts.swf"));
fl.addEventListener(Event.COMPLETE, fontLoadCompleteHandler);
}
});
loader.loadBytes(urlloader.data);
}
private function fontLoadCompleteHandler(e:Event):void
{
print("Font Loaded");
init();
}
private function init():void
{
_chars = "abcdefghijklmnopqrstuvwxyz" +
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
"1234567890-^\\" +
"!\"#$%&'()=~|@[`{;:]+*},./<>?_";
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
_timer.start();
_t = getTimer();
var r:Number = 200;
var th:Number;
var cs:CharSprite;
var p:Point = new Point(stage.stageWidth * 0.5, stage.stageHeight * 0.5);
sp = new Sprite();
sp.x = p.x;
sp.y = p.y;
addChild(sp);
for (var i:int = 0; i < 36; i++) {
th = 2 * Math.PI * i / 36;
cs = new CharSprite();
cs.x = r * Math.cos(th);
cs.z = r * Math.sin(th);
cs.tf.text = "a";
cs.color = 0xff0000 | Math.round(255 * i / 36) << 8;
sp.addChild(cs);
}
}
private function timerHandler(e:TimerEvent):void
{
sp.rotationY += 0.5;
sp.rotationZ += 1.0;
sp.rotationX += 1.5;
stage.invalidate();
}
private function keyDownHandler(e:KeyboardEvent):void
{
trace(e.charCode, String.fromCharCode(e.charCode));
}
}
}
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;
class CharSprite extends Sprite {
public var tf:TextField;
public function CharSprite() {
super();
tf = new TextField();
tf.defaultTextFormat = new TextFormat("oxygene", 30, 0x00cccc, null, null, null, null, null, TextFormatAlign.CENTER);
tf.x = -tf.width * 0.5;
tf.y = -tf.height * 0.5;
tf.embedFonts = true;
addChild(tf);
}
public function get color():uint {
return uint(tf.defaultTextFormat.color);
}
public function set color(value:uint):void {
var f:TextFormat = tf.defaultTextFormat;
f.color = value;
tf.setTextFormat(f);
}
}