PDA

View Full Version : Virtual Creditcard/generate numbers


swed
05-26-2003, 06:09 PM
Hi!

I hope my friend "Eon" read this, my mathematic genie...

Here is my question

I have tried to make a virtual credit card (ice projector)

I want the 16 numbers to generate when the user start the card, different from each other.

When the number is generated I would like to store it in a txt.file (not a database) in some
Way, but the random generated numbers are the first thing to fix.

It would be nice if each number appears after itch other if it’s possibly

Have someone any idea to do that?

Thank swed


http://www.dynamisk.nu/testcard.htm

retrotron
05-26-2003, 06:43 PM
You could use Moock's function which generates a random number between two specified values:

function myRandom(minVal,maxVal) { // returns randomNum in specified range
return minVal + Math.floor(Math.random() * (maxVal + 1 - minVal));
} // end myRandom()

var creditCardNum = myRandom(1000000000000000,9999999999999999);

swed
05-26-2003, 06:48 PM
Hi and thanks!

Could you get my file and put the code as it should be ?

Thanks
Swed:D

retrotron
05-26-2003, 06:56 PM
I'm not sure what you mean by get your file . . . (from where?) . . . but why not try it yourself first?

swed
05-26-2003, 07:05 PM
From my link, but i will try myself to...

Regards
Swed

retrotron
05-26-2003, 07:11 PM
Ah, I see, you have a link for the .fla in your .htm link. I'm retarded.

Cool. Let me know if you can't get it to work.

swed
05-26-2003, 07:30 PM
retarded ? i don´t think soo, you help me to find the script !

It would be cool to have each number spinning for a couple
of sek and then stop, but how ???

The next thing is to send this number to a storage file
( txt ) thats tricky i think, ASP? or what ?

Help on the way?

All hands in the air and the brains clear...

Swed:cool:

Slowburn
05-26-2003, 07:37 PM
swed:

To save the .TXT file to the server you can use any backend or middleware you want....PHP, ASP, CGI, CF, etc...

But that is another topic in a different forum thread.

swed
05-26-2003, 07:53 PM
Hi Slowburn!

So you mean that i should move this question to an
other Forum to get an answer ?!

I wonder if someone could show me the steps to
create such txt file and maybe the code...

But if you say this is not the Forum, huuuuu this looks
like the state of Sweden ( bigbrother )

Hi from
Swede

Slowburn
05-26-2003, 07:58 PM
I would suggest asking this question in the scripting and backend section of this forum.

you can try to fgure it out by going to the source (http://www.php.net), or ask in the Scripting and Backend section.

It is a little more complicated for me to say here, since I'm not very good at PHP yet. but I'm suresomeone will be able to help you there.

Hope this helps.

Cheers.

swed
05-26-2003, 08:05 PM
Hi Slowburn!

Just kidding, you have a point there...

I will try to post the question later

Nice evening my friend

Regards
swed

retrotron
05-26-2003, 08:42 PM
Hey there,

Yeah, definitely post in the backend forum about how to write information to a textfile. You should find lots of help there.

On the matter of spinning numbers, post the following code into a blank .fla and test it, that should be the kind of thing you're looking for.

// ---------------------------------------
// functions //
// ---------------------------------------

// return a random number between specified values
function myRandom(minVal,maxVal) {
return minVal + Math.floor(Math.random() * (maxVal + 1 - minVal));
} // end myRandom()

// create 16 textfields, 7 px apart, with a 7px space every 4 numbers
function buildCardNumbers() {
// establish TextFormat
numFormat = new TextFormat();
numFormat.font = "_sans";
numFormat.color = "0x444444";
numFormat.size = 24;
// create textfield for each credit card number
var x_pos = 0; // start counting at 0
for (var i=0; i < 16; i++) { // loop 16 times, creating textfield each time
// find out if i is every 4th number
if (i % 4 == 0) { // if i divides into 4 with no remainder
x_pos += 24; // add 24 px to x_pos (accounting for space every 4 num)
} else { // if i is not divisible by 4
x_pos += 12; // add 12 px to x_pos
} // end if i mod 4
_root.createTextField("cardNum" + i + "_mc", i, x_pos, 20, 30, 30);
} // end looping 16 times
} // end buildCardNumbers()

// choose a random number between 0 and 9 for each textfield
function setCardNumbers() {
if (timeCount < 20) { // if timeCount has not yet reached 20
for (var i=0; i < 16; i++) { // loop through each text field
with (_root["cardNum" + i + "_mc"]) {
text = myRandom(0,9); // set the textfield to random num
setTextFormat(numFormat); // apply the TextFormat
} // end "with" grouping
} // end looping through each textfield
} else { // if timeCount has reached 20
clearInterval(cardInterval); // stop the interval from executing
} // end "if timeCount < 100"
timeCount += 1;
} // end setCardNumbers()

// ---------------------------------------
// execute the functions //
// ---------------------------------------

// build the card Numbers
buildCardNumbers();

// execute the setCardNumbers every 80 milliseconds
var timeCount = 0; // start timeCount at 0
var cardInterval = setInterval(setCardNumbers, 80);

swed
05-26-2003, 09:10 PM
Hi!

Huuuuu, nice thing but a stupid question...

How to move the generated numbers to the place i wont it ?

It´s about x and y, but i´m scared to ruin the nice script

Thanks again, and the txt question is on the other Forum

Smile Swed:)

