Solved

How to display a php image array in different flash uiloaders

Posted on 2011-02-27
3
642 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to dynamically set the form action using jQuery.
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

773 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