i am trying to send the data from actionscript to php file.but am not able to communicate with php file.am getting error like this "Undefined index: username in C:\xampp\htdocs\As\basics.php on line 2".
my code is below.
/*********actionscript******************/
var str:String = "hi";
var myscore = 0;
submit.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_7);
function fl_ClickToGoToAndStopAtFrame_7(event: MouseEvent): void {
var myrequest:URLRequest = new URLRequest("http://localhost/As/basics.php");
myrequest.method = URLRequestMethod.POST;
var variables:URLVariables = new URLVariables();
variables.username = str;
variables.score = myscore;
myrequest.data = variables;
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE, dataOnLoad);
loader.load(myrequest);
}
function dataOnLoad(evt:Event)
{
submit.alpha=100;
//status is a custom flag passed from back-end
}
/*********php code**********************/
<?php
$name = $_POST['username'];
echo "Result:<input type='text' value='$name'>";
echo "<param name='movie' value='cmphp.swf' />";
echo "<object type='application/x-shockwave-flash' data='cmphp.swf'width='1024' height='500'>";
echo "<param name='movie' value='FlashVars_AS2.swf' />";
?>
Related
php code :
while($row = mysql_fetch_assoc($arr))
{
$id = $row['id'];
$user_from = $row['user_from'];
$user_to = $row['user_to'];
$date = $row['date'];
$msg_body = $row['msg_body'];
$opened = $row['opened'];
if(strlen($msg_body)>150)
{
$msg_body = substr($msg_body,0,150)."....";
}
echo "<div id='toggletext$id' style='background-color:#ADD8E6;padding:6px;' onclick='toggle()'>";
echo "<form method='post'>";
echo "<input type='hidden' id='id1' value=$id>";
echo "<a href='$username'>$username</a> ";
echo " : $msg_body ";
echo "</form>";
echo "</div> <hr/>";
}
** it will echo the value present in $arr in forms of div so each $arr row will get displayed with unique div id **
js code :
function toggle()
{
var hr = new XMLHttpRequest();
var id = document.getElementById("id1").value;
var tx = "toggletext"+id;
var fn = document.getElementById(tx);
var url = "in.php";
fn.style.backgroundColor = "#fff";
var v = '<?php echo #$username;?>';
var vars = "post="+v+"&id="+id;
hr.open("POST", url, true);
hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
hr.onreadystatechange = function()
{
if(hr.readyState == 4 && hr.status == 200)
{
var return_data = hr.responseText;
document.getElementById("status").innerHTML = return_data;
}
}
hr.send(vars);
document.getElementById("status").innerHTML = "processing...";
}
// The problem is ...when there are 2 div(if $arr has 2 rows)..if i click the second div first div will get selected ..
Change your id in your input type hidden
echo "<input type='hidden' id='id".$id."' value=$id>";
and get like this in your javascript...
var incval = '<?php echo $id ?>';
var id = document.getElementById("id"+incval).value;
I am giving php echo because you already call username....
Finally, try to use My_Sqli function instead my_sql
i want to insert timer time in my database.i have created a timer class which is increasing in miniutes and seconds (in a dynamic text field).i have a home_button i want that when i click home_button timer time would be inserted into time column of scoreu table.all code is working fine.column is updating but time is not showing up in database table please help me to solve this..here is my as3 code
var myCount:Number = 00;
var seconds:Number = 00;
var minutes:Number = 0;
var myTime:Timer = new Timer(1000,myCount);
myTime.addEventListener(TimerEvent.TIMER, startCount);
my_time.text = "";
myTime.start();
function startCount(event:TimerEvent):void
{
seconds +=1;
if (seconds > 60)
{
seconds =00;
minutes +=1;
}
my_time.text = minutes+":"+(seconds >= 10 ? seconds : "0"+seconds);
}
var variables:URLVariables = new URLVariables();
variables.time1 = my_time.text;
home_Btn.buttonMode = true;
home_Btn.addEventListener(MouseEvent.CLICK, indexBtn_click1);
function indexBtn_click1(event:MouseEvent):void
{
myTime.stop();
var request:URLRequest = new URLRequest('http://localhost/timesend.php');
request.method = URLRequestMethod.POST;
request.data = variables;
var loader:URLLoader = new URLLoader(request);
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.load(request);
loader.addEventListener(Event.COMPLETE, dataOnLoad);
}
function dataOnLoad(event:Event)
{
var variables:URLVariables = URLVariables(event.target.data);
trace(variables.result); // gives : System Updated
}
here is timesend.php
<?php
// data.php
include('connect1.php');
// if we are here, that's mean that we are already connected to mysql server
// and we don't need to do another connection
$etime = $_POST['time1'];
// $link is the same connection created in your connect.php script
if (mysqli_query($link, "INSERT INTO scoreu (user) VALUES('$etime')")) {
echo 'result=System Updated';
} else {
echo 'result=error';
}
mysqli_close($link);
?>
there was a problem in table field type declaration ..i declared it as varchar..but now i have fixed the type as TEXT..now it is working perfect..
i want to update my database table newlessontime by posting a value from as3.but query is not working ...but when i give $etime = 4 in php code then database is updating lesson1 column but but when it comes for post method, value is not inserting into lesson1 column why is this happening? stdroll column value was inserted already i want to update lesson1 in same row of the table
here is my php file
// lesson1t.php
include('connect.php');
$etime = $_POST['time1'];
//$etime = 4;
if (mysqli_query($link, "UPDATE newlessontime set lesson1=$etime WHERE stdroll=123")) {
echo 'result=System Updated';
} else {
echo 'result=error';
}
mysqli_close($link);
?>
here is the fla file
home_Btn.buttonMode = true;
home_Btn.addEventListener(MouseEvent.CLICK, indexBtn_click1);
function indexBtn_click1(event:MouseEvent):void
{
myTime.stop();
variables.time1 = my_time.text ;
var request:URLRequest = new URLRequest('http://localhost/lesson1t.php');
request.method = URLRequestMethod.POST;
request.data = variables;
var loader:URLLoader = new URLLoader(request);
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.load(request);
loader.addEventListener(Event.COMPLETE, dataOnLoadl);
function dataOnLoadl(event:Event)
{
var variables:URLVariables = URLVariables(event.target.data);
trace(variables.result); // gives : System Updated
}
gotoAndPlay("manu");
SoundMixer.stopAll();
}
Maybe you problem is that you do not defined variable.time1 as a var in as3.
Try this...
home_Btn.buttonMode = true;
home_Btn.addEventListener(MouseEvent.CLICK, indexBtn_click1);
function indexBtn_click1(event:MouseEvent):void
{
myTime.stop();
var request:URLRequest = new URLRequest('http://localhost/lesson1t.php');
request.method = URLRequestMethod.POST;
//You should define what is variables...
var variables:URLVariables = new URLVariables(); //this you forgot!
variables.time1 = my_time.text ;
request.data = variables;
var loader:URLLoader = new URLLoader(request);
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.load(request);
loader.addEventListener(Event.COMPLETE, dataOnLoadl);
function dataOnLoadl(event:Event)
{
var variables:URLVariables = URLVariables(event.target.data);
trace(variables.result); // gives : System Updated
}
gotoAndPlay("manu");
SoundMixer.stopAll();
}
Try this and tell us what happen...
I forgot to give quote around $etime.
It should be '$etime' ..Now its working
Here's what I'm working with:
var stats:Array = ["11", "22", "33"];
create();
function create():void
{
var sender:URLLoader = new URLLoader;
var myVar:URLVariables = new URLVariables;
myVar.stats = stats;
var website:URLRequest = new URLRequest("http://www.roomrecess.com/MQFiles/createChar.php");
website.data = myVar;
sender.load(website);
sender.addEventListener(Event.COMPLETE, sendComplete);
}
You can also email me at: brian.king#southmont.12.in.us
thanks!!!!
Should be pretty self explanatory.
var vars = new URLVariables();
vars.postFieldName1="dummy1";
vars.postFieldNameA="dummy2";
var req:URLRequest = new URLRequest("entry.php");
req.method = URLRequestMethod.POST;
req.data = vars;
var sender=new URLLoader();
sender.addEventListener(Event.COMPLETE, dataSent);
sender.dataFormat = URLLoaderDataFormat.BINARY;
sender.load(req);
I have this code on .fla file
fm_button.visible = false;
var menu_label:Array = new Array("Introduction", "Products", "Services",
"Testimonials", "Our Company", "Contact Us");
var total:Number = menu_label.length;
var i:Number = 0;
var page:Number;
var main_menu:MovieClip = new MovieClip();
stage.addChild(main_menu);
for (i = 0; i < total; i++)
{
var btn = new flashmo_button();
btn.name = "btn" + i;
btn.x = fm_button.x;
btn.y = fm_button.y + i * ( fm_button.height + 10 );
btn.buttonMode = true;
btn.item_no = i;
btn.flashmo_click_area.addEventListener( Event.ENTER_FRAME, btn_enter );
var each_substring:Array = menu_label[i].split("|");
btn.flashmo_button_label.fm_label.text = each_substring[0];
btn.item_url = each_substring[1];
main_menu.addChild(btn);
}
function btn_over(e:MouseEvent):void
{
e.target.parent.over = true;
}
function btn_out(e:MouseEvent):void
{
e.target.parent.over = false;
}
What i want is to get this values:
("Introduction", "Products", "Services", "Testimonials", "Our
Company", "Contact Us");
from a text or php file named menu.php or menu.txt
Is this possible?
Why you need read from .php file?
Is this client-server communication?
In that case, when .fla file loads by client browser over http(s) you should do something like this:
menu.php (for example put this file to document root folder):
<?php $menu = array('Elem1', 'Elem2');
echo json_encode($menu); ?>
.fla:
var sendData:URLVariables = new URLVariables();
var request:URLRequest = new URLRequest('/menu.php');
request.method = URLRequestMethod.GET;
var loader:URLLoader = new URLLoader(request);
loader.addEventListener(Event.COMPLETE, onCompleted);
So, your .fla are doing query to server and get's list of categories (onCompleted method receive data).
If this is not server-client communication, you should use other file format, because .php is not a data storage )