[Tweener] Loading images via xml
Philip Ames
philco at thisworldover.com
Sat Oct 4 15:08:37 PDT 2008
Wow Gerry, thank you so much. I even understand (a little) of what you did
but I¹m going to pour over it and try to break it now :). Thanks for your
help
you said...
> Ok I see...
> You could make something like that using different code but I whipped this
> together using those example
> files. The prev and next buttons have numbers in them because Zeh provided a
> sample that reuses the box
> movieClip. You can clean them up on your own but here is the adjusted fla that
> loads images from
> the xml and creates boxes for the amount of images in the xml.
> http://www.thespikeranch.com/filez/boxList_xml.zip
>
> -Gerry
>
>
>
> On Oct 4, 2008, at 2:19 PM, Philip Ames wrote:
>
>> 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
>>
>>
>> _______________________________________________
>> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.caurinauebi.com/pipermail/tweener-caurinauebi.com/attachments/20081004/8a61c25d/attachment-0001.htm>
More information about the Tweener
mailing list