Solved

How to display a php image array in different flash uiloaders

Posted on 2011-02-27
3
644 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

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 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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

724 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