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);
Related
I need some help in displaying all the values in a Firebase database, in a table.
As is, it is just displaying the first value in the table alone
Results:
var tblCodes = document.getElementById('tbl_qrcode_list');
var databaseRef = firebase.database().ref('qrcode/');
var rowIndex = 1;
databaseRef.once('value', function(snapshot) {
snapshot.forEach(function(childSnapshot) {
var childKey = childSnapshot.key;
var childData = childSnapshot.val();
var row = tblCodes.insertRow(rowIndex);
var cellId = row.insertCell(0);
var cellName = row.insertCell(1);
cellId.appendChild(document.createTextNode(childKey));
cellName.appendChild(document.createTextNode(childData.qrcode_desc));
rowIndex = rowIndex + 1;
});
});
function save_code(){
var qrcode_desc = document.getElementById('qrcode_desc').value;
var qrcode_grp = document.getElementById('qrcode_grp').value;
var qrcode_stg = document.getElementById('qrcode_stg').value;
var qrcode_img = document.getElementById('qrcode_img').value;
var qrid = firebase.database().ref().child('qrcode').push().key;
var data = {
qrcode_id: qrid,
qrcode_desc: qrcode_desc,
qrcode_grp: qrcode_grp,
qrcode_stg: qrcode_stg,
qrcode_img: qrcode_img,
}
You need to create a cell for each value here :
you need to create cells for each data
var cell3 = row.insertCell(2);
var cell4 = row.insertCell(3);
var cell5 = row.insertCell(4);
cellName.appendChild(document.createTextNode(childData.qrcode_desc));
cellName.appendChild(document.createTextNode(childData.qrcode_grp));
cell3.appendChild(document.createTextNode(childData.qrcode_id));
cell4.appendChild(document.createTextNode(childData.qrcode_img));
cell5.appendChild(document.createTextNode(childData.qrcode_stg));
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
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' />";
?>
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 )
i am having this hard time figuring what is needed to do,
i am using URLVariables to send/recieve values between flash and PHP
the problem is, i am unable to access nested arrays ( array inside an array ) with flash
heres an example:
$dgresult = array("total" => $results);
echo http_build_query($dgresult,"flf_");
in flash, all i need to do is to use:
var variables:URLVariables = new URLVariables(e.target.data);
then i can access it with :
variables.total
the problem now is when i have nested arrays:
$dgresult = array("total" => $results);
array_push($dgresult,$another_array);
http_build_query($dgresult,"flf_");
i can still access variables.total
but what about anything that has flf_ ?
how is that possible?
you should try to simply use established formats for complex data, such as JSON. For PHP see here and for AS3 see here. Or ready made solutions such as AMFPHP.
greetz
back2dos
or you can just parse the object
var url:String = 'http://localhost/dump.php';
var params:Object = {
test: 'ok',
nested_1: {
nested_2: {
nested_3: {
nested_4: {
hello: 'mf',
str: '~!##$%^&*()_+'
}
}
}
},
};
var request:URLRequest = new URLRequest(url);
var variables:URLVariables = new URLVariables();
parameters = fixParameters(parameters || {});
for (var key:String in parameters) {
variables[key] = parameters[key];
}
request.data = variables;
var loader:URLLoader = new URLLoader();
loader.load(request);
and here is fixParameters method
private function fixParameters(data:Object, parameters:Object = null, prefixes:Array = null):Object {
var setPrefix:Array;
var prefixKey:String;
if (!parameters) {
parameters = {};
}
if (!prefixes) {
prefixes = [];
}
for (var key:String in data) {
setPrefix = prefixes.concat([key]);
if (typeof(data[key]) == 'object') {
parameters = fixParameters(data[key], parameters, setPrefix);
} else {
prefixKey = '';
for (var i:Number = 0; i < setPrefix.length; i++) {
prefixKey += i == 0 ? setPrefix[i] : '[' + setPrefix[i] + ']';
}
parameters[prefixKey] = data[key];
}
}
return parameters;
}