ColdSpringProductions
asked on
In ActionScript 3, how do I use a combo box to get images from a XML file?
Hello!
I am using a combo box to extract text and images from an XML file. I have the text part of the script working, but I've been unable to get the images to successfully come to stage. Any assistance is greatly appreciated.
I am using a combo box to extract text and images from an XML file. I have the text part of the script working, but I've been unable to get the images to successfully come to stage. Any assistance is greatly appreciated.
//import controls
import flash.net.*;
import fl.controls.ComboBox;
//var declarations
var xmlData:XML;
var classDataLoader:URLLoader = new URLLoader();
var classreqDataLoader:URLLoader = new URLLoader();
//loading xml data
classDataLoader.load(new URLRequest("classes.xml"));
classDataLoader.addEventListener(Event.COMPLETE,loadCompleteClass);
//function extracting data from xml
function loadCompleteClass(event:Event):void
{
xmlData = new XML(classDataLoader.data);
for (var i in xmlData.crclass)
{
cbClasses.addItem({label:xmlData.crclass.name[i]});
}
}
//EventListeners for combo box
cbClasses.addEventListener(Event.CHANGE, showReq);
//function populating text area
function showReq(event:Event):void
{
var itemSelected:Number = cbClasses.selectedIndex;
taReq.text = xmlData..requirement[itemSelected];
}
/*XML code:
<classes>
<crclass>
<name>Class 5</name>
<requirement>Bouffant Caps, Hoods, Beard Cover, Face Mask, Coveralls, Gloves, Shoe Covers, Booties</requirement>
<figure>file = "class5.png" width = "144" height = "415"</figure>
</crclass>
<crclass>
<name>Class 6</name>
<requirement>Bouffant Caps, Hoods, Beard Cover, Face Mask, Coveralls, Gloves, Shoe Covers, Booties</requirement>
<figure>file = "class6.png" width = "144" height = "415"</figure>
</crclass>
<crclass>
<name>Class 7 (Cleanroom)</name>
<requirement>Bouffant Caps, Hoods, Beard Cover, Face Mask, Coveralls, Gloves, Shoe Covers, Booties</requirement>
<figure>file = "class7cr.png" width = "144" height = "415"</figure>
</crclass>
<crclass>
<name>Class 7 (Benches)</name>
<requirement>Bouffant Caps or Hoods, Beard Cover, Face Mask, Smock, Gloves</requirement>
<figure>file = "class7bn.png" width = "144" height = "415"</figure>
</crclass>
<crclass>
<name>Class 7 (Vestibules)</name>
<requirement>Bouffant Caps or Hoods, Beard Cover or Face Mask, Smock, Gloves</requirement>
<figure>file = "class7vs.png" width = "144" height = "415"</figure>
</crclass>
<crclass>
<name>Class 8</name>
<requirement>Bouffant Caps, Beard Cover, Smock</requirement>
<figure>file = "class8.png" width = "144" height = "415"</figure>
</crclass>
</classes>
*/
ASKER
Well, the problem I'm having is that I can populate the text area okay, but I can't seem to figure out how to call the .pngs to the stage when a selection is made in the combo box. That's where I've been beating out my brains for the past two weeks.
ok, it doesn't look like you are loading the images at all. I was just looking at the directory structure, since I always screw myself up with that... sorry about that. But just to be safe, double check yours! Anyhow, try this.
Add a movieclip to the stage, give it an instance name of mySquare
add this to the showReq function:
loadMovie(xmlData..figure[ itemSelect ed], mySquare);
so it looks like this:
function showReq(event:Event):void
{
var itemSelected:Number = cbClasses.selectedIndex;
taReq.text = xmlData..requirement[itemS elected];
loadMovie(xmlData..figure[ itemSelect ed], mySquare);
}
That should be close. Let me know if it works
Add a movieclip to the stage, give it an instance name of mySquare
add this to the showReq function:
loadMovie(xmlData..figure[
so it looks like this:
function showReq(event:Event):void
{
var itemSelected:Number = cbClasses.selectedIndex;
taReq.text = xmlData..requirement[itemS
loadMovie(xmlData..figure[
}
That should be close. Let me know if it works
ASKER
Okay, I got two errors:
1046: Type was not found or was not a compile-time constant: mySquare
1180: Call to a possibly undefined method loadMovie
1046: Type was not found or was not a compile-time constant: mySquare
1180: Call to a possibly undefined method loadMovie
ASKER
I changed the properties on mySquare in that I deselected the Export for ActionScript option in Linkage.
Now I'm left with the 1180 error.
Now I'm left with the 1180 error.
my appologies, loadMovie() is for AS2. You need the loader() class.
I will see if I can sort out the function and post it a bit later, I am walking out the door to a meeting and will be back on later.
I will see if I can sort out the function and post it a bit later, I am walking out the door to a meeting and will be back on later.
ASKER
Any luck on finding how to use the loader() class for this case?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
No worries--I'll give it a try tomorrow.
I would say that you should make sure that the SWF, XML and images are all in the same directory since that is how you are calling it...