HexGrid
Artificial Life simulator
/*
HexGrid Class
AS3
HexGrid Class is a test of multiple custom methods and classes
Future modifications
Make the map so it looks like a real map instead of the randomly placed hex type from the array
Make AI for weather
Make AI units that grow and spread over the map
Ver Mod Date
0.0 Created. used Polygon class for hexes Spring 2011
0.1 used gTween and Timer to fade in hexes
0.2 Create a dot in each hex, new color circle onRollOver/Out
0.3 Added ColorTransForm to change the color onRollOver...
Added dotColor for assignment of Color 18 April 2011
0.4 createLabel method 19 April
0.5 added switch statement to change colorDot 20 April
0.6 completed ColorTransform using hex.dotColor for mouseOver/Dn/Up
hex is a MovieClip, hexBG a Sprite 27 April 2011
0.7 accessing class's array for testing of access to each hex's arry
made ChildA/B/C
Editing errors 27 January 2016
Editing Hexes 1 February
*/
package
{
import flash.text.*;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.StageScaleMode;
import flash.events.*;
import flash.utils.*;
import flash.geom.*;
import flash.display.*;
//import TextFunctions;
public class HexGrid extends Sprite
{
public var tFX:TextFunctions = new TextFunctions();
public var gTwn:gTweens = new gTweens();
public static var XX:int = 99;
private var Name:String = "HexGrid";
public var critter:Critter;
public var critter1:Critter;
public var critter2:Critter;
private var curRow:int = 0;
private var curCol:int = 0;
private var tileSize:int = 30;
private var mapArray:Array = [];
private var sH:int;
private var sW:int;
private var mapTimer:Timer;
private var mapCol:int = 0;
private var mapRow:int = 0;
private var canvas:MovieClip = new MovieClip();
private var wildLife:MovieClip = new MovieClip();
private var display:MovieClip = new MovieClip();
private var hex0:Sprite;
private var hex:MovieClip = new MovieClip();
private var bezel:Sprite = new Sprite();
private var i:int = 0;
private var halfOffset:Boolean = false;
private var columnOffset:int = 0;
private var wid:Number;
private var hth:Number;
private var halfHt:Number;
private var hexesWide:int = 0;
private var hexesHigh:int = 0;
private var hexLabel:Sprite = new Sprite();
private var mapTypes:Array = ['valley', 'sea', 'field', 'praire', 'desert', 'ocean', 'swamp', 'shallows', 'forest', 'mountain', 'hills', 'lake', 'barren']
private var fmt:TextFormat = tFX.getFormat('black');
private var trans:ColorTransform = new ColorTransform();
private var itir:int = 0;
public var map:MovieClip;
public var mouseBoard:MovieClip;
public function HexGrid()
{
stage.scaleMode = StageScaleMode.NO_SCALE;
canvas.addChild(bezel);
fmt.size = 32;
fmt.bold = true;
this.addEventListener(Event.ADDED_TO_STAGE, init);
}
// PUBLIC FX:
private function init(e:Event):void
{
sH = stage.stageHeight;
sW = stage.stageWidth;
if (sW <= sH)
{
sW = sH*1.15;
}
graphics.lineStyle(1, 0x00ffff);
graphics.drawRect(0, 0, sW, sH);
this.removeEventListener(Event.ADDED_TO_STAGE, init);
addChild(canvas);
addChild(wildLife);
addChild(display);
hex0 = new Polygon(6, tileSize, [0xffffff], 0xff0000, 1);
wid = hex0.width * .8;
hth = hex0.height * .85;
halfHt = hex0.height * .37;
hexesWide = Math.floor(sW / (tileSize * .82));
while(hexesWide * tileSize * .82 > sW)
{
hexesWide--;
}
mapArray = new Array(hexesWide);
hexesHigh = Math.floor(sH / (tileSize * .92));
while(hexesHigh * tileSize * .93 > sH)
{
hexesHigh--;
}
if((hexesHigh*tileSize * .93) + tileSize*.5 >= sH)
{
halfOffset = true;
}
trace(mapArray.length * tileSize, hexesHigh*tileSize);
for( i = 0; i < mapArray.length; i++)
{
if(halfOffset)
{
if(columnOffset == 0)
{
mapArray[i] = new Array(hexesHigh + 1);
columnOffset = 1;
}
else
{
mapArray[i] = new Array(hexesHigh);
columnOffset = 0;
}
}
else
{
mapArray[i] = new Array(hexesHigh);
}
}
generateMap();
hexLabel = makeLabel(" --Hex Grid-- ");
display.addChild(hexLabel);
hexLabel.x = (sW - hexLabel.width)/2;
hexLabel.y = 10;
//gTwn.tweenFrom0(hexLabel, 1, 9);
mouseBoard = makeBoard([" ", "Health:", "Stomach:", "Enery:", "Blood Sugar:"]);
addChild(mouseBoard);
//mouseBoard.alpha = 1;
}
private function generateMap():void
{
columnOffset = 0;
for(var curCol:int = 0; curCol < mapArray.length; curCol++)
{
for( var curRow:int = 0;curRow < mapArray[curCol].length; curRow++)
{
mapArray[curCol][curRow] = mapTypes[Math.floor(Math.random() * mapTypes.length)];
var inner:Number;
var plantGrowth:int;
hex = new MovieClip();
hex.plants = [10, 20, 60, 99, 99, 99, 99];
hex.resources = [99, 99, 99, 99, 99];
switch(mapArray[curCol][curRow])
{
case 'valley':
inner = 0x66aa00;
plantGrowth = 3;
break;
case 'plains':
inner = 0x99ff00;
plantGrowth = 3;
break;
case 'praire':
inner = 0x99FF00;
plantGrowth = 3;
break;
case 'field':
inner = 0x885500;
plantGrowth = 3;
break;
case 'desert':
inner = 0xffff00;
plantGrowth = 1;
break;
case 'forest':
inner = 0x005511;
plantGrowth = 3;
break;
case 'mountain':
inner = 0x444444;
plantGrowth = 3;
break;
case 'hills':
inner = 0xFFFFaa;
plantGrowth = 3;
break;
case 'ocean':
inner = 0x0044ff;
plantGrowth = 3;
break;
case 'lake':
inner = 0x00ffff;
plantGrowth = 3;
break;
case 'sea':
inner = 0x00aaaa;
plantGrowth = 3;
break;
case 'swamp':
inner = 0x447700;
plantGrowth = 3;
break;
case 'shallows':
inner = 0x88ccff;
plantGrowth = 3;
break;
case 'barren':
inner = 0xaa4400;
plantGrowth = 0;
break;
}
hex.Name = mapArray[curCol][curRow]+String(curCol) +String(curRow);
canvas.addChild(hex);
var hexBG:Sprite = new Polygon(6, tileSize, [inner], 1, 1);
hex.addChild(hexBG);
hexBG.rotation+=30;
var dot:Sprite = new Sprite();
hex.addChild(dot);
hex.dotColor = 0xffffff;
hex.x = (hex0.width * .44 + (wid * curCol));
if(columnOffset == 0)
{
hex.y = halfHt + (hth * curRow);
if(curCol > hexesWide -1 || curRow > hexesHigh - 1)
{
hex.dotColor = 0xff0000;
}
}
else
{
hex.y = halfHt + (hth * .50 + hth * curRow);
if(curCol > hexesWide -2 || curRow > hexesHigh - 2)
{
hex.dotColor = 0xff0000;
}
}
if(curCol == 0 || curRow == 0)
{
hex.dotColor = 0xff0000;
}
dot.graphics.lineStyle(2, hex.dotColor);
dot.graphics.drawCircle(0,0,1);
mapArray[curCol][curRow] = hex;
hex.alpha = .5;
}
if(columnOffset)
{
columnOffset = 0;
}
else
{
columnOffset = 1;
}
}
mapTimer = new Timer(1);
mapTimer.addEventListener(TimerEvent.TIMER, displayMap);
mapTimer.start();
// make outline based on hexgrid:
bezel.graphics.lineStyle(2, 0xffffff);
bezel.graphics.beginFill(0x444444);
bezel.graphics.drawRect(0,0,canvas.width + 2-tileSize *.24, canvas.height -tileSize *.29);
}
private function displayMap():void
{
if(mapCol < mapArray.length)
{
if(mapRow < mapArray[mapCol].length)
{
var hex:Sprite = mapArray[mapCol][mapRow];
if(hex)
{
//gTwn.tweenFrom0(hex, 1, .4);
hex.addEventListener(MouseEvent.ROLL_OVER, overHex);
hex.addEventListener(MouseEvent.ROLL_OUT, outHex);
hex.addEventListener(MouseEvent.MOUSE_DOWN, downHex);
hex.addEventListener(MouseEvent.MOUSE_UP, upHex);
}
mapRow++;
}
else
{
mapRow = 0;
mapCol++;
}
}
else
{
mapTimer.reset();
makeCritters(5);
}
}
private function makeCritters(num:int):void
{
//map = mapArray;
for(i = 0; i <= num; i++)
{
var h:MovieClip = mapArray[i][0];
var crit:MovieClip = new Critter('Goat', i, h);
mapArray[i][0].addChild(crit);
crit.hexRow = i;
crit.hexCol = 0;
crit.addEventListener(MouseEvent.ROLL_OVER, displayStats);
}
}
private function displayStats(e:MovieClip):void
{
var targ:MovieClip = e.currentTarget;
var arr:Array = [["Name:", targ.Name],["stomach:", targ.stomach], ["smallIntestine:", targ.smallIntestine], ["energy:", targ.energy], ['bloodSugar:', targ.bloodSugar], ['fat:', targ.fat], ['health:', targ.overAllHealth], ['spiritual:', targ.spiritualHealth], ['physical:', targ.physicalHealth], ['mental:', targ.mentalHealth],['enclave:', targ.enclave.Name]];
//gTwn.tweenIn(mouseBoard, .6, .7);
mouseBoard.x = mouseX + 10;
mouseBoard.y = mouseY + 10;
var txt:String = "Critter Stats<BR>";
for(var i:int = 0; i < arr.length; i++)
{
txt += arr[i][0] + arr[i][1] + "<BR>";
}
mouseBoard.fld.htmlText = txt;
targ.removeEventListener(MouseEvent.ROLL_OVER, displayStats);
targ.addEventListener(MouseEvent.ROLL_OUT, fadeStats);
}
private function fadeStats(e:MovieClip):void
{
//gTwn.tweenOut(mouseBoard, .6);
e.currentTarget.addEventListener(MouseEvent.ROLL_OVER, displayStats);
e.currentTarget.removeEventListener(MouseEvent.ROLL_OUT, fadeStats);
}
private function overHex(e:MovieClip):void
{
trans.color = 0xffffff;
e.currentTarget.getChildAt(1).transform.colorTransform = trans;
}
private function outHex(e:MovieClip):void
{
trans.color = e.currentTarget.dotColor;
e.currentTarget.getChildAt(1).transform.colorTransform = trans;
}
private function downHex(e:MovieClip):void
{
trans.color = 0xff00ff;
e.currentTarget.getChildAt(1).transform.colorTransform = trans;
switch(e.currentTarget.dotColor)
{
case 0:
e.currentTarget.dotColor = 0x0000ff;
break;
case 0x0000ff:
e.currentTarget.dotColor = 0x00ff00;
break;
case 0x00ff00:
e.currentTarget.dotColor = 0x00ffff;
break;
case 0x00ffff:
e.currentTarget.dotColor = 0xff0000;
break;
case 0xff0000:
e.currentTarget.dotColor = 0xff00ff;
break;
case 0xff00ff:
e.currentTarget.dotColor = 0xffff00;
break;
case 0xffff00:
e.currentTarget.dotColor = 0xffffff;
break;
case 0xffffff:
e.currentTarget.dotColor = 0;
break;
}
}
private function upHex(e:MovieClip):void
{
trans.color = e.currentTarget.dotColor;
e.currentTarget.getChildAt(1).transform.colorTransform = trans;
}
private function makeBoard(info:Array):MovieClip
{
var board:MovieClip = new MovieClip();
fmt.size = 14;
fmt.color = 0xffffff;
board.fld = tFX.textFld('Critter Statistics', fmt, [0], 'left');
var fld:TextField = board.fld;
var w:Number = fld.width;
fld.width = w*1.2;
fld.multiline = true;
fld.wordWrap = true;
var txt:String = "Critter Statistics<BR>";
for(i = 0; i < info.length; i++)
{
txt+=info[i]+"<BR>";
}
fld.htmlText = txt;
fld.selectable = false;
board.addChild(fld);
board.graphics.lineStyle(2, 0xffffff);
board.graphics.beginFill(0x110011);
board.graphics.drawRect(0,0, fld.width, fld.height *2.2);
return board;
}
private function makeLabel(str:String):Sprite
{
var fld2:TextField = tFX.textFld(str, fmt, [0], 'left');
fmt.color = 0xf7e0b0;
var fld3:TextField = tFX.textFld(str, fmt, [0], 'left');
fmt.color = 0x978050;
var fld:TextField = tFX.textFld(str, fmt, [0], 'left');
hexLabel.graphics.lineStyle(1, 0xffffff);
hexLabel.graphics.beginFill(0, .5);
hexLabel.graphics.drawRoundRect(0,0, fld.width* 1.2, fld.height * 1.2, 13);
hexLabel.graphics.endFill();
hexLabel.addChild(fld2);
fld2.x = (hexLabel.width-fld2.width)/2;
fld2.y = (hexLabel.height-fld2.height)/2;
hexLabel.addChild(fld3);
fld3.x = fld2.x - 3;
fld3.y = fld2.y -3;
hexLabel.addChild(fld);
fld.x = fld2.x - 2;
fld.y = fld2.y - 2;
return hexLabel;
}
}
/* Critter
ActionScript 3.0
Artificial Inteligence similation
Future modifications:
Make a critter:
initiate timer for feeding, digesting, resting, aging...
Created 2012
Edited January 2016
Version Modification
0.0
Methods:
wander
feed
ruminate
rest
digest
*/
}
import flash.text.TextRun;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.*;
import flash.utils.*;
import flash.geom.*;
class Critter extends MovieClip
{
private var critter:MovieClip = new MovieClip();
private var xVel:Number = 0;
private var yVel:Number = 0;
private var speed:Number = 1;
private var dTT:Number = 0;
private var goal:Array = [];
private var desire:Array = [];
private var health:Array = [];
private var strength:Array = [];
private var map:Array= [];
private var age:int = 0;
public var type:String = "goat";
public var Name:String = "Goat";
public var hexRow:int;
public var hexCol:int;
public var stomach:int = 200;
internal var full:int = 1000;
internal var empty:int = 0;
public var smallIntestine:int = 900;
public var energy:Number = 1400;
public var bloodSugar:Number = 1500;
public var fat:Number = 99;
public var food:int;
public var overAllHealthL:int = 100;
public var spiritualHealth:int = 100;
public var physicalHealth:int = 100;
public var mentalHealth:int = 100;
private var grazing:Boolean = false;
// timers:
private var grazeTimer:Timer = new Timer(9999, 1);
private var ruminateTimer:Timer;
private var restTimer:Timer;
private var digestTimer:Timer = new Timer(999);
private var statTimer:Timer = new Timer(5000);
private var observeTimer:Timer = new Timer(500);
private var mateTimer:Timer;
private var i:int = 0;
private var j:int = 0;
private var trans:ColorTransform = new ColorTransform();
public var enclave:Object;
public function Critter(type:String, num:int, home:MovieClip)
{
var Name:String = (type+num.toString());
addEventListener(Event.ADDED_TO_STAGE, init);
enclave = home;
}
private function init(e:Event):void
{
critter.graphics.lineStyle(2, 0xffffff);
critter.graphics.drawCircle(0,0,10);
critter.fat = 150;
critter.dotColor = 0x660000;
var critterColor:Sprite = new Sprite();
critter.addChild(critterColor);
critterColor.graphics.beginFill(critter.dotColor);
critterColor.graphics.drawCircle(0,0, 10);
addChild(critter);
digestTimer.addEventListener(TimerEvent.TIMER, digest);
digestTimer.start();
grazeTimer = new Timer(1, 1);
grazeTimer.addEventListener(TimerEvent.TIMER, graze);
grazeTimer.start();
critter.AddEventListener(MouseEvent.ROLL_OVER, overCritter);
critter.AddEventListener(MouseEvent.ROLL_OUT, outCritter);
critter.AddEventListener(MouseEvent.MOUSE_DOWN, downCritter);
critter.AddEventListener(MouseEvent.MOUSE_UP, upCritter);
statTimer.addEventListener(TimerEvent.TIMER, stats);
statTimer.start();
}
public function wander(To:Array):void
{
var colMod:int = 1 - Math.floor(Math.random() *2);
var rowMod:int = 1 - Math.floor(Math.random() *2);
if(hexCol == 00 && colMod<0)
{
colMod = 1;
}
else if(hexCol == enclave.maxCol && colMod >0)
{
colMod = -1;
}
if(hexRow == 0 && rowMod <0)
{
rowMod = 1;
}
else if (hexRow == enclave.maxRow && rowMod >0)
{
rowMod = -1;
}
}
private function stats():void
{
energy -=2;
bloodSugar -=2;
if(age>100)
{
physicalHealth--;
}
else if(age > 200)
{
physicalHealth -=2;
}
if(fat > 100)
{
var ugh:int = fat/100;
energy-=ugh*2;
mentalHealth -=ugh;
physicalHealth -=ugh;
}
health = checkHealth();
}
internal function checkHealth():Array
{
age++;
if(bloodSugar < 500)
{
mentalHealth -=2;
}
else if(bloodSugar < 1000)
{
mentalHealth--;
}
else if(bloodSugar < 1500)
{
mentalHealth;
}
else if(bloodSugar < 2000)
{
mentalHealth++;
}
else if(bloodSugar < 2500)
{
mentalHealth+=2;
}
var overAllHealth:int = (physicalHealth + mentalHealth + spiritualHealth)/4;
return [overAllHealth, physicalHealth, mentalHealth, spiritualHealth];
}
private function checkFood():uint
{
var position:uint = 0;
for(i = 0; i < enclave.plants.length; i++)
{
if(position == 0 && enclave.plants[i] > 0)
{
position = i;
}
}
return position;
}
private function graze():void
{
if(stomach < full)
{
var food:int=checkFood();
if(food)
{
enclave.plants[food]--;
stomach++;
grazing = true;
grazeTimer = new Timer(999, 1);
grazeTimer.addEventListener(TimerEvent.TIMER, graze);
grazeTimer.start();
}
else
{
wander(['no food']);
}
}
else
{
grazing = false;
ruminateTimer = new Timer(9999, 1);
ruminateTimer.addEventListener(TimerEvent.TIMER, rest);
ruminateTimer.start();
}
}
private function rest():void
{
if(energy < 1000 && stomach < 250)
{
if(!grazing)
{
grazing = true;
grazeTimer = new Timer(999, 1);
grazeTimer.addEventListener(TimerEvent.TIMER, graze);
grazeTimer.start();
}
}
}
private function digest():void
{
if(smallIntestine >0)
{
energy +=15;
smallIntestine-=10;
}
if(energy>10)
{
energy-=10;
if(bloodSugar<2500)
{
bloodSugar += 10;
}
else
{
fat +=3;
}
}
if(fat>100)
{
critter.dotColor = 0;
}
else if(bloodSugar < 250)
{
critter.dotColor = 0xff0000;
}
else if(bloodSugar < 500)
{
critter.dotColor = 0xffaa00;
}
else if(bloodSugar < 750)
{
critter.dotColor = 0xffff00;
}
else if(bloodSugar < 1000)
{
critter.dotColor = 0xaaaaaa;
}
else if(bloodSugar < 1500)
{
critter.dotColor = 0x0000ff;
}
else if(bloodSugar < 2000)
{
critter.dotColor = 0x00ffff;
}
else if(bloodSugar < 2500)
{
critter.dotColor = 0x00ff00;
}
else if(bloodSugar >= 2500)
{
critter.dotColor = 0xffffff;
}
trans.color = critter.dotColor;
critter.getChildAt(0).transform.colorTransform = trans;
}
private function overCritter():void
{
trans.color = 0xffffff;
critter.getChildAt(0).transform.colorTransform = trans;
}
private function outCritter():void
{
trans.color = critter.dotColor;
critter.getChildAt(0).transform.colorTransform = trans;
}
private function downCritter():void
{
trans.color = 0xff00ff;
critter.getChildAt(0).transform.colorTransform = trans;
}
private function upCritter():void
{
trans.color = critter.dotColor;
critter.getChildAt(0).transform.colorTransform = trans;
}
}
import flash.display.*;
import flash.geom.*;
class Polygon extends Sprite
{
public var poly:Sprite
private var degrees:Number;
private var distFromCenter:Number;
private var polyRadious:Number;
private var newX:Number;
private var newY:Number;
private var lastAngle:Number = 0;
private var divisions:Number;
public function Polygon(sides:Number, pDiameter:Number, pFill:Array, strokeSize:Number=1, strokeColor:Number=0)
{
poly = new Sprite();
if(pFill[2])
{
var gradient:Array = pFill[2];
poly.graphics.beginGradientFill(gradient[0],gradient[1],gradient[2],gradient[3],gradient[4],gradient[5],gradient[6]);
}
else if (pFill[1])
{
var fillType:String = GradientType.RADIAL;
var colors:Array = [pFill[0], pFill[1]];
var alphas:Array = [1, 1];
var ratios:Array = [0x00, 0xFF];
var matr:Matrix = new Matrix();
var stripes:int = 20;
matr.createGradientBox(stripes, stripes, 0, -stripes*.54, -stripes*.54);
poly.graphics.beginGradientFill(fillType, colors, alphas, ratios, matr, "pad", "rgb", 0.0);
}
else if(pFill[0])
{
poly.graphics.beginFill(pFill[0]);
}
degrees = 360/sides;
polyRadious = pDiameter / 2;
newX,newY,lastAngle = 0;
poly.graphics.lineStyle (1, strokeColor);
var newY:Number = Math.sin(lastAngle * Math.PI / 180) * polyRadious;
var newX:Number = Math.cos(lastAngle * Math.PI / 180) * polyRadious;
poly.graphics.moveTo(newX, newY);
for (var i:Number = 0; i < sides; i++)
{
// Main Points:
lastAngle-=degrees;
newY=Math.sin(lastAngle*Math.PI/180)*polyRadious;
newX=Math.cos(lastAngle*Math.PI/180)*polyRadious;
poly.graphics.lineTo (newX, newY);
}
poly.graphics.endFill();
var oddNumber:Boolean = false;
for(i=sides;i>2;i-=2)
{
if(i-2==1)
{
oddNumber=true;
}
}
if(oddNumber)
{
poly.rotation -=90;
}
else
{
poly.rotation +=90;
}
addChild(poly);
}
}
import flash.text.*;
import flash.text.TextFormat;
class TextFunctions
{
public var blueFmt:TextFormat = new TextFormat();
public var goldFmt:TextFormat = new TextFormat();
public var blackFmt:TextFormat = new TextFormat();
public function TextFuntions():void
{
makeFormats();
}
public function nameCase(str:String):String
{
var tmpStr:String = str.slice(0, 1);
tmpStr = tmpStr.toUpperCase();
var tmpStr2:String = str.slice(1, (str.length));
return(tmpStr + (tmpStr2.toLowerCase()));
}
// tFX.textFld(fld, 'Critter Statistics', fmt, 'left');
public function textFld(fldName:String, fldFmt:TextFormat, size:Array, fAlign:String = 'left'):TextField
{
var fld:TextField = new TextField();
fld.selectable = false;
if(size.length == 4)
{
fld.width = size[0];
fld.height = size[1];
fld.multiline = true;
fld.wordWrap = true;
}
if(fAlign=='right')
{
fld.autoSize = TextFieldAutoSize.RIGHT;
}
else if(fAlign=='center')
{
fld.autoSize = TextFieldAutoSize.CENTER;
}
else
{
fld.autoSize = TextFieldAutoSize.LEFT;
}
fld.defaultTextFormat = fldFmt;
//fld.htmlText = fldText;
fld.name = fldName;
return(fld);
}
private function makeFormats():void
{
blueFmt.color = 0x113366;
blueFmt.size = 14;
blueFmt.font = 'Tahoma';
blueFmt.color = 0x877040;
blueFmt.size = 13;
blueFmt.font = 'Tahoma';
blackFmt.size = 12;
blackFmt.font = 'Tahoma';
}
public function getFormat(fmt:String):TextFormat
{
var newFmt:TextFormat;
if(fmt=='blue')
{
newFmt = blueFmt;
}
else if(fmt=='gold')
{
newFmt = goldFmt;
}
else
{
newFmt = blackFmt;
}
return newFmt;
}
public function inputFld(fName:String, size:Array, fldFmt:TextFormat):TextField
{
var fldName:TextField = new TextField();
fldName.selectable = false;
if(size.length == 4)
{
fldName.width = size[0];
fldName.height = size[1];
fldName.multiline = true;
fldName.wordWrap = true;
}
else
{
var tmp:TextField = new TextField();
//tmp.text = fldText;
tmp.autoSize = TextFieldAutoSize.LEFT;
var w:Number = tmp.width;
var h:Number = tmp.height;
fldName.width = w;
fldName.height = h;
}
fldName.type = TextFieldType.INPUT;
fldName.defaultTextFormat = fldFmt;
//fldName.htmlText = fldText;
fldName.autoSize = TextFieldAutoSize.NONE;
return(fldName);
}
}
import fl.transitions.Tween;
import fl.transitions.easing.*;
class gTweens
{
public function gTweens()
{
}
public function tweenFrom0(tgt:Object, newAlpha:int=1, twnTime:int=1):void
{
tgt.alpha = 0;
var twFade0:Tween = new Tween(tgt, 'alpha', Regular.easeOut, tgt.alpha, newAlpha, twnTime, true);
}
public function tweenIn(tgt:Object, twnTime:int=2, newAlpha:int=1):void
{
var twFadeIn:Tween = new Tween(tgt, 'alpha', Regular.easeOut, tgt.alpha, newAlpha, twnTime, true);
}
public function tweenOut(tgt:Object, twnTime:int=2, newAlpha:int=0):void
{
var twFadeOut:Tween = new Tween(tgt, 'alpha', Regular.easeOut, tgt.alpha, newAlpha, twnTime, true);
}
}