Progression(3.0.7)をためしてみる。

umhr_progressionFlashのフレームワーク、Progression(3.0.7)をためしてみる。
1ASファイルで書いたので、wonderflにアップだ!と思ったら、Progression3には対応してないみたいでがっかり。

Get Adobe Flash player

ちょっと、まだProgressionだかららくらく開発!という域には行ってない。
SceneとPageの関係がいまいち理解し切れていない。
あと、たとえば得点データを管理する際に、どういうやりかたをするのがいいのか、とかがぜんぜん未整理。

[11/20追記]Progression4版作りました。

▼ActionScript AS3(FP9)
[sourcecode language=”as3″]
/*
* (ほぼ)初めてのProgression (3.07)
* なんとか形にはなったけど、へんなところ多いと思う。
* import何回すれば気が済むんだよ、とかw
* まだSceneとPageの関係がいまいちつかめてない。
*
* あと、2,3本作ればなじむのかな。
*
* クイズ内容は日ごろからためておくといいかも。
*
* */

package {
import flash.display.StageAlign;
import flash.display.StageQuality;
import flash.display.StageScaleMode;
import flash.text.TextField;
import jp.progression.casts.*;
import jp.progression.commands.*;
import jp.progression.core.debug.Verbose;
import jp.progression.events.*;
import jp.progression.loader.*;
import jp.progression.*;
import jp.progression.scenes.*;

public class Index extends CastDocument {
public var prog:Progression;
public function Index() {
}
/*======================================================================*//**
* SWF ファイルの読み込みが完了し、stage 及び loaderInfo にアクセス可能になった場合に送出されます。
*/
protected override function _onInit():void {
// stage の初期設定を行います。
align = StageAlign.TOP_LEFT;
quality = StageQuality.HIGH;
scaleMode = StageScaleMode.NO_SCALE;

// 開発者用の出力を有効化します。
//Verbose.enabled = true;
//Verbose.filteringCommand();

addBackground();

// Progression インスタンスを作成します。
prog = new Progression( "index", stage, IndexScene );

// ブラウザ再生時に URL 同期を有効化します。
//prog.sync = true;

// 最初のシーンに移動します。
prog.goto( prog.firstSceneId );

// IndexButton を作成します。
var indexButton:IndexButton = new IndexButton();
indexButton.x = 8;
addChild( indexButton );
}
private function addBackground():void {
graphics.beginFill(0xDDDDDD);
graphics.drawRoundRect(8, 18, 465 – 16, 465 – 26, 16);
graphics.endFill();
graphics.beginFill(0xEEEEEE);
graphics.drawRect(40, 50, 385, 375);
graphics.endFill();
}
}
}

import flash.display.SimpleButton;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.text.TextFormat;
import jp.progression.casts.*;
import jp.progression.commands.*;
import jp.progression.events.*;
import jp.progression.loader.*;
import jp.progression.*;
import jp.progression.scenes.*;

