ok i used a tutorial try it every thing is cool when i put the poll into a page and test it . but when i did put the poll movie clip inside another main movie clip . or try to load it as external poll.swf it dosenot return the values from php into the status_txt i donot know why . it load the variables from data base but when i try to vote again it suppose to tell me you already voted but it dosenot do this . it shows the processing mc and dosenot return the message you already voted from php parse file ! what is missing here
frame 1 layer 1
stop();
var variables1:URLVariables = new URLVariables();
var varSend1:URLRequest = new URLRequest("parse_my_poll.php");
varSend1.method = URLRequestMethod.POST;
varSend1.data = variables1 ;
var varLoader1:URLLoader = new URLLoader;
varLoader1.dataFormat = URLLoaderDataFormat.VARIABLES;
varLoader1.addEventListener(Event.COMPLETE, completeHandler1);
variables1.myRequest = "load_numbers";
varLoader1.load(varSend1);
function completeHandler1(event:Event):void{
count1_txt.text = "" + event.target.data.choice1Count;
count2_txt.text = "" + event.target.data.choice2Count;
count3_txt.text = "" + event.target.data.choice3Count;
}
frame 1 layer 2
processing_mc.visible=false;
var choiceNum:Number=0;
var errorsFormat:TextFormat = new TextFormat();
errorsFormat.color = 0X00F00;
var successFormat:TextFormat = new TextFormat();
successFormat.color = 0X00F00;
function btn1Click(event:MouseEvent):void{
choiceNum = 1;
choice_txt.text = choice1_txt.text;
}
function btn2Click(event:MouseEvent):void{
choiceNum = 2;
choice_txt.text = choice2_txt.text;
}
function btn3Click(event:MouseEvent):void{
choiceNum = 3;
choice_txt.text = choice3_txt.text;
}
btn1.addEventListener(MouseEvent.CLICK ,btn1Click );
btn2.addEventListener(MouseEvent.CLICK ,btn2Click );
btn3.addEventListener(MouseEvent.CLICK ,btn3Click );
var variables:URLVariables = new URLVariables();
var varSend:URLRequest = new URLRequest("parse_my_poll.php");
varSend.method = URLRequestMethod.POST;
varSend.data = variables1 ;
var varLoader:URLLoader = new URLLoader;
varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
varLoader.addEventListener(Event.COMPLETE, completeHandler);
function completeHandler(event:Event):void{
processing_mc.visible=false;
status_txt.text = event.target.data.return_msg;
status_txt.setTextFormat(errorsFormat);
if(event.target.data.return_msg == "thanks for voting!"){
status_txt.setTextFormat(successFormat);
count1_txt.text = "" + event.target.data.choice1Count;
count2_txt.text = "" + event.target.data.choice2Count;
count3_txt.text = "" + event.target.data.choice3Count;
}
}
vote_btn.addEventListener(MouseEvent.CLICK , ValidateAndSend );
function ValidateAndSend(event:MouseEvent):void{
if(!choice_txt.length){
status_txt.text ="please choose before you press vote";
status_txt.setTextFormat(errorsFormat);
}else {
processing_mc.visible=true;
variables.userChoice=choiceNum;
variables.myRequest = "store_choice";
varLoader.load(varSend);
}
}
php parseing file code
<?php
mysql_connect("localhost","myusername","password") or die (mysql_error());
mysql_select_db("counter_database") or die (mysql_error());
if ($_POST['myRequest'] == "load_numbers") {
// Query the totals from the database
$sql1 = mysql_query("SELECT id FROM votingPoll WHERE choice='1'");
$choice1Count = mysql_num_rows($sql1);
$sql2 = mysql_query("SELECT id FROM votingPoll WHERE choice='2'");
$choice2Count = mysql_num_rows($sql2);
$sql3 = mysql_query("SELECT id FROM votingPoll WHERE choice='3'");
$choice3Count = mysql_num_rows($sql3);
echo "choice1Count=$choice1Count";
echo "&choice2Count=$choice2Count";
echo "&choice3Count=$choice3Count";
}
if ($_POST['myRequest'] == "store_choice") {
//Obtain user IP address
$ip = $_SERVER['REMOTE_ADDR'];
// Create local variable from the Flash ActionScript posted
variable
$userChoice = $_POST['userChoice'];
$sql = mysql_query("SELECT id FROM votingPoll WHERE
ipaddress='$ip'");
$rowCount = mysql_num_rows($sql);
if ($rowCount == 1) {
$my_msg = "You have already voted in this poll.";
print "return_msg=$my_msg";
} else {
$sql_insert = mysql_query("INSERT INTO votingPoll
(choice, ipaddress) VALUES('$userChoice','$ip')") or die (mysql_error
());
$sql1 = mysql_query("SELECT * FROM votingPoll WHERE
choice='1'");
$choice1Count = mysql_num_rows($sql1);
$sql2 = mysql_query("SELECT * FROM votingPoll WHERE
choice='2'");
$choice2Count = mysql_num_rows($sql2);
$sql3 = mysql_query("SELECT * FROM votingPoll WHERE
choice='3'");
$choice3Count = mysql_num_rows($sql3);
$my_msg = "Thanks for voting!";
print "return_msg=$my_msg";
echo "&choice1Count=$choice1Count";
echo "&choice2Count=$choice2Count";
echo "&choice3Count=$choice3Count";
}
}
?>
when i make all the code in a movie clip it all works fine but when i put this movie clip inside another movie clip it dosenot get any data from php like thanks for voting or you already voted what do i need to make it work ?