PDA

View Full Version : Vote system using PHP and Flash


AMparanoia
10-29-2003, 09:33 PM
Hi there,

Ok, i just started playing around with PHP combined with flash and now i'm trying to make a vote system using an example script. I know it should be something simple, but i just can't figure out what's wrong.

I've got the vote system working already. You can see the result >>HERE<< (http://www.amparanoia.nl/vote_system/).

But now i'm trying to implement it into my site by importing the *.swf into flash (loadmovie). So the only thing i've to do is to change the paths so everything has the right target. But i'm probably forgetting something

You can download the php files >>HERE<< (http://www.amparanoia.nl/php/php_files.rar)

Now in flash this is the script which is calling all the functions:


onClipEvent (load) {
lsig = 1;
function laden() {
loadVariables("frage.txt?z="+new Date().getTime(), "_parent");
loadVariables("themen.txt?z="+new Date().getTime(), "_parent");
loadVariables("stimm.txt?z="+new Date().getTime(), "_parent");
}
laden();
}
onClipEvent (data) {
_root.frage = frage;
// Themen
themen = new Array();
themen = thema.split(",");
gThema = themen.length;
// Zahlen
gruppen = new Array();
gruppen = stimmen.split(",");
gAnzahl = gruppen.length;
_root.max = gruppen.length-1;
if (_root.max >= 11) {
_root.hoch._visible = 1;
_root.runter._visible = 1;
}
// TotalStimmen
if (lsig==1) {
for (i=0; i<_root.max; i++) {
_root.totalStimmen += Number(gruppen[i]);
lsig = 0;
}
}
// Variablen für die Gruppen
for (j=0; j<_root.max; j++) {
_root["gruppe"+j] = Number(gruppen[j]);
}
// Anzeige aufbauen/Prozentberechnen/Themen
for (k=0; k<_root.max; k++) {
duplicateMovieClip("_root.obj", "obj"+k, k);
_root["obj"+k]._x = 2;
_root["obj"+k]._y = _root["obj"+k]._height*k+80;
_root.hoehe = _root["obj"+k]._height*k;
_root.hsig = 1;
_root["obj"+k].g = _root["gruppe"+k];
_root["prozent"+k] = int((Number(gruppen[k])/_root.totalStimmen)*1000)/10 +"%";
_root["obj"+k].wert = _root["prozent"+k];
_root["obj"+k].w = parseInt(_root["obj"+k].wert);
_root.totalProzent += parseFloat(_root["prozent"+k]);
_root.totalProzent = Math.round(_root.totalProzent);
if (_root.totalProzent != 100) {
_root.totalProzent = 100;
}
_root["obj"+k].t = themen[k];
}
_root.hoehe = _root.hoehe + _root.obj0._height +60;
}


I changed the target of frage.txt, stimm.txt and themen.txt to _parent so it knows the files are in the same folder. For some reason the question (which is frage.txt) does work, but stimm.txt and themen.txt (which are for the multiple-choice answers) don't? And they are all in the same folder.

This should be simple IMO, but i must have forgotten (or just don't understand it at all) something and i hope somebody can help me out!

Thanx in advance!

AMparanoia
10-30-2003, 12:51 PM
OK, i've figured it out. I just renamed all the _roots to _parents. And now it works besides the voting itself.

The button to vote has this script:


on (release) {
if (_parent.wahl==1) {
partei = t;
_parent.gotoandstop(3);
loadVariables("vote7.php3", "_parent.okay", "POST");
_parent.wahl = 0;
}
}


I'll be more specific about my movie and the script because nobody seems to help me out otherwise.

I've one MC which is duplicated for every new multiple choice answer. The instance of the MC is 'obj'.

I've another MC which is empty but has all the code i placed in the first post. So there are no MC's in MC's etc.

I've got 2 scenes: 1st. 'Init' and 2nd. 'vote'. The init is empty but has only this actionscript in the keyframe: _parent.wahl = 1;
It says _parent.wahl is true. So that refers to the if (_parent.wahl==1) { part of the button (which is in the MC 'obj').

If it's true the script continues. Partei = t; is a variable of t which is a var of an text area.

Then _parent.gotoandstop(3); is the part i don't understand. Because it tells to go to the main (_root) and goto the 3rd frame. The weird thing is: I only have 2 frames?! But somehow it worked before i loaded it into my main movie so it must be alright?

Then loadVariables("vote7.php3", "_parent.okay", "POST"); is another thing i don't understand, because it refers to a MC with the instance 'okay' and i can't find the bloody thing! When i use the telltarget command to see if the instance 'okay' is really there it shows it without a problem. But only when i use the absolute path. When i use relative it's gone?!

Then the _parent.wahl = 0; is to say it's false so it knows not do all this again.

You can download the .fla/.swf of the vote system >HERE< (http://www.amparanoia.nl/vote_system/votet.rar) so you can see what the movie looks like.

I load the movie into my main movie with this script: loadMovie("votet.swf", "_root.vote");

You can see the main movie with the vote system (that works besides the voting itself) HERE (http://www.amparanoia.nl/)

Hope somebody can help me out.

Thanx in advance

AMparanoia
10-31-2003, 10:32 PM
Ok, i think i've found the bug, but i still have no idea how to fix it.

In the scene 'init' there is only this script:
_root.wahl = 1;
I first had no idea what that wahl ment, but now i do. It's linked with a part of the 'schreiben2.php. This is the part i mean:
function init() {


$wahl_array = file("wahl.txt");
$reload_dat = fopen("wahl.txt","w");

etc etc...

So this means the voting will only take place when wahl (wahl.txt.) is true. If it's true it'll continue with the voting. So somehow the wahl.txt doesn't load because the path is probably not correct, but i've tried everything...i've tried this., _parent., _parent._parent, _root. etc... and none of them worked. :(

I've als tried to remove the _parent.wahl==1 and the if _parent.wahl==1 statement at the button to check if it would work. Then it partly works. It goed to the next frame with the thanx for your vote etc... but the answers still stand because the rest of the script in the php isn't executed. So i have to figure out how to make this work.
If somebody has any suggestions, please please, let me know! :D
This %^$ $^ vote system is giving me a headache, but i want to make this #%^ thing working if it's only to make me sleep better ;)