[Tweener] Loading images via xml
Philip Ames
philco at thisworldover.com
Sat Oct 4 11:19:53 PDT 2008
Gerry, thank you. That works like a charm in "test scene", but I'm going
have to spend some time pulling it apart to understand.
The demo I'm trying to apply this to is the example I pulled down for
tweener, "box_list_scroll_as2_flash8.fla" (
http://tweener.googlecode.com/svn/trunk/examples), where the movie clip
instance "itemList" nested on the root.
In that example, the images are within "itemList" - all I was trying to do
was replace those images with the xml content.
Thanks again
you said...
> Since I had a couple of minutes I just threw this together that might
> help you out.
>
> I dragged a Loader component onto the stage to speed things up and
> then gave it an instance name of "my_ldr".
> This code is in the help files...I changed some things however.
>
> <code>
> /* on frame one of the main timeline */
> /* load images from xml */
>
> var doc:String = "images.xml";
> var startx:Number = 20;
> var starty:Number = 20;
> //loader
> var loaderListener:Object = new Object();
> loaderListener.progress = function(evt_obj:Object):Void {
> trace(evt_obj.type); // progress
> trace("\t" + evt_obj.target.bytesLoaded + " of " +
> evt_obj.target.bytesTotal + " bytes loaded");
> }
> loaderListener.complete = function(evt_obj:Object):Void {
> trace(evt_obj.type); // complete
> }
> my_ldr.addEventListener("progress", loaderListener);
> my_ldr.addEventListener("complete", loaderListener);
>
> //xml
> var myXML:XML = new XML();
> myXML.ignoreWhite=true;
> myXML.load(doc);
> myXML.onLoad = function(success) {
> if (success) {
> var myImage = myXML.firstChild.childNodes;
> for (var i:Number = 0; i<myImage.length; i++) {
> var imageNumber = i+1;
> var imageName:String = myImage[i].attributes.title;
> var imageURL:String = myImage[i].firstChild.nodeValue;
> trace ("Image number is "+imageNumber+", is titled "+imageName+"
> and is located in "+imageURL+".");
> //make a button to load image
> var _btn:MovieClip = drawRectangle(i,imageName,imageURL,100, 20,
> 0x333333, 100);
> _btn._x = startx;
> _btn._y = starty+(_btn._height+1) * i;
> }
> }
> };
> //rectangle
> function
> drawRectangle(nm:Number,txt:String,imageUrl:String,boxWidth:Number,
> boxHeight:Number, fillColor:Number, fillAlpha:Number):MovieClip {
>
> //this function creates a button with a text label and calls function
> to load image
> var img_btn:MovieClip = createEmptyMovieClip("img_btn"+nm,nm);
> var my_fmt:TextFormat = new TextFormat();
> my_fmt.color = 0xFFFFFF;
> my_fmt.font = "Arial";
> my_fmt.size = 12;
> // ("my_txt", 1, 100, 100, 300, 100);
> img_btn.createTextField("tf",1,1,1,98,18);
> img_btn.tf.type = "dynamic";
> img_btn.tf.multiline = false;
> img_btn.tf.text = txt;
> img_btn.tf.setTextFormat(my_fmt);
>
> with (img_btn) {
> beginFill(fillColor, fillAlpha);
> moveTo(0, 0);
> lineTo(boxWidth, 0);
> lineTo(boxWidth, boxHeight);
> lineTo(0, boxHeight);
> lineTo(0, 0);
> endFill();
> }
> img_btn.onRelease = function(){
> loadImg(imageUrl);
> }
>
> return img_btn;
> }
> //
> function loadImg(img:String):Void{
> my_ldr.load(img);
> trace("load image: "+img);
> }
>
> </code>
>
>
>
>
> On Oct 4, 2008, at 10:26 AM, Philip Ames wrote:
>
>> Hi Gerry, thanks for your response. I'm using AS2 but didn't get
>> much help
>> from the help section.
>>
>> I'm using the following slice of code to try and pull in the XML on
>> the
>> first frame of itemList, which is a child of the main stage...
>> ---------------------
>> var myXML:XML = new XML();
>> myXML.ignoreWhite=true;
>> myXML.load("images.xml");
>> myXML.onLoad = function(success) {
>> if (success) {
>> var myImage = myXML.firstChild.childNodes;
>> for (i=0; i<myImage.length; i++) {
>> var imageNumber = i+1;
>> var imageName = myImage[i].attributes.title;
>> var imageURL = myImage[i].firstChild.nodeValue;
>> trace ("Image number is "+imageNumber+", is titled "+imageName
>> +" and
>> is located in "+imageURL+".")
>> }
>> }
>> };
>> ---------------------
>> And my XML is set up...
>> ---------------------
>> <gallery>
>> <image title="image1">images/1.jpg</image>
>> <image title="image2">images/2.jpg</image>
>> <image title="image3">images/3.jpg</image>
>> <image title="image4">images/4.jpg</image>
>> <image title="image5">images/5.jpg</image>
>> </gallery>
>> ---------------------
>>
>> The trace returns everything it is supposed to, but the images do
>> not load.
>> I've checked the paths and they are correct.
>>
>> Any notions of what I'm doing wrong?
>>
>> Thanks in advance
>>
>>
>> _______________________________________________
>> Tweener mailing list
>> Tweener at lists.caurinauebi.com
>> http://lists.caurinauebi.com/listinfo.cgi/tweener-caurinauebi.com
>
> _______________________________________________
> Tweener mailing list
> Tweener at lists.caurinauebi.com
> http://lists.caurinauebi.com/listinfo.cgi/tweener-caurinauebi.com
More information about the Tweener
mailing list