[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to display a php image array in different flash uiloaders

Posted on 2011-02-27
3
Medium Priority
?
647 Views
Last Modified: 2013-11-11
I am stuck on the following problems:

Problem 1:
How do I display a php array of blob images in multiple flash uiloaders using as3?

Php Code:
<?php
//connected to database

//Selecting the Table
$sql = "SELECT IMG FROM Product"; 
$result = mysql_query($sql)  or die("Invalid query: " . mysql_error());
mysql_close($link);

//Loop through the IMG column in the Product table
while ($display = mysql_fetch_array($result, MYSQL_ASSOC)) {
$show = $display["IMG"];

//code allows the image to display
header("Content-type: image/png");  
echo $show;
}
?>

Open in new window


Problem 2:
The php file above returns an array so I am assuming I don't need to convert but my assumptions are probably wrong. How can I load the data from the php code to my as3 code?

AS3 Code:
var imagePHP:String = "/scripts/imgView.php";
var subLoad:URLRequest = new URLRequest(imagePHP);
var mainLoad:URLLoader = new URLLoader(subLoad);
mainLoad.addEventListener(Event.COMPLETE, done);

function done(e:Event):void
{
	for(var i = 0; i < count; i++) {
	//7 UILoaders to hold the first 7 images from database
		Product1.load(mainLoad[i]);
		Product2.load(mainLoad[i]);
		Product3.load(mainLoad[i]);
		Product4.load(mainLoad[i]);
		Product5.load(mainLoad[i]);
		Product6.load(mainLoad[i]);
		Product7.load(mainLoad[i]);		
	}
}

Open in new window

0
Comment
Question by:eager_to_learn
  • 2
3 Comments
 
LVL 20

Expert Comment

by:ChristoferDutz
ID: 34995019
Well I have to admit that I have doubts that sending multiple images this way will actually work. Flash has no means to spit this one big image-data-block up.

I do things like this using AMF and sending multiple byte-Arrays containing the image data. In ActionScript I get an Array of ByteArrays. I manually create one Image for each ByteArray and set the source property of the Image to one of these ByteArrays.

Works great.
0
 

Accepted Solution

by:
eager_to_learn earned 0 total points
ID: 35041388
Thanks ChristoferDutz for helping.

I read through another forum with a similar question. After a few tweaks I finally enabled the images
to load in separate UILoaders. I hope this may help others with the same question.

//holder for new XML file
var xml:XML = new XML();
//holder for the count of the XML file children
var imgCount:uint;
//holder for the new URLLoader
var loader:URLLoader = new URLLoader();
//load a URLRequest into the new URLloader. This is the php file
//that holds the database info
loader.load(new URLRequest('ImageLoad.php'));
//listen for the end of the loader url request
loader.addEventListener(Event.COMPLETE, xmlLoaded);
//initiate the xmlLoaded function when the file upload ends
function xmlLoaded(Event):void {
	//holder for the xml strings
	xml = XML(loader.data);
	//List of children from the xml file
	var pick:XMLList = xml.img;
	//counts the children of the xml file
	imgCount = xml.img.length();
	//loops through the children of the xml file	
	for(var i:int = 0; i < imgCount; i++){
	//displays the children in seperate UILoaders 1 through 7. The thumburl is a label from 
                     //the xml file (<img thumburl = 'image path'/>)
	Position1.scaleContent = true;
                     Position1.source = pick[0].@thumburl;
	Position2.scaleContent = true;
	Position2.source = pick[1].@thumburl;
	Position3.scaleContent = true;
	Position3.source = pick[2].@thumburl;
	Position4.scaleContent = true;
	Position4.source = pick[3].@thumburl;
	Position5.scaleContent = true;
	Position5.source = pick[4].@thumburl;
	Position6.scaleContent = true;
	Position6.source = pick[5].@thumburl;
	Position7.scaleContent = true;
	Position7.source = pick[6].@thumburl;
    		
	}
	removeEventListener(Event.COMPLETE, xmlLoaded);
	}

Open in new window

0
 

Author Closing Comment

by:eager_to_learn
ID: 35081130
Solution found by requester
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.
Suggested Courses
Course of the Month17 days, 17 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question