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 )
Related
I am creating CSV from fetching data from MySQL data base. there are around 18000 rows and 8 columns but it show me Page unresponsive error and show me kill page or wait:
I've used following code.
function report_print()
{
date = time();
$myFile = "report_$date.csv";
$this->load->library('parser');
$stringData = $this->input->post('data');
$fileArray = $this->getdata($stringData);
$this->generateconvert_to_csv($fileArray, $myFile, ',');
die;
}
I have also tried to create CSV with jQuery with following code but it shows me error for " Network fail".
jQuery.fn.tableToCSV = function() {
var clean_text = function(text){
text = text.replace(/"/g, '""');
return '"'+text+'"';
};
$(this).each(function(){
var table = $(this);
var caption = $(this).find('caption').text();
var title = [];
var rows = [];
$(this).find('tr').each(function(){
var data = [];
$(this).find('th').each(function(){
var text = clean_text($(this).text());
title.push(text);
});
$(this).find('td').each(function(){
var text = clean_text($(this).text());
data.push(text);
});
data = data.join(",");
rows.push(data);
});
title = title.join(",");
rows = rows.join("\n");
var csv = title + rows;
var uri = 'data:text/csv;charset=utf-8,' + encodeURIComponent(csv);
var download_link = document.createElement('a');
download_link.href = uri;
var ts = new Date().getTime();
if(caption==""){
download_link.download = ts+".csv";
} else {
download_link.download = caption+"-"+ts+".csv";
}
document.body.appendChild(download_link);
download_link.click();
document.body.removeChild(download_link);
});
};
Anyone's Help will be appreciated for how to create a CSV with this much record without any issue ?
I've got this code that retrieve data from my SQL Data Base into my AS3 code.
My table (data base) has this rows : "id", "title", "price", "information", "mail".
In my AS3 code I loaded "title".
Php Code :
header('Content-type: application/json');
$ts = gmdate("D, d M Y H:i:s") . " GMT";
header("Expires: $ts");
header("Last-Modified: $ts");
header("Pragma: no-cache");
header("Cache-Control: no-cache, must-revalidate");
$num = mysql_numrows($sql_result);
$phptheTitle = "";
$obj = array();
while ($row = mysql_fetch_array($sql_result)) {
$theTitle = $row["theTitle"];
$phptheTitle = $phptheTitle.' </br> '.$theTitle;
$datas = array();
$datas['theTitle'] = $row["theTitle"];
$datas['prix'] = $row["prix"];
$obj[] = $datas;
}
echo json_encode( array('products' => $obj) );
mysql_free_result($sql_result);
mysql_close($connection);
?>
AS3 code :
function categorieSelected(evt:Event):void {
var urlReq:URLRequest = new URLRequest ("http://www.mywebsite.com/find_annonces.php");
urlReq.method = URLRequestMethod.POST;
var urlVars:URLVariables = new URLVariables();
urlReq.data = urlVars;
trace("typeSelected");
urlVars.categorie = evt.target.value;
trace(urlVars.categorie);
varLoader2.load(urlReq);
var loader:URLLoader = new URLLoader (urlReq);
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.load(urlReq);
trace(urlReq);
loader.addEventListener(Event.COMPLETE, loadComplete);
}
function loadComplete(evt:Event):void {
trace("loadComplete");
var myResult:String = evt.target.data;
trace(myResult);
output_txt.htmlText = myResult;
var datas :Object = JSON.parse( myResult );
var products :Array = datas && datas.products ? datas.products : [];
var len:int = products.length;
for( var i:int = 0; i<len; ++i ){
trace( products[i].title, products[i].price );
}
}
So my output_txt is displaying all items in the row "title".
Now, is it possible to create a link for each title(in AS3) ?
In order to display "price", "information", "mail" when we click on the title(each title has their own "price", "information" and "mail", contain in my database).
Exemple :
The AS3 code displays "Computer". When I click on "ipod Touch" it displays "price", "information" and "mail" that is contains in my database.
Here's a short video of what I'd like to do : http://sendvid.com/whdm4sjf
EDIT
So with the help of Aaron, the code works a little bit better.
In my AS3, the user can choose a "categorie" in order to displays all the titles contains in the categorie.
For that I've put this $categorie = $_POST['categorie']; in PHP
And this code in AS3
var loader5:URLLoader = new URLLoader();
var varLoader2:URLLoader = new URLLoader;
varLoader2.dataFormat=URLLoaderDataFormat.VARIABLES;
varLoader2.addEventListener(Event.COMPLETE,completeHandler2);
function categorieSelected(evt:Event):void {
var urlReq:URLRequest = new URLRequest ("http://www.brousse-en-folie.com/sondage/convertXML.php");
urlReq.method = URLRequestMethod.POST;
var urlVars:URLVariables = new URLVariables();
urlReq.data = urlVars;
trace("typeSelected");
urlVars.categorie = evt.target.value;
varLoader2.load(urlReq);
loader5.load(new URLRequest("http://www.brousse-en-folie.com/sondage/convertXML.php"));
loader5.addEventListener(Event.COMPLETE, complete);
}
But it seems that with the JSON loading, there is a conflict and I've got this error with the function categorieSelected
Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs.
Here's a short video of the problem : http://sendvid.com/18rr26rb
Here's a rough idea of what I would do:
Return all your data as XML or JSON. For example you can use PHP json_encode to return the SQL results as JSON.
Load the JSON into AS3 using URLLoader and JSON.parse.
Now you have an Array of data you can iterate over and display list items.
Add a click handler to each display list item that will hide the list, and show a detailed view.
You can accomplish this many ways, here's one simple example:
PHP
$products = array();
while ($row = mysql_fetch_array($sql_result)) {
$products[] = array(
"title" => $row["theTitle"],
"price" => $row["thePrice"]
);
}
echo json_encode($products);
Which should output valid JSON like this:
[
{
"title": "Product 1",
"price": 100
},
{
"title": "Product 2",
"price": 200
},
{
"title": "Product 3",
"price": 300
}
]
AS3
Load the JSON and render it out:
var products:Array;
var list:Sprite = new Sprite();
addChild(list);
var details:TextField = new TextField();
addChild(details);
var loader:URLLoader = new URLLoader();
loader.load(new URLRequest("products.php"));
loader.addEventListener(Event.COMPLETE, complete);
function complete(e:Event):void {
products = JSON.parse(loader.data) as Array;
for(var i:int = 0; i < products.length; i++){
createListItem(i, products[i]);
}
showList();
}
function createListItem(index:int, item:Object):void {
var listItem:TextField = new TextField();
listItem.text = item.title;
listItem.y = index * 20;
listItem.addEventListener(MouseEvent.CLICK, function(e:MouseEvent):void {
showDetails(item);
});
list.addChild(listItem);
}
function showList():void {
details.visible = false;
list.visible = true;
}
function showDetails(item:Object):void {
list.visible = false;
details.visible = true;
details.text = "Price: " + item.price + "\nInformation: " + item.information + "\nMail: " + item.mail;
}
This is just a rough start to give you an idea.
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 using google map api to show addresses on map with markers, the problem i am having is, In the marker, i am showing a link to go to the profile page of person which is there in the map, but if there are more than 1 person exists on same address then google group those addresses and doesn't show the link, is there any way we can stop grouping of addresses?
Any help would be appreciated.Thanks
<pre>
<script type="text/javascript">
var global =0;
//<![CDATA[
if (GBrowserIsCompatible()) {
var side_bar_html = "";
var gmarkers = [];
var htmls = [];
var i = 0;
var allIcon = new GIcon();
allIcon.image = "images/icons/<?php echo $map_category; ?>-all.png";
allIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
allIcon.iconSize = new GSize(35, 29);
allIcon.shadowSize = new GSize(37, 34);
allIcon.iconAnchor = new GPoint(9, 34);
allIcon.infoWindowAnchor = new GPoint(9, 2);
allIcon.infoShadowAnchor = new GPoint(18, 25);
allIcon.transparent = "http://www.google.com/intl/en_ALL/mapfiles/markerTransparent.png";
allIcon.printImage = "coldmarkerie.gif";
allIcon.mozPrintImage = "coldmarkerff.gif";
// An array of GIcons, to make the selection easier
var icons = [];
icons[0] = allIcon;
icons[1] = planIcon;
icons[2] = specialIcon;
var clusterIcon = new GIcon();
clusterIcon.image = 'images/icons/<?php echo $map_category; ?>-all.png';
clusterIcon.iconSize = new GSize( 30, 51 );
clusterIcon.shadowSize = new GSize( 56, 51 );
clusterIcon.iconAnchor = new GPoint( 13, 34 );
clusterIcon.infoWindowAnchor = new GPoint( 13, 3 );
clusterIcon.infoShadowAnchor = new GPoint( 27, 37 );
// A function to create the marker and set up the event window
function createMarker(point,name,html,cat,id) {
var marker = new GMarker(point,icons[cat]);
GEvent.addListener(marker, "click", function() {
rating_html = CallRating(<?php echo $page_id; ?>,id);
rating_html = decodeURI(rating_html);
marker.openInfoWindowHtml(html);
document.getElementById("rating_html_"+id+"").innerHTML=rating_html;
});
GEvent.addListener(marker, "dragstart", function() {
map.closeInfoWindow();
});
// save the info we need to use later for the side_bar
gmarkers[i] = marker;
htmls[i] = html;
// add a line to the side_bar html
if(i%2==0)
{
var sclass="even";
}
else
{
var sclass="odd";
}
side_bar_html += '<li class="'+sclass+'"><a href="javascript:myclick(' + i + ',' + id + ')" class="map_data mapdata-list">' + name + '<\/a></li>';
global=i;
i++;
return marker;
}
// This function picks up the click and opens the corresponding info window
function myclick(i,id) {
rating_html = CallRating(<?php echo $page_id; ?>,id);
rating_html = decodeURI(rating_html);
gmarkers[i].openInfoWindowHtml(htmls[i]);
document.getElementById("rating_html_"+id+"").innerHTML=rating_html;
}
// create the map
var map = new GMap(document.getElementById("map"));
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
//map.setMapType(G_SATELLITE_MAP);
map.setCenter(new GLatLng(<?php echo $emp_info['emp_latitude']; ?>, <?php echo $emp_info['emp_longitude']; ?>), 8);
// create the clusterer
var clusterer = new Clusterer(map);
// set the clusterer parameters if you dont like the defaults
clusterer.icon = clusterIcon;
clusterer.maxVisibleMarkers = 100;
clusterer.gridSize = 5;
clusterer.minMarkersPerClusterer = 5;
clusterer.maxLinesPerInfoBox = 6;
var rating_html="";
// Read the data
var request = GXmlHttp.create();
request.open("GET", "xml/<?php echo $org_id.'/emp/'.$emp_id.'/'.$map_category; ?>.xml", true);
request.onreadystatechange = function() {
if (request.readyState == 4) {
var xmlDoc = GXml.parse(request.responseText);
// obtain the array of markers and loop through it
var markers = xmlDoc.documentElement.getElementsByTagName("marker");
var i = 0;
for (i = 0; i < markers.length; i++) {
// obtain the attribues of each marker
var lat = parseFloat(markers[i].getAttribute("lat"));
var lng = parseFloat(markers[i].getAttribute("lng"));
var point = new GPoint(lng,lat);
var town = markers[i].getAttribute("town");
var name = markers[i].getAttribute("name");
var id = markers[i].getAttribute("id");
var cat = markers[i].getAttribute("cat");
var marker = createMarker(point,name,"<a href='<?php echo $url;?>="+id+"' target='_blank' class='map_data'>"+name+"</a><br>"+town+"<div id='rating_html_"+id+"'></div>",cat,id);
// create clusterer object
clusterer.AddMarker(marker,town);
}
// put the assembled side_bar_html contents into the side_bar div
if(side_bar_html=="")
{
document.getElementById("list_html").innerHTML = "<li>No data found! Please try again.</li>";
}
else
{
document.getElementById("list_html").innerHTML = side_bar_html;
gmarkers[global].openInfoWindowHtml(htmls[global]);
map.closeInfoWindow();
}
// Clear the "please wait" message
}
}
request.send(null);
}
else {
alert("Sorry, the Google Maps API is not compatible with this browser");
}
//]]>
</script>
</pre>
If you put multiple markers for single point, those will always overlap. It will be interesting to see if anyone can help you. I would suggest, when there are more than one people come under same place/marker, put their details/links on the infoWindow. Don't try to show multiple markers for same point. And if you are desperate enough to show multiple markers, then just change size of your marker-icons, so that they are visible to user even-if overlaps.
It is a good thing that google is showing all the relative address together otherwise if it wont, markers will be hidden by each other and you wont be able to see even how many markers are there on one place.
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;
}