Hi All
more or less new to this forum and new to AS3.
I started my first class tonight, and had some problems,
but figured all of them out. Everything works like I want.
But as it is my first class I wanted to ask if someone
might point out if I did some basic mistakes, or if there
are places for improvement.
Thank you for your time it is highly appreciated.
C:-) H.2.O
[AS]
package {
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.Graphics;
import flash.events.TimerEvent;
import flash.utils.Timer;
public class MainTest extends Sprite {
//basic configuration
var _rows:uint = 10;
var _cols:uint = 10;
var _rectwidth:uint = 30;
var _rectheight:uint = 20;
var _offsetleft:int = 30;
var _offsettop:int = 30;
//helperVars
var _xpoint:uint = 0;
var _ypoint:uint = 0;
var _rand:uint;
var _myTimer:Timer = new Timer(25);
var _arrCards:Array = new Array();
var cont:MovieClip = new MovieClip;
var sp:Sprite;
public function MainTest() {
init();
_myTimer.addEventListener(TimerEvent.TIMER,onTime);
_myTimer.start();
}
private function init():void{
addChild(cont);
cont.x = _offsetleft;
cont.y = _offsettop;
for(var arr_ = 0; arr_ < _rows * _cols;arr_++){
_arrCards[arr_] = new Array(arr_%_cols,Math.floor(arr_/_cols));
}
}
private function onTime(e:TimerEvent):void{
_rand = uint(Math.random() * _arrCards.length-1);
trace(_rand);
createRect(_rand);
_arrCards.splice(_rand,1);
if(_arrCards.length == 0){
_myTimer.removeEventListener(TimerEvent.TIMER,onTime);
}
}
private function createRect(arrIndex:uint):void{
sp = new Sprite();
with(sp.graphics){
lineStyle(1,0xCCCCCC);
beginFill(0x1188FF);
drawRect(0,0,_rectwidth,_rectheight);
endFill();
};
sp.x = _arrCards[arrIndex][0] * _rectwidth;
sp.y = _arrCards[arrIndex][1] * _rectheight;
sp.name = "card" + (_arrCards[arrIndex][0] * 10 + _arrCards[arrIndex][1]);
cont.addChild(sp);
}
}
}
[/AS]