Solved

How to display a php image array in different flash uiloaders

Posted on 2011-02-27
3
640 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
Comment Utility
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
Comment Utility
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
Comment Utility
Solution found by requester
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
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.
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.

743 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

18 Experts available now in Live!

Get 1:1 Help Now