Solved

# how to set interval actionscript

Posted on 2006-05-31
Medium Priority
1,132 Views
Hi guys,

I'm making a poker game right now.
Is there anybody who could help me set an interval between each card that been drawed. I really appreciate anybody who could help me.

this is the card drawing code.

picked = new Array();

for(i=0 ; i<52 ; i++) {
picked[i] = 0;
}

pos_x = 92;
for(x=0 ; x<5 ; x++) {
card = new Array();
card[x] = "";
do {
n = (Math.round(Math.random()* 51)) + 1;
} while(picked[n]==1)
picked[n] = 1;
card[x] = n;
c = _root.attachMovie(card[x],"card"+x,x);
c._x = pos_x;
pos_x += 100;
if(x%2) { c._y = 450; }
else { c._y = 420; }
}
0
Question by:Edwat
• 4
• 3

LVL 11

Expert Comment

ID: 16796540
lets say that drawCard is a function which draws the cards:

var currentCard:Number = 0;
var interval:Number = setInterval(drawCard, 1000);
function drawCard() {

}
0

LVL 11

Expert Comment

ID: 16796563
sorry :) .....

lets say that drawCard is a function which draws the cards:

var currentCard:Number = 0;
var interval:Number = setInterval(drawCard, 1000);
function drawCard() {
if (currentCard == 5) {
clearInterval(interval);
return;
}

++currentCard;
}

hope its understandable.
0

Author Comment

ID: 16796996
uh.. I still couldn't make it work..
please see my code again ..

function drawcard() {
c = _root.attachMovie(card[x],"card"+x,x);
c._x = pos_x;
if(x%2) { c._y = 450; }
else { c._y = 420; }
clearInterval(interval);
}

picked = new Array();

for(i=0 ; i<52 ; i++) {
picked[i] = 0;
}
pos_x = 92;
for(x=0 ; x<7 ; x++) {
card = new Array();
card[x] = "";
do {
n = (Math.round(Math.random()* 51)) + 1;
} while(picked[n]==1)
picked[n] = 1;
card[x] = n;
pos_x += 100;
interval = setInterval(drawcard, 1000);
}
0

LVL 11

Accepted Solution

Buffon earned 750 total points
ID: 16797077
1) I do not understand what is "picked".
2) attachMovie doesnt return anything, so:

c = _root.attachMovie(card[x],"card"+x,x);
c._x = pos_x;
if(x%2) { c._y = 450; }
else { c._y = 420; }

this wont work.

so I suggest first to try:

var currentCard:Number = 0;
var pos_x = 92;
var card:Array = new Array();
var interval:Number = setInterval(drawCard, 1000);
function drawCard() {
if (currentCard == 5) {
clearInterval(interval);
return;
}

_root.attachMovie((Math.round(Math.random()* 51)) + 1,"card" + currentCard, _root.getNextHighestDepth());
_root["card" + currentCard]._x = pos_x;
pos_x += 100;
if(currentCard % 2) { _root["card" + currentCard]._y = 450; }
else { _root["card" + currentCard]._y = 420; }

++currentCard;
}
0

Author Comment

ID: 16804103
"picked" is used to identify if one card has been picked so there won't be a same card for each draw..
0

Author Comment

ID: 16804428
thx buffon, the interval is working now, but how to set that there won't be a same card for each draw?
0

Author Comment

ID: 16805021
just got it. thanks buffon.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't hā¦
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and cā¦
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
###### Suggested Courses
Course of the Month13 days, 8 hours left to enroll