code:
outline=function(m,x,y){
w=x+71
h=y+99
//lineStyle(thickness:Number, rgb:Number, alpha:Number, pixelHinting:Boolean, noScale:String, capsStyle:String, jointStyle:String, miterLimit:Number)
m.lineStyle(2,0x9FFFCF,50,true,"normal","round","r ound")
m.beginFill(0x9FFFCF,60)
m.moveTo(x,y)
m.lineTo(w,y)
m.lineTo(w,h)
m.lineTo(x,h)
m.lineTo(x,y)
m.endFill()
}
_global.cards = flash.display.BitmapData.loadBitmap('deck');
//DropShadowFilter([distance], [angle], [color], [alpha], [blurX], [blurY], [strength], [quality], [inner], [knockout], [hideObject])
myDropShadow = new flash.filters.DropShadowFilter(4,45,0x00000000,10, 10,10);
MovieClip.prototype.createNewCard = function(name,depth,deck,col,row){
// create the movieclips to hold the card
var m = this.createEmptyMovieClip(name,depth);
var m1 = m.createEmptyMovieClip('m',1); m1._x = 36; m1._y = 50;
var m2 = m1.createEmptyMovieClip('m',1);
m2.filters = [myDropShadow];
// copy the passed parameters to the movieclip
m.deck = deck;
m.col = col;
m.row = row;
m.$s = true; // flip state
// add some functions
m.destroy = function(){
this.bmp.dispose();
this.swapDepths(this.getNextHighestDepth());
this.removeMovieClip();
}
m.$copy = function(col,row){
this.bmp.dispose();
this.bmp = new flash.display.BitmapData(72,100,true);
this.bmp.applyFilter(this.bmp,this.flash.geom.rect angle, new flash.geon.Point(0,0),myDropShadow)
this.bmp.copyPixels(_global.cards,new flash.geom.Rectangle(col * 72,row * 100,72,100),new flash.geom.Point(0,0));
this.m.m.attachBitmap(this.bmp,1,'auto',true);
this.m.m._x = -38; this.m.m._y = -50;
}
m.flipCard = function(){
this.$s = !this.$s;
if (this.$s) this.$copy(this.col,this.row) else this.$copy(this.deck,4);
}
m.flipCardAnimated = function(){
this.$f = 0;
this.onEnterFrame = function(){
this.$f++;
this.m._yscale = Math.abs(Math.cos(Math.PI * this.$f * .1)) * 100;
if (this.$f == 5){
this.flipCard();
} else if (this.$f == 10){
this.onEnterFrame = null;
this.onAnimationCompleted();
}
}
}
m.moveCardAnimated = function(dx,dy){
this.$f = 0;
this.sx = this._x;
this.sy = this._y;
this.dx = dx;
this.dy = dy;
this.onEnterFrame = function(){
this.$f++;
this._x = this.sx * (10-this.$f) * .1 + this.dx * this.$f * .1;
this._y = this.sy * (10-this.$f) * .1 + this.dy * this.$f * .1;
if (this.$f == 10){
this.onEnterFrame = null;
this.onAnimationCompleted();
}
}
}
// show card
m.flipCard();
// return refrence
return m;
}
Array.prototype.shuffle = function() {
len = this.length;
for (var i=0; i < len; i++) {
rand = Math.floor(Math.random()*len);
//swap current index with a random one
temp = this[i];
this[i] = this[rand];
this[rand] = temp;
}
}
startingCash=100
money=startingCash
bet=0
code:
cr=100
cardStart=50
createNewCard('drawCard',getNextHighestDepth(),3,0 ,1);
drawCard._x = 400; drawCard._y = cr;
Array.prototype.shuffle = function() {//adds the method shuffe() to all Arrays to shuffle it's elements
var len = this.length;
for (var i=0; i < len; i++) {
var rand = Math.floor(Math.random()*len);
//swap current index with a random one
var temp = this[i];
this[i] = this[rand];
this[rand] = temp;
}
}
function createDeck(){
var deck=new Array()//create array of cards like 0|0 that represent their position in the card graphic
for(var s=0;s<4;s++){//maybe shoul be using Points i.e. flash.geom.Point
for(var n=0;n<13;n++){
//deck.push(s.toString()+"|"+n.toString())
deck.push(createNewCard('Card'+s.toString()+n.toSt ring(),getNextHighestDepth(),3,n,s));
deck[deck.length-1]._visible=false
deck[deck.length-1].value=n
deck[deck.length-1].suit=s
deck[deck.length-1].onRelease = drawCard.onReleaseOutside = function(){
this.flipCardAnimated();
}
}
}
return deck;
}
var m = this.createEmptyMovieClip("layout",getNextHighestD epth());
for (x=cardStart;x<320;x+=80){
outline(m,x,100);
}
/*test this with a shuffle and displaying the results in a text filed
to get a card out of the deck use array.shift() to pull one card at a time into the string
I'll need another hand array I suppose to evaluate the hand at the end
*/
deck = new Array()
deck=createDeck()
deck.shuffle()
//lightrn logo
bgLogo._alpha=35
cardsDrawn=0
cp=cardStart
handDelt=false
drawCard.onRelease = drawCard.onReleaseOutside = function(){
if (!handDelt){
for (x=0;x<4;x++){
deck[x]._x=this._x
deck[x]._y=cr
deck[x]._visible=true
deck[x].moveCardAnimated(cp,cr)
cardsDrawn++
cp+=80
deck[x].onAnimationCompleted = function(){
this.onAnimationCompleted = function(){
}
this.flipCardAnimated();
}
}
handDelt=true
}else{
/******************************************
//deal only cards not flipped down
//code to go here!
********************************************/
}
}//drawcard button action