class FeatureButton extends CastButton {
public function FeatureButton( initObject:Object = null ) {
super( initObject );
var sb:SimpleButton = Create.newSimpleButton( { text:"Start!" } );
addChild(sb);
// クリック時の移動先を設定する
sceneId = new SceneId( "/index/feature/Q0" );
}
protected override function _onCastMouseDown():void {
addCommand();
}
protected override function _onCastMouseUp():void {
addCommand();
}
protected override function _onCastRollOver():void {
addCommand();
}
protected override function _onCastRollOut():void {
addCommand();
}
}
///////////////////////
///////////////////////
import jp.progression.casts.*;
import jp.progression.commands.*;
import jp.progression.events.*;
import jp.progression.loader.*;
import jp.progression.*;
import jp.progression.scenes.*;
class QScene extends SceneObject {
public var page:QPage;
public function QScene(obj:Object,onClick:Function) {
page = new QPage(null, obj);
page.name = obj.name;
page.addEventListener(MouseEvent.CLICK, click);
function click(e:MouseEvent):void {
page.maru = Boolean(e.target.name == "true");
onClick(e);
}
}
protected override function _onLoad():void {
addCommand();
}
protected override function _onInit():void {
// ページを画面に表示します。
addCommand(new AddChild( progression.container, page ));
}
protected override function _onGoto():void {
addCommand(new RemoveChild( progression.container, page ));
}
protected override function _onUnload():void {
addCommand();
}
}
////////////////
import flash.text.TextField;
import jp.progression.casts.*;
import jp.progression.commands.*;
import jp.progression.events.*;
import jp.progression.loader.*;
import jp.progression.*;
import jp.progression.scenes.*;
class QPage extends CastSprite {
private var _kekka:Sprite;
public function QPage( initObject:Object = null,obj:Object = null) {
super( initObject );
var sp:Sprite = new Sprite();
var tf:TextField = new TextField();
//tf.text = obj.title;
tf.defaultTextFormat = new TextFormat("_sans",14);
tf.htmlText = obj.title;
tf.autoSize = "left";
tf.y = 100;
sp.addChild(tf);
var shuffle_ar:Array = shuffle(obj.q.length);
for (var i:int = 0; i < obj.q.length; i++) {
var j:int = shuffle_ar[i];
var qt:SimpleButton = Create.newSimpleButton( { text:obj.q[j] } );
qt.name = String(j == obj.a);
qt.y = 150 + i * 50;
sp.addChild(qt);
}
sp.x = (465 – sp.width) / 2;
_kekka = new Sprite();
this.addChild(sp);
}
private function shuffle(_n:int):Array {
var _array:Array = new Array();
for (var i:int= 0; i<_n; i++){
_array[i] = Math.random();
}
return _array.sort(Array.RETURNINDEXEDARRAY);
}
public var maru:Boolean;
protected override function _onCastAdded():void {
maru = false;
_kekka.graphics.clear();
while (_kekka.numChildren > 0) {
_kekka.removeChildAt(0);
}
alpha = 0;
x = 200;
addCommand(
new DoTweener( this, { alpha:1, x:0, time:0.2 , transition:"easeOutCubic" } )
);
}
protected override function _onCastRemoved():void {
var tf:TextField = new TextField();
tf.defaultTextFormat = new TextFormat(null, 36, 0xFF0000);
tf.text = String(maru);
tf.autoSize = "center";
tf.x = (465 – tf.width) / 2;
tf.y = (465 – tf.height) / 2;
_kekka.addChild(tf);
if (maru) {
_kekka.graphics.lineStyle(24, 0xFF0000);
_kekka.graphics.drawCircle(465 / 2, 465 / 2, 100);
}else {
_kekka.graphics.lineStyle(24, 0xFF);
_kekka.graphics.moveTo(165, 165);
_kekka.graphics.lineTo(300, 300);
_kekka.graphics.endFill();
_kekka.graphics.moveTo(165, 300);
_kekka.graphics.lineTo(300, 165);
_kekka.graphics.endFill();
}
_kekka.alpha = 0;
this.addChild(_kekka);

addCommand(
new DoTweener( _kekka, { alpha:1, time:0.2 , transition:"easeInCubic" } ),
new DoTweener( this, { alpha:0, x: -200, time:0.2 , transition:"easeInCubic" } )
);
}
}

