# Cant convert XMLList to DisplayObject

**URL:** <https://forum.kirupa.com/t/cant-convert-xmllist-to-displayobject/264534>\
**Category:** Uncategorized\
**Created:** [June 26, 2008, 9:59pm UTC](https://forum.kirupa.com/t/cant-convert-xmllist-to-displayobject/264534 "2008-06-26T21:59:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![rondog](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/rondog/32/2478_2.png) [@rondog](https://forum.kirupa.com/u/rondog)\
**Post date:** [June 26, 2008, 9:59pm UTC](https://forum.kirupa.com/t/cant-convert-xmllist-to-displayobject/264534/1 "2008-06-26T21:59:50Z")

</div>

I have a slideList being populated by XML. Its datascource is just an ID. I added an event listener when you rollOver the listItem. I keep getting this error

```auto

TypeError: Error #1034: Type Coercion failed: cannot convert XMLList@359defb1 to flash.display.DisplayObject.
    at Vforum/::showThumb()
    at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at fl.controls::SelectableList/fl.controls:SelectableList::handleCellRendererMouseEvent()
Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL: file:///E|/New%20Vforum%20AS3/data/slide01.jpg
    at Vforum$iinit()

```

the problem resides in my showThumb function…anyone know whats up?

```auto

package 
{
    import flash.text.TextField;
    import flash.display.MovieClip;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.errors.*;
    import flash.events.*;
    import fl.events.ListEvent;

    public class Vforum extends MovieClip
    {
        private static const MEDIAPATH:String = "data/";
        private static const PADNUM:String = "01_";
        private static const SLIDESCALE:Number = 0.7;

        private var xmlData:XML;
        private var xmlLoader:URLLoader = new URLLoader();
        private var thumbLoader:URLLoader = new URLLoader();
        private var xmlList:XMLList;

        public function Vforum():void
        {
            var xmlSource:String = xmlSheet.text;
            xmlLoader.addEventListener(Event.COMPLETE, onComplete);
            xmlLoader.load(new URLRequest(MEDIAPATH + xmlSource));
            slideList.addEventListener(ListEvent.ITEM_ROLL_OVER, showThumb);
            //slideList.addEventListener(ListEvent.ITEM_CLICK, showData);
            //slideList.addEventListener(ListEvent.ITEM_ROLL_OUT, showOrigThumb);
        }
        private function onComplete(e:Event):void
        {
            xmlData = new XML(xmlLoader.data);
            xmlList = new XMLList(xmlData..Slide);
            for (var i:uint = 0; i < xmlList.length(); i++)
            {
                var title = xmlList*.Title;
                var slideID = xmlList*.@id;
                var bgSwf = xmlList*.BGSwf;
                var swfFile = xmlList*.SwfFile;
                var slideText = xmlList*.SlideText;
                slideList.addItem({label:slideID + ". " + title, data:slideID});
            }
        }
        private function showThumb(e:ListEvent):void
        {
            var thumb = e.item.data;
            if (thumb >= 10)
            {
                thumbLoader.load(new URLRequest(MEDIAPATH + "slide" + thumb + ".jpg"));
            } else
            {
                thumbLoader.load(new URLRequest(MEDIAPATH + "slide0" + thumb + ".jpg"));
            }
            thumbs.addChild(thumb);
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![sekasi](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@sekasi](https://forum.kirupa.com/u/sekasi)\
**Post date:** [June 26, 2008, 10:14pm UTC](https://forum.kirupa.com/t/cant-convert-xmllist-to-displayobject/264534/2 "2008-06-26T22:14:36Z")

</div>

A general thing about your code: Typing/(Casting) your variables will have a significant positive imprint on performance. (var i:int instead of var i … etc)

That being said, try this

var thumb : DisplayObject = e.item.data as DisplayObject;

---

<div class="post-metadata">

**Author:** ![rondog](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/rondog/32/2478_2.png) [@rondog](https://forum.kirupa.com/u/rondog)\
**Post date:** [June 26, 2008, 10:27pm UTC](https://forum.kirupa.com/t/cant-convert-xmllist-to-displayobject/264534/3 "2008-06-26T22:27:05Z")

</div>

ok I got past that error…thanks Sekasi, however, I am running into another problem. I am getting this error:

```auto

TypeError: Error #2007: Parameter child must be non-null.
	at flash.display::DisplayObjectContainer/addChild()
	at Vforum/::showThumb()
	at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
	at flash.events::EventDispatcher/dispatchEvent()
	at fl.controls::SelectableList/fl.controls:SelectableList::handleCellRendererMouseEvent()
TypeError: Error #2007: Parameter child must be non-null.
	at flash.display::DisplayObjectContainer/addChild()
	at Vforum/::showThumb()
	at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
	at flash.events::EventDispatcher/dispatchEvent()
	at fl.controls::SelectableList/fl.controls:SelectableList::handleCellRendererMouseEvent()
Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL: file:///E|/New%20Vforum%20AS3/data/slide0null.jpg

```

so it is reading

var thumb

as a null value. Any idea why?

---

<div class="post-metadata">

**Author:** ![rondog](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/rondog/32/2478_2.png) [@rondog](https://forum.kirupa.com/u/rondog)\
**Post date:** [June 26, 2008, 10:29pm UTC](https://forum.kirupa.com/t/cant-convert-xmllist-to-displayobject/264534/4 "2008-06-26T22:29:08Z")

</div>

sorry, here is my most updated code:

```auto

		private function showThumb(e:ListEvent):void
		{
			var thumb:DisplayObject = e.item.data as DisplayObject;
			trace(thumb);
			if (e.item.data >= 10)
			{
				thumbLoader.load(new URLRequest(MEDIAPATH + "slide" + thumb + ".jpg"));
			} else
			{
				thumbLoader.load(new URLRequest(MEDIAPATH + "slide0" + thumb + ".jpg"));
			}
			thumbs.addChild(thumb);
		}

```

---

<div class="post-metadata">

**Author:** ![rondog](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/rondog/32/2478_2.png) [@rondog](https://forum.kirupa.com/u/rondog)\
**Post date:** [June 26, 2008, 10:49pm UTC](https://forum.kirupa.com/t/cant-convert-xmllist-to-displayobject/264534/5 "2008-06-26T22:49:07Z")

</div>

arrggh…I think im going about this the wrong way…I just want to load a jpg into the thumbs movieclip…Can you suggest a better way to do this? My new code looks like this:

```auto

			private function showThumb(e:ListEvent):void
		{
			var id:Number = e.item.data;
			if (e.item.data >= 10)
			{
				thumbToLoad = MEDIAPATH + "slide" + id + ".jpg";
			} else
			{
				thumbToLoad = MEDIAPATH + "slide0" + id + ".jpg";
			}
			var toLoad = thumbLoader.load(new URLRequest(thumbToLoad));
			thumbs.addChild(toLoad);
		}

```

and tracing thumbToLoad is the correct path I want to load, but I guess im stuck at that point.

---

<div class="post-metadata">

**Author:** ![Anogar](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@Anogar](https://forum.kirupa.com/u/Anogar)\
**Post date:** [June 26, 2008, 11:02pm UTC](https://forum.kirupa.com/t/cant-convert-xmllist-to-displayobject/264534/6 "2008-06-26T23:02:52Z")

</div>

You need to add the loader to the stage, not the XMLList. An XMLList is just a big chunk of data, I’m not sure what you thought was going to happen when you attached it, but it’s not going to work. That’s like trying to add a String or a Number to the stage.

---

<div class="post-metadata">

**Author:** ![rondog](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/rondog/32/2478_2.png) [@rondog](https://forum.kirupa.com/u/rondog)\
**Post date:** [June 26, 2008, 11:18pm UTC](https://forum.kirupa.com/t/cant-convert-xmllist-to-displayobject/264534/7 "2008-06-26T23:18:40Z")

</div>

post #4 I can understand your explanation, but my most recent post was adding the loader to my stage.
