PDA

View Full Version : Can Someone Check My Code Im Almost Done


mrg1982
10-13-2005, 11:38 AM
Hi again all:D

Ive tried searching for a tutorial of previous post for a while now, but no luck. This relates to a previous post of mine with shared objects, basically my problem was trying to store peoples stats to the one file name but it kept overwriting. So it was suggested to use an array but Ive had trouble with that.

What Ive done now is made a simple counter and when someone clicks on a button the counter increases in one increment.

Using this i manage to store my results as (on clicking a button)

on (press) {
_global.i++;
this["results"+i] = SharedObject.getLocal("results", "/");
this["results"+i].data.stats = username_txt"+"userscore_txt;
this["results"+i].flush();
}


Then they click another button to see all the results, this takes them to a new scene. Now on this scene I placed that scrollpane on my stage and made a new movie called it "userranks" such that this is what will be shown in the scrollpane. And I made a button with this code to that creates new textfields for the number of scores stored and displays them like this;

on (press) {
this["results"+i] = SharedObject.getLocal("results", "/");
this.userranks.createTextField("Score"+i, i, 200, 10+i, 100, 100);
userranks.this["Score"+i] = this["results"+i].data.stats;
}

Only thing is I thought what I was doing was right, it seemed to make sense, but nothing appears on the new scene.:eek:

Please can someone tell me what im doing wrong, once I get this my project is finished.

Thanks agian:D

mrg1982
10-14-2005, 05:53 AM
Hi again all

Ive been tinkering with my code and have finally got it to do what I want it to do.

However I was wondering if it was possible to tidy up my code. Because I dont know how many people are going to use my code I was wondering how I can use a loop command with an array.

This is my test code Im using;

On my first frame I have this

_global.i=0;
stop();

There is a input text box on my stage and in that Var name I entered "def".

I place this button on the stage as well with this code.

on (press) {
counter = SharedObject.getLocal("counter", "/");
counter.data.number = Number(i);
if (counter.data.number == 0) {
_global.i = 1;
counter.data.number = Number(i);
} else if (counter.data.number>0) {
_global.i = i++;
counter.data.number = Number(i);
}
counter.flush();
this["x"+i] = def;
test1 = SharedObject.getLocal("test1", "/");
test1.data.value1 = new Array(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16);
test1.flush();
gotoAndPlay("2");
}

On my sceond frame I have the scroll pane on stage which will play a movie name testing. This movie I made in my library and on the first frame of this movie I placed this code

this.onEnterFrame = function() {
test1 = SharedObject.getLocal("test1", "/");
counter = SharedObject.getLocal("counter", "/");
for (j=1; j<=Number(counter.data.number); j++) {
this.createTextField("scores"+j, this.getNextHighestDepth(), 0, Number(30)*Number(j), 0, 25);
this["scores"+j].border = true;
this["scores"+j].text = test1.data.value1[j-1];
}
};
stop();

This is my working code and I have no problems with. How ever the part I want to tidy up is this

test1.data.value1 = new Array(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16);

is it possibly to use a loop command to fill in an array. Can someone please show me how.