Solved

How to display a php image array in different flash uiloaders

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
change password links 7 73
Online file editor, manager 6 59
Hacked File Timestamps 4 49
Whether to use true/false, yes/no or 0/1 11 51
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The goal of the tutorial is to teach the user how to how to record live broadcast.
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 …

910 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now