I am trying to create a video that loads the videos stred in a directory, depenant on the users id etc.
To do this, I am using php. However, I cannot then get the php to convert to xml within the actionscript:
Here is php code:
$query = "SELECT * FROM video_files ORDER BY video_id DESC";
$resultID = mysql_query($query) or die("Data not found.");
$xml_output = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
$xml_output .= "<PLAYLIST VIDEO_X=\"0\" VIDEO_Y=\"0\" >\n";
for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){
$row = mysql_fetch_assoc($resultID);
$xml_output .= "<VIDEO TITLE=\"".$row['title']."\" THUMB=\"\" URL=\"".$row['path']."\"/>\n";
}
$xml_output .= "</PLAYLIST>";
echo $xml_output;
here is actionscript:
import fl.video.*;
var thumb_width:Number;
var thumb_height:Number;
var thumbs_x:Number;
var thumbs_y:Number;
var video_x:Number;
var video_y:Number;
var my_videos:XMLList;
var my_total:Number;
var main_container:Sprite;
var thumbs:Sprite;
var titles:Sprite;
var my_player:FLVPlayback;
var myXMLLoader:URLLoader = new URLLoader();
myXMLLoader.load (new URLRequest("playlist.php"));
myXMLLoader.addEventListener (Event.COMPLETE, processXML);
function processXML (e:Event):void {
var myXML:XML = new XML(e.target.data);
thumb_width = myXML.#THUMB_WIDTH;
thumb_height = myXML.#THUMB_HEIGHT;
thumbs_x = myXML.#THUMBS_X;
thumbs_y = myXML.#THUMBS_Y;
video_x = myXML.#VIDEO_X;
video_y = myXML.#VIDEO_Y;
my_videos = myXML.VIDEO;
my_total = my_videos.length();
makeContainers ();
callThumbs ();
makePlayer ();
}
function makeContainers ():void {
main_container = new Sprite();
addChild (main_container);
thumbs = new Sprite();
thumbs.addEventListener (MouseEvent.CLICK, playVideo);
thumbs.addEventListener (MouseEvent.MOUSE_OVER, onOver);
thumbs.addEventListener (MouseEvent.MOUSE_OUT, onOut);
thumbs.x = thumbs_x;
thumbs.y = thumbs_y;
thumbs.buttonMode = true;
main_container.addChild (thumbs);
titles = new Sprite();
titles.x = thumbs_x;
titles.y = thumbs_y;
main_container.addChild (titles);
}
function callThumbs ():void {
for (var i:Number = 0; i < my_total; i++) {
var thumb_url = my_videos[i].#THUMB;
var thumb_loader = new Loader();
thumb_loader.name = i;
thumb_loader.load (new URLRequest(thumb_url));
thumb_loader.contentLoaderInfo.addEventListener (Event.COMPLETE, thumbLoaded);
thumb_loader.y = (thumb_height+10)*i;
var thumb_title = my_videos[i].#TITLE;
var title_txt:TextField = new TextField();
title_txt.text = thumb_title;
title_txt.y = thumb_loader.y;
title_txt.x = thumb_width + 10;
title_txt.width = thumb_width;
title_txt.height = thumb_height;
title_txt.wordWrap = true;
titles.addChild (title_txt);
}
}
function thumbLoaded (e:Event):void {
var my_thumb:Loader = Loader(e.target.loader);
thumbs.addChild (my_thumb);
}
function makePlayer ():void {
my_player = new FLVPlayback();
my_player.skin ="videos/videoskin.swf";
my_player.skinBackgroundColor = 0xAEBEFB;
my_player.skinBackgroundAlpha = 0.9;
my_player.x = video_x;
my_player.y = video_y;
my_player.width = 500;
my_player.height = 400;
main_container.addChild (my_player);
my_player.source = my_videos[0].#URL;
}
function playVideo (e:MouseEvent):void {
var video_url = my_videos[e.target.name].#URL;
my_player.source = video_url;
}
function onOver (e:MouseEvent):void {
var my_thumb:Loader = Loader(e.target);
my_thumb.alpha = 0.5;
}
function onOut (e:MouseEvent):void {
var my_thumb:Loader = Loader (e.target);
my_thumb.alpha = 1;
}
anyone know where i am going wrong? It works with a normal xml file just not php
The format for your XML output in PHP is wrong. Every tag must be closed.
You have:
<?xml version="1.0" encoding="utf-8"?>
<PLAYLIST VIDEO_X="0" VIDEO_Y="0">
<VIDEO TITLE="videotitle" THUMB="thumbnail" URL="URL" />
</PLAYLIST>
You need to close the video tag. So output should look like this:
<?xml version="1.0" encoding="utf-8"?>
<PLAYLIST VIDEO_X="0" VIDEO_Y="0">
<VIDEO TITLE="videotitle" THUMB="thumbnail" URL="URL"></VIDEO>
</PLAYLIST>
You should also set the content-type for your PHP script.
header('Content-type: text/xml');
I don't have access to my laptop to thoroughly test your code, but this is my answer from a first glance at your code.
Related
I want to create an object in jquery using a json response that is return from my controller
var cellContents = {'29-08-2018': '20','18-08-2018': '60'};
This is the desired format that i want and below given is my json response
{"status":1,"result":[{"followup_datee":"17-08-2018","date":[{"fcount":"1"}]},{"followup_datee":"18-08-2018","date":[{"fcount":"1"}]}]}
i tried some code to make the format that i want but it failed this is the code that i tried
var arr2 = [];
//var cellContents = JSON.parse(data.result);
for(var i=0; i<data.result.length; i++){
var arr = [];
for(var j=0; j<data.result[i].date.length; j++)
{
arr.push(parseInt(data.result[i].date[j].fcount));
}
var test = [data.result[i].followup_datee];
arr2.push(test.concat(arr));
}
var jsonString = JSON.stringify(arr2);
console.log(jsonString);
after i tried this code i got some response in the console like this
[["17-08-2018",1],["18-08-2018",1]]
This is the controller that i am using in php
public function getLeadcount()
{
$status = 1;
$arr = [];
$sess = $this->session->userdata('user_id');
$result = $this->mdl_lead_registration->getLeaddate($sess);
if(!empty($result))
{
$status = 1;
foreach($result as $res)
{
$res->{'date'} = '';
$res->date = $this->mdl_lead_registration->getLeadcount($sess,$res->followup_datee);
}
}
echo json_encode(array("status" => $status,"result" => $result));
}
I think you all understand my problem . Any sort of help is appreciable.
Use the following code:
var data = {"status":1,"result":[{"followup_datee":"17-08-2018","date":[{"fcount":"1"}]},{"followup_datee":"18-08-2018","date":[{"fcount":"1"}]}]};
var obj = {};
for (var i = 0; i < data.result.length; i++){
obj[data.result[i].followup_datee] = parseInt(data.result[i].date[0].fcount);
// Here you change the property.
// In js you can access to an object's property like an array,
// see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_Accessors.
// If you want to use the count as a string, use instead:
// obj[data.result[i].followup_datee] = data.result[i].date[0].fcount;
}
console.log(obj);
I am trying to import all the data from csv to the database.
Below code is ajax request that is sent to a php file.
$('#upload_location_csv').click(function(e){
e.preventDefault();
var queryDict = {};
location.search.substr(1).split("&").forEach(function(item) {queryDict[item.split("=")[0]] = item.split("=")[1]});
fi = document.getElementById("csv_file_input").files[0];
reader = new FileReader;
reader.onload = function(){
csv_data = reader.result;
$.ajax({
type:"post",
url:ajax_root_path+'fend.php',
data:{
location_id:queryDict['id'],
csv_data:csv_data,
perform_action:"save_delivery_csv_data"
},
success:function(resObj){
window.location.reload();
},
error:function(resObj){
}
});
};
reader.readAsText(fi);
});
This is the action that is performed, where here is, save_delivery_csv_data .
When I click on import csv, the page reloads and no request is sent to fend.php.
case 'save_delivery_csv_data':
{
$location_id = $param_array['location_id'];
$csv_data = $param_array['csv_data'];
$csv_data_rows = explode("\n",$csv_data);
unset($csv_data_rows[0]);
$csv_data_rows = array_values($csv_data_rows);
debug($csv_data_rows);
$csv_data_array = array();
foreach ($csv_data_rows as $csv_row_key => $csv_row_value)
{
$csv_row_value_array = explode(",",$csv_row_value);
debug($csv_row_value_array);
if(count($csv_row_value_array) == 5)
{
/*$csv_data_array[$csv_row_key] = array();
$csv_data_array[$csv_row_key]['locality_id'] = $csv_row_value_array[0];
$csv_data_array[$csv_row_key]['locality_name'] = $csv_row_value_array[1];
$csv_data_array[$csv_row_key]['minimum_order_amount'] = $csv_row_value_array[2];
$csv_data_array[$csv_row_key]['delivery_time'] = $csv_row_value_array[3];
$csv_data_array[$csv_row_key]['delivery_charge'] = $csv_row_value_array[4];*/
//debug($csv_row_value_array);
if(isset_empty($csv_row_value_array[3]))
{
//debug($csv_row_value_array);
$locality_id = $csv_row_value_array[0];
$location_outletValues = array();
$location_outletValues['cloud_site_id'] = $cloud_site_id;
$location_outletValues['location_id'] = $location_id;
$location_outletValues['locality_id'] = $locality_id;
$location_outletValues['minimum_order'] = $csv_row_value_array[2];
$location_outletValues['delivery_time'] = $csv_row_value_array[3];
$location_outletValues['delivery_charge'] = $csv_row_value_array[4];
$sql = "SELECT outlet_locality_id FROM ".PLATFORM_OUTLET_LOCALITIES."
WHERE location_id='".$location_id."' AND locality_id='".$locality_id."'";
$outlet_locality_array = $DB->query($sql);
//debug($outlet_locality_array);
if(count($outlet_locality_array) > 0)
{
$condition_array = array();
$condition_array['outlet_locality_id'] = $outlet_locality_array[0]->outlet_locality_id;
//debug($condition_array);
debug($location_outletValues);
$DB->update(PLATFORM_OUTLET_LOCALITIES,$location_outletValues,$condition_array);
}
else
{
$DB->insert(PLATFORM_OUTLET_LOCALITIES,$location_outletValues);
}
}
}
}
break;
//debug($csv_data_array);
}
What am I missing out here?? I also tried debugging variables values, but no request was sent to fend.php, whereas other request on the same page are being successfully sent.
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 have been playing with the Google maps trying to make a tour and save the start end and the way points in a database.
here is the java-script code that i use to pass the values
function saveRoute() {
var name = "<?php Print($log_username);?>";
var waypts = [];
var end = points.length-1;
var dest = points[end].LatLng;
if (document.getElementById("roundTrip").checked) {
end = points.length;
dest = points[0].LatLng;
}
data.start = {'lat': points[0].LatLng.lat(), 'lng': points[0].LatLng.lng()}
data.end = {'lat': dest.lat(), 'lng':dest.lng()}
for (var i=1; i<end; i++) {
waypts[i-1] = [points[i].LatLng.lat(),points[i].LatLng.lng()]
data.waypoints = waypts;
}
var str = JSON.stringify(data)
var jax = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
jax.open('POST','process.php');
jax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
jax.send('command=save&mapdata='+str)
jax.onreadystatechange = function(){ if(jax.readyState==4) {
if(jax.responseText.indexOf('bien')+1)alert('Updated');
else alert(jax.responseText)
}}
}
here is my php processing.php
<?
ob_start();
header('Cache-Control: no-store, no-cache, must-revalidate');
$data = $_REQUEST['mapdata'];
echo $data;
mysql_connect('localhost','root','');
mysql_select_db('mapdir');
if($_REQUEST['command']=='save')
{
$query = "update mapdir set value='$data'";
if(mysql_query($query))die('bien');
die(mysql_error());
}
if($_REQUEST['command']=='fetch')
{
$query = "select value from mapdir";
if(!($res = mysql_query($query)))die(mysql_error());
$rs = mysql_fetch_array($res,1);
die($rs['value']);
}
?>
i always get the ajax response as "updated" but nothing happens to the database
where i have gone wrong ?
I Am trying to add data into a combo box named combo_assembly using Ajax..
The Function is:
function populate_combo_assembly(xmlindata) {
var xmldata = xmlindata.getElementsByTagName('Assemblies');
if(xmldata.length <= 0) {
alert("Data Unavailable");
return;
}
window.document.getElementById('combo_assembly').options.length = 0;
var firstOption = new Option('--Please select--', '', false, false);
window.document.getElementById('combo_assembly').options.add(firstOption);
for(var i =0; i <= xmldata.length; i++) {
var typename = '';
var x,y;
x = xmlindata.getElementsByTagName('name')[i];
y = x.childNodes[0];
typename = y.nodeValue;
var newOption = new Option(typename, typename, false, false);
window.document.getElementById('combo_assembly').options.add(newOption);
}
window.document.getElementById('combo_assembly').disabled = false;
}
And taking The values from a file..Code is:
<?php
include("database/dbconfig.inc.php");
header("Content-type: text/xml");
echo "<?xml version=\"1.0\" ?>\n";
echo "<Assemblies>\n";
$select = "SELECT * FROM assembly";
try {
foreach($dbh->query($select) as $row) {
echo "<Assembly>\n<name>".$row['name']."</name>\n<id>".$row['id']."</id>\n<category>".$row['category']."</category>\n</Assembly>\n";
}
}
catch(PDOException $e) {
echo $e->getMessage();
die();
}
echo "</Assemblies>";
?>
THe problem is that this xml file is taking all the contents I from the database table. But the function is taking only the first two values from the xml code.
The Output of xml file
<Assemblies>
<Assembly>
<name>total</name>
<id>A00000</id>
<category>Brake</category>
</Assembly>
<Assembly>
<name>asd</name>
<id>A00001</id>
<category>Brake</category>
</Assembly>
<Assembly>
<name>ga</name>
<id>ga</id>
<category>Suspension</category>
</Assembly>
<Assembly>
<name>65</name>
<id>r00</id>
<category>Brake</category>
</Assembly>
<Assembly>
<name>yty</name>
<id>tyt</id>
<category>Suspension</category>
</Assembly>
<Assembly>
<name>Gaurav</name>
<id>Z0012</id>
<category>Brake</category>
</Assembly>
</Assemblies>
Thanks In advance for help.
You are retrieving the xmldata as
var xmldata = xmlindata.getElementsByTagName('Assemblies');
Shouldn't that be
var xmldata = xmlindata.getElementsByTagName('Assembly');
As the information is not contained in the wrapper element .