///////////////////////
import jp.progression.casts.*;
import jp.progression.commands.*;
import jp.progression.events.*;
import jp.progression.loader.*;
import jp.progression.*;
import jp.progression.scenes.*;
class AnnouncementScene extends SceneObject {
public var page:AnnouncementPage;
public function AnnouncementScene() {
page = new AnnouncementPage();
page.addEventListener(MouseEvent.CLICK, onClick);
}
public function setScore(n:Number):void {
page.setScore(n);
//trace(n,n,n)
}
private function onClick(e:MouseEvent):void {
progression.goto(new SceneId( "/index" ));
}
protected override function _onInit():void {
addCommand(new AddChild( progression.container, page ));
}
protected override function _onGoto():void {
addCommand(new RemoveChild( progression.container, page ));
}
}
////////////////
import jp.progression.casts.*;
import jp.progression.commands.*;
import jp.progression.events.*;
import jp.progression.loader.*;
import jp.progression.*;
import jp.progression.scenes.*;
class AnnouncementPage extends CastSprite {
private var tf:TextField;
public function AnnouncementPage( initObject:Object = null ) {
super( initObject );
graphics.beginFill(0x333333);
graphics.drawRect(50, 60, 365, 355);
graphics.endFill();
tf = new TextField();
tf.defaultTextFormat = new TextFormat("_sans",14);
tf.textColor = 0xFFFFFF;
tf.selectable = false;
this.addChild(tf);
}
public function setScore(n:Number):void {
tf.text = "お疲れ様でした。\nあなたの正答率は " + n*100 + "% です。\nこれからも勉強しましょう!";
tf.autoSize = "center";
tf.x = (465 – tf.width) / 2;
tf.y = (465 – tf.height) / 2 – 20;
}
protected override function _onCastAdded():void {
tf.visible = true;
y = 0;
alpha = 0;
addCommand(new DoTweener( this, { alpha:1, time:0.5 } ));
}
protected override function _onCastRemoved():void {
addCommand(
new DoTweener( tf, { visible:false, delay:0.5 } ),
new DoTweener( this, { alpha:0, time:0.5 } )
);
}
}
///////////////////////
import jp.progression.casts.*;
import jp.progression.commands.*;
import jp.progression.events.*;
import jp.progression.loader.*;
import jp.progression.*;
import jp.progression.scenes.*;
class FeatureScene extends SceneObject {
public var page:FeaturePage;
private var announcement:AnnouncementScene;
private var score:int;
private var question_array:Array;
public function FeatureScene() {
page = new FeaturePage();

question_array = [];
question_array.push( { q:["addChildIndex", "setChildIndex", "getChildIndex", "areInaccessibleObjectsUnderPoint"], a:0, name:"", title:"DisplayObjectContainerに\n存在<b>しない</b>のはどれ?" } );
question_array.push( { q:["clear", "append", "prependRotation", "transpose"], a:0, name:"", title:"Matrix3Dに存在<b>しない</b>のはどれ?" } );
question_array.push( { q:["FLVLoaderContext", "DigitWidth", "TabStop", "StaticText"], a:0, name:"", title:"AS3.0にビルトインで存在<b>しない</b>\nクラスはどれ?" } );
question_array.push( { q:["Blend", "CSMSettings", "CFFHinting", "AVM1Movie"], a:0, name:"", title:"AS3.0にビルトインで存在<b>しない</b>\nクラスはどれ?" } );
question_array.push( { q:["Flash Player 9.0.18.60", "Flash Player 9.0.28.0", "Flash Player 9.0.45.0", "Flash Player 9.0.115.0"], a:0, name:"", title:"フルスクリーンモードに\n対応<b>した</b>のはどのバージョンから?" } );
question_array.push( { q:["FlashLite3.1", "Flash Player 8.5", "FlexBuilder 2", "Flash Catalyst"], a:0, name:"", title:"AS3.0に<b>対応してない</b>のはどれ?" } );
question_array.push( { q:["Math.strong(12,5)", "Math.random()*5", "Math.min(10.0,-2)", "Math.atan2(45,12)"], a:0, name:"", title:"AS3.0のMathの使い方で<b>間違っている</b>のはどれ?" } );
question_array.push( { q:["6", "7", "8", "June"], a:0, name:"", title:"Date.getMonth()で7月の\n返り値として得られるのはどれ?" } );
question_array.push( { q:["&gt;", "&lt;", "&amp;", "&nbsp;"], a:0, name:"", title:"文字実体参照で「>」を表すのはどれ?" } );
question_array.push( { q:["Math.ceil(1.4) == 2", "Math.floor(-1.4) == -1", "-0.4>>0 == -1", "Math.round(1.4) == 2"], a:0, name:"", title:"trueになるのはどれ?" } );
question_array.push( { q:["int(2) === Number(2)", "new Object() == new Object()", "new String() == null", "new Boolean() === ”"], a:0, name:"", title:"trueになるのはどれ?" } );
question_array.push( { q:["定義上の値の範囲は0以上1未満である", "Math.random(-1)でマイナスの値が得られる", "小数点7桁目は必ず偶数である", "パブリッシュ後は再生のたびに同じ乱数が得られる"], a:0, name:"", title:"Math.random()の説明で\nもっとも適切なのはどれ?" } );
question_array.push( { q:["TextBlock", "TextField", "TextArea", "TextBox"], a:0, name:"", title:"Flash Player 10から追加されたのはどのクラス?" } );
question_array.push( { q:["16進数", "2進数", "8進数", "10進数"], a:0, name:"", title:"「0xFF0000」は何進数の表現?" } );
question_array.push( { q:["SimpleButton", "Sprite", "Stage", "Loader"], a:0, name:"", title:"DisplayObjectContainerを継承してないのはどれ?" } );
question_array.push( { q:["private", "public", "internal", "final"], a:0, name:"", title:"クラス属性<b>でない</b>ものはどれ?" } );
question_array.push( { q:["internal", "public", "private", "protected"], a:0, name:"", title:"「同じパッケージ内でのみ参照できるメンバー」\nの属性を表すものはどれ?" } );
question_array.push( { q:["addEventListener", "addEventListenar", "addEventLissentener", "addEventLisner"], a:0, name:"", title:"正しいのはどれ?" } );
question_array.push( { q:["stage.mouseX", "Stage.stageMouseX", "stage._xmouse", "stage.stageMouseX"], a:0, name:"", title:"ステージ上のマウスのx座標を得るのに\n適切なのはのはどれ?" } );
question_array.push( { q:["stage.stageWidth", "Stage.width", "stage._width", "stage.width"], a:0, name:"", title:"ステージの幅を得るのに\n適切なのはのはどれ?" } );
question_array.push( { q:["obj.eval(‘foo’)", "obj[‘foo’]", "obj.foo", "obj[‘fo’+’o’]"], a:0, name:"", title:"Objectの連想配列へのアクセスの\n仕方で不適切なのはどれ?" } );
question_array.push( { q:["_array.length", "_array.length()", "_array.numChildren", "_array.numChildren()"], a:0, name:"", title:"配列(_array)内のエレメント数を示すのはどれ?" } );
question_array.push( { q:["_xml.length()", "_xml.length", "_xml.numChildren", "_xml.numChildren()"], a:0, name:"", title:"XMLオブジェクト(_xml)内のエレメント数を示すのはどれ?" } );
question_array.push( { q:["_sp.numChildren", "_sp.length()", "_sp.length", "_sp.numChildren()"], a:0, name:"", title:"Sprite(_sp)に内包する\nディスプレイオブジェクトの数を示すのはどれ?" } );
question_array.push( { q:["_array.pop()", "_array.shift()", "_array.push()", "_array.slice()"], a:0, name:"", title:"配列(_array)の最後のエレメントを削除して、\nそのエレメントの値を返すのはどれ?" } );
question_array.push( { q:["Vector", "Rectangle", "Vector3D", "Matrix3D"], a:0, name:"", title:"「すべてのエレメントが同じデータ型を持つ配列」\nという説明が最も適切なのはどれ?" } );
question_array.push( { q:["&&", "||", "!", "%="], a:0, name:"", title:"理論積の演算子はどれ?" } );
question_array.push( { q:["userName", "isDebugger", "playerType", "os"], a:0, name:"", title:"Capabilitiesクラスに\n存在<b>しない</b>プロパティはどれ?" } );
question_array.push( { q:["塗りつぶしツール", "バケツツール", "なげなわツール", "矩形ツール"], a:0, name:"", title:"Flash CS4のツールウィンドウ上に\n存在<b>しない</b>のはどれ?" } );
question_array.push( { q:["Stage", "Function", "QName", "Object"], a:0, name:"", title:"AS3.0にトップレベルクラス<b>ではない</b>\nのはどれ?" } );
trace("設問数:", question_array.length);
}
public function setScene():void {
removeAllScenes();
var shuffle_ar:Array = shuffle(question_array.length);
for (var i:int = 0; i < 10; i++) {
var j:int = shuffle_ar[i];
question_array[j].name = "Q" + i;
var scene:QScene = new QScene(question_array[j], onClick);
scene.name = "Q" + i;
addScene(scene);
}

announcement = new AnnouncementScene();
announcement.name = "announcement";
addScene(announcement);
}
private function shuffle(_n:int):Array {
var _array:Array = new Array();
for (var i:int= 0; i<_n; i++){
_array[i] = Math.random();
}
return _array.sort(Array.RETURNINDEXEDARRAY);
}
private function onClick(e:MouseEvent):void {
if (e.target.name == "true") {
score ++;
}

if (e.currentTarget.name && e.currentTarget.name.substr(0, 1) == "Q" && int(e.currentTarget.name.substr(1)) < 9) {
var num:int = int(e.currentTarget.name.substr(1));
progression.goto(new SceneId( "/index/feature/Q" + String(num+1) ));
}else {
announcement.setScore(score / 10);
score = 0;
progression.goto(new SceneId( "/index/feature/announcement" ));
}
}
protected override function _onInit():void {
trace("onInt");
addCommand(new AddChild( progression.container, page ));
}
protected override function _onGoto():void {
trace("onGoto")
addCommand(new RemoveChild( progression.container, page ));
}
}
////////////////
import jp.progression.casts.*;
import jp.progression.commands.*;
import jp.progression.events.*;
import jp.progression.loader.*;
import jp.progression.*;
import jp.progression.scenes.*;
class FeaturePage extends CastSprite {
public function FeaturePage( initObject:Object = null ) {
super( initObject );
}
protected override function _onCastAdded():void {
alpha = 0;
addCommand(new DoTweener( this, { alpha:1, time:0.5 } ));
}
protected override function _onCastRemoved():void {
addCommand(new DoTweener( this, { alpha:0, time:0.5 } ));
}
}
////////////////
import jp.progression.casts.CastButton;
import jp.progression.scenes.SceneId;
class IndexButton extends CastButton {
public function IndexButton( initObject:Object = null ) {
super( initObject );
var tf:TextField = new TextField();
tf.text = "ActionScript Quiz";
tf.textColor = 0xFFFFFF;
tf.selectable = false;
this.addChild(tf);
// クリック時の移動先を設定する
sceneId = new SceneId( "/index" );
}
}
/////////////////
import jp.progression.casts.*;
import jp.progression.commands.*;
import jp.progression.events.*;
import jp.progression.loader.*;
import jp.progression.*;
import jp.progression.scenes.*;
class IndexScene extends SceneObject {
public var page:IndexPage;
private var feature:FeatureScene;
public function IndexScene() {
// FeatureScene を作成します。
feature = new FeatureScene();
feature.name = "feature";
addScene( feature );

page = new IndexPage();
}
/*======================================================================*//**
* シーン移動時に目的地がシーンオブジェクト自身もしくは子階層だった場合に、階層が変更された瞬間に送出されます。
* このイベント処理の実行中には、addCommand() メソッド、及び insertCommand() メソッドによるコマンドの同期処理が行えます。
*/
protected override function _onLoad():void {
//trace("0");
addCommand();
}
/*======================================================================*//**
* シーンオブジェクトが目的地だった場合に、到達した瞬間に送出されます。
* このイベント処理の実行中には、addCommand() メソッド、及び insertCommand() メソッドによるコマンドの同期処理が行えます。
*/
protected override function _onInit():void {
//trace("1");
feature.setScene();
addCommand(
// ページを画面に表示します。
new AddChild( progression.container, page )
);
}
/*======================================================================*//**
* シーンオブジェクトが出発地だった場合に、移動を開始した瞬間に送出されます。
* このイベント処理の実行中には、addCommand() メソッド、及び insertCommand() メソッドによるコマンドの同期処理が行えます。
*/
protected override function _onGoto():void {
//trace("2");
addCommand(
// ページを画面から削除します。
new RemoveChild( progression.container, page )
);
}
/*======================================================================*//**
* シーン移動時に目的地がシーンオブジェクト自身もしくは親階層だった場合に、階層が変更された瞬間に送出されます。
* このイベント処理の実行中には、addCommand() メソッド、及び insertCommand() メソッドによるコマンドの同期処理が行えます。
*/
protected override function _onUnload():void {
// 実行したいコマンドを登録します。
addCommand();
}
}
//////////////////////
import jp.progression.casts.*;
import jp.progression.commands.*;
import jp.progression.events.*;
import jp.progression.loader.*;
import jp.progression.*;
import jp.progression.scenes.*;
class IndexPage extends CastSprite {
public function IndexPage( initObject:Object = null ) {
super( initObject );
var tf:TextField = new TextField();
tf.defaultTextFormat = new TextFormat("_sans",14);
tf.text = "やあみんな、ActionScript Quizの時間だよ!\n何問正解できるかな?";
tf.autoSize = "center";
tf.x = (465 – tf.width) / 2;
tf.y = (465 – tf.height) / 2 – 50;
this.addChild(tf);

var featureButton:FeatureButton = new FeatureButton();
featureButton.x = 200;
featureButton.y = 240;
addChild( featureButton );
}
protected override function _onCastAdded():void {
alpha = 0;
addCommand(
new DoTweener( this, { alpha:1, time:0.5 } )
);
}
protected override function _onCastRemoved():void {
addCommand(
new DoTweener( this, { alpha:0, time:0.5 } )
);
}
}
//////////////////////
//////////////////////
//////////////////////
import flash.display.DisplayObject;
import flash.display.Graphics;
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.text.TextFormat;
import flash.display.Sprite;
import flash.display.Shape;
import flash.display.SimpleButton;
import flash.display.BitmapData;
import flash.display.Bitmap;