retrotron
05-26-2003, 09:47 PM
to change the x placement, change this line:
var x_pos = 0; // start counting at 0
and replace the "0" with whatever x coordinate you want.

To change the y placement, change this line:
_root.createTextField("cardNum" + i + "_mc", i, x_pos, 20, 30, 30);
and replace the "20" with whatever y coordinate you want.

swed
05-27-2003, 05:06 AM
Thanks!

Best regardss
Swed:D

retrotron
05-27-2003, 05:33 AM
I modified the script so its easier to work with. Now the numbers are all created in a movieclip called "cardNumbers_mc", and the function that builds the cardnumbers takes two parameters: an x and y coordinate. The function then takes those two values and places "cardNumbers_mc" accordingly. So to place the numbers at any specific location, you simply define the x and y when you call the function like so: buildCardNumbers(x,y). Here's the code, notice where you define the x and y coordinates (buildCardNumbers(100,300); but you can replace 100 and 300 with whatever you want).


// ---------------------------------------
// functions //
// ---------------------------------------

// return a random number between specified values
function myRandom(minVal,maxVal) {
return minVal + Math.floor(Math.random() * (maxVal + 1 - minVal));
} // end myRandom()

// create 16 textfields, 7 px apart, with a 7px space every 4 numbers
function buildCardNumbers(x,y) {
// x: the x coordinate to place the movieclip
// y: the y coordinate to place the movieclip

// create the holder movieclip
this.createEmptyMovieClip("cardNumbers_mc", 0);
this.cardNumbers_mc._x = x;
this.cardNumbers_mc._y = y;

// establish TextFormat
numFormat = new TextFormat();
numFormat.font = "_sans";
numFormat.color = "0x444444";
numFormat.size = 24;
// create textfield for each credit card number
var x_pos = 0; // start counting at 0
for (var i=0; i < 16; i++) { // loop 16 times, creating textfield each time
// find out if i is every 4th number
if (i % 4 == 0) { // if i divides into 4 with no remainder
x_pos += 24; // add 24 px to x_pos (accounting for the space every 4th num)
} else { // if i is not divisible by 4
x_pos += 12; // add 12 px to x_pos
} // end if i mod 4
this.cardNumbers_mc.createTextField("cardNum" + i + "_mc", i, x_pos, 0, 30, 30);
} // end looping 16 times
} // end buildCardNumbers()

// choose a random number between 0 and 9 for each textfield
function setCardNumbers() {
if (timeCount < 20) { // if timeCount has not yet reached 20
for (var i=0; i < 16; i++) { // loop through each text field
with (_root.cardNumbers_mc["cardNum" + i + "_mc"]) {
text = myRandom(0,9); // set the textfield to random num
setTextFormat(numFormat); // apply the TextFormat
} // end "with" grouping
} // end looping through each textfield
} else { // if timeCount has reached 20
clearInterval(cardInterval); // stop the interval from executing
} // end "if timeCount < 100"
timeCount += 1;
} // end setCardNumbers()

// ---------------------------------------
// execute the functions //
// ---------------------------------------

// build the card Numbers at x,y (e.g. 100, 300)
buildCardNumbers(100,300);

// execute the setCardNumbers every 80 milliseconds
var timeCount = 0; // start timeCount at 0
var cardInterval = setInterval(setCardNumbers, 80);

swed
05-27-2003, 11:14 AM
Hi!

I´m stund by the help you get here on this Forum, thanks
again and the best to you...

Regards
Swed:D :D :D :D