class Create{
public static var defaultTextFormat:TextFormat = new TextFormat();

public static function newSimpleButton(… args):SimpleButton {

var propObj:Object = { x:0, y:0, width:0, height:0, color:0xFF0000, alpha:1, round:0, lineSize:0, lineColor:0, lineAlpha:1, ellipseWidth:0, ellipseHeight:0, text:"" };

if(args){
for (var i:int = 0; i < args.length; i++) {
for (var str:String in args[i]) {
propObj[str] = args[i][str];
}
}
}

if (propObj.text) {
var tf:TextField = newTextField( { y:2, text:propObj.text, setTextFormat:[ { font:"_sans", align:"center" } ], autoSize:"center" } );
}

if (!(propObj.width)) {
propObj.width = tf.width + 16;
}
if (!(propObj.height)) {
propObj.height = tf.height + 4;
}

var upState:Sprite = newSprite( { x:propObj.x, y:propObj.y }, drawRect( { color:0xCCCCCC, width:propObj.width, height:propObj.height, round:8 } ) );
upState.addChild(newShape( { x:2, y:2 }, drawRect( { color:0xE5E5E5, width:propObj.width – 4, height:propObj.height – 4, round:6 } )));
var overState:Sprite = newSprite( { x:propObj.x, y:propObj.y }, drawRect( { color:0xBBBBBB, width:propObj.width, height:propObj.height, round:8 } ));
overState.addChild(newShape( { x:2, y:2 }, drawRect( { color:0xEEEEEE, width:propObj.width – 4, height:propObj.height – 4, round:6 } )));
var downState:Sprite = newSprite( { x:propObj.x, y:propObj.y }, drawRect( { color:0xAAAAAA, width:propObj.width, height:propObj.height, round:8 } ));
downState.addChild(newShape( { x:2, y:2 }, drawRect( { color:0xDDDDDD, width:propObj.width – 4, height:propObj.height – 4, round:6 } )));
var hitTestState:Shape = newShape( { x:propObj.x, y:propObj.y }, drawRect( { width:propObj.width, height:propObj.height, round:8 } ));
if (propObj.text) {
upState.addChild(newTextField({y:2,width:propObj.width,height:propObj.height-2,text:propObj.text,setTextFormat:[{font:"_sans",align:"center"}]}));
overState.addChild(newTextField({y:2,width:propObj.width,height:propObj.height-2,text:propObj.text,setTextFormat:[{font:"_sans",align:"center"}]}));
downState.addChild(newTextField({y:3,width:propObj.width,height:propObj.height-3,text:propObj.text,setTextFormat:[{font:"_sans",align:"center"}]}));
}
var sb:SimpleButton = new SimpleButton(upState, overState, downState, hitTestState);

return sb;
}

public static function drawRect(… args):Object {
var propObj:Object = { x:0, y:0, width:100, height:100, color:0xFF0000, alpha:1, round:0, lineSize:0, lineColor:0, lineAlpha:1, ellipseWidth:0, ellipseHeight:0 };

if(args){
for (var i:int = 0; i < args.length; i++) {
for (var str:String in args[i]) {
propObj[str] = args[i][str];
}
}
}
if(!(propObj.ellipseWidth)){
propObj.ellipseWidth = propObj.round;
}
if(!(propObj.ellipseHeight)){
propObj.ellipseHeight = propObj.ellipseWidth;
}

var resultArray:Array = [];
resultArray.push({ beginFill:[propObj.color, propObj.alpha] });
if (propObj.lineSize > 0) {
resultArray.push( { lineStyle:[propObj.lineSize, propObj.lineColor, propObj.lineAlpha] } );
}
if(propObj.round || propObj.ellipseWidth || propObj.ellipseHeight){
resultArray.push( { drawRoundRect:[propObj.x, propObj.y, propObj.width, propObj.height, propObj.ellipseWidth, propObj.ellipseHeight] } );
}else {
resultArray.push( { drawRect:[propObj.x, propObj.y, propObj.width, propObj.height] } );
}
return { graphics:resultArray };
}
public static function drawCircle(… args):Object {
var propObj:Object = { x:0, y:0, width:0, height:0, color:0xFF0000, alpha:1, r:100, radius:0, lineSize:0, lineColor:0, lineAlpha:1 };

if(args){
for (var i:int = 0; i < args.length; i++) {
for (var str:String in args[i]) {
propObj[str] = args[i][str];
}
}
}
if(!(propObj.radius)){
propObj.radius = propObj.r;
}
if(!(propObj.width)){
propObj.width = propObj.radius;
}
if(!(propObj.height)){
propObj.height = propObj.radius;
}

var resultArray:Array = [];
resultArray.push({ beginFill:[propObj.color, propObj.alpha] });
if (propObj.lineSize > 0) {
resultArray.push( { lineStyle:[propObj.lineSize, propObj.lineColor, propObj.lineAlpha] } );
}
if (propObj.width == propObj.height) {
resultArray.push( { drawCircle:[propObj.x, propObj.y, propObj.radius] } );
}else {
resultArray.push( { drawEllipse:[propObj.x, propObj.y, propObj.width, propObj.height] } );
}

return { graphics:resultArray };
}

public static function newShape(… args):Shape {
var sp:Shape;
var str:String;
var length:int = args.length;
for (var i:int = 0; i < length; i++) {
var obj:Object = args[i];
if(i == 0){
if(obj.Shape){
sp = obj.Shape;
}else{
sp = new Shape();
}
}
if(obj.graphics){
for (var j:int = 0; j < obj.graphics.length; j++) {
if(obj.graphics[j]){
for (str in obj.graphics[j]) {
sp.graphics[str].apply(null, obj.graphics[j][str]);
}
}
}
}
for (str in obj) {
if(str != "Shape" && str != "graphics"){
sp[str] = obj[str];
}
}
}
return sp;
}
public static function newSprite(… args):Sprite {
var sp:Sprite;
var str:String;
var length:int = args.length;
for (var i:int = 0; i < length; i++) {
var obj:Object = args[i];
if(i == 0){
if(obj.Sprite){
sp = obj.Sprite;
}else{
sp = new Sprite();
}
}
if(obj.graphics){
for (var j:int = 0; j < obj.graphics.length; j++) {
if(obj.graphics[j]){
for (str in obj.graphics[j]) {
sp.graphics[str].apply(null, obj.graphics[j][str]);
}
}
}
}
for (str in obj) {
if(str != "Sprite" && str != "graphics" && str != "addChild"){
sp[str] = obj[str];
}
}
if(obj.addChild){
sp.addChild(obj.addChild);
}
}
return sp;
}
public static function newTextField(… args):TextField {
var ta:TextField = new TextField();
ta.defaultTextFormat = defaultTextFormat;
var length:int = args.length;
for (var i:int = 0; i < length; i++) {
var obj:Object = args[i];
for (var str:String in obj) {
if(str != "setTextFormat"){
ta[str] = obj[str];
}
}
if(obj.setTextFormat){
var format:TextFormat = new TextFormat();
if(obj.setTextFormat[0] is TextFormat){
format = obj.setTextFormat[0];
}else{
for (var tfstr:String in obj.setTextFormat[0]) {
format[tfstr] = obj.setTextFormat[0][tfstr];
}
}
ta.setTextFormat(format,isNaN(obj.setTextFormat[1])?-1:obj.setTextFormat[1],isNaN(obj.setTextFormat[2])?-1:obj.setTextFormat[2]);
}
}
return ta;
}

public static function newBitmap(… args):Bitmap {
var length:int = args.length;
var bd:BitmapData;
var bitmap:Bitmap;
var strObj:Object = { width:100 , height:100, transparent:true, fillColor:0xFFFFFFFF , pixelSnapping:"auto", smoothing:false ,x:0 ,y:0};

var tempDO:DisplayObject;
for (var i:int = 0; i < length; i++) {
var obj:Object = args[i];
for (var str:String in obj) {
if (str == "draw") {
tempDO = obj[str];
strObj.width = obj[str].width;
strObj.height = obj[str].height;
}else {
strObj[str] = obj[str];
}
}
}
bd = new BitmapData(strObj.width, strObj.height, strObj.transparent, strObj.fillColor);

if (tempDO) {
bd.draw(tempDO)
}
bitmap = new Bitmap(bd, strObj.pixelSnapping, strObj.smoothing);
bitmap.x = strObj.x;
bitmap.y = strObj.y;
return bitmap;
}
}

[/sourcecode]