# AS3 XML gallery problems

**URL:** <https://forum.kirupa.com/t/as3-xml-gallery-problems/271559>\
**Category:** flash\
**Created:** [September 24, 2008, 5:02pm UTC](https://forum.kirupa.com/t/as3-xml-gallery-problems/271559 "2008-09-24T17:02:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![beeza](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@beeza](https://forum.kirupa.com/u/beeza)\
**Post date:** [September 24, 2008, 5:02pm UTC](https://forum.kirupa.com/t/as3-xml-gallery-problems/271559/1 "2008-09-24T17:02:30Z")

</div>

Hi all, first post here - have posted the same topic over at goto forums, but thought i would see if I could get some more feedback here…

Currently I am working on a gallery that generates x15 thumbnails onto the stage, through a loader & URL request. (returns product search results from a database) This works great & I have 15 ‘items’ from the search display randomly on the stage, all scripted in the **baseClass**.

The idea originally was to have these ‘items’ load into a thumbnail movieclip I have created in my library, but have no idea how to do this.  
I have another class called **PostElement** that adds interactivity to the thumbnail movieclip which I applied through the linkage menu.

So the question is whether I should attempt to load these ‘items’ into my thumbnail mc & if this is even possible in AS3.  
(as seen in AS2 XML galleries: \_root.Frame.Pic.load(images\_path[0].attributes.title); …)  
**OR** should I try (which I have, see below) and instantiate the **PostElement** class in the **baseClass** in the hope to give the loaded images the interactivity of that class? (although I still have no visual holder for the images)

I’ve attached both classes, when I run the code i’m getting the error:  
// Error #1009:The access to a attribute or a method of a null-object reference is not possible.  
// at baseClass/::onLoadComplete()  
// at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()  
// at flash.events::EventDispatcher/dispatchEvent()  
// at [flash.net](http://flash.net)::URLLoader/flash.net:URLLoader::onComplete()

Here is the full code for the **baseClass** (the document class)

```auto
package 
{
   import PostElement; // <--- do i need to import this class?
   import flash.display.*;
   import flash.net.*;
   import flash.events.*;
   
   public class baseClass extends MovieClip 
   {
      var myLoader:URLLoader = new URLLoader();
      var myURL = new URLRequest("http://itemsearchexample....");
      var myXML:XML;
      
      public function baseClass() 
      {
      myLoader.load(myURL);
      myLoader.addEventListener(Event.COMPLETE, onLoadComplete);
      }
      
      function onLoadComplete(e:Event):void 
      {
         myXML.ignoreComments = true;
         myXML.ignoreWhitespace = true;
         
         myXML = new XML(e.target.data);
               
         var i:Number;
         var url:String;
               
         for (i = 0; i < myXML.Items.Item.length(); i++) 
            
         {
            var loader:Loader = new Loader();
                       
            url = myXML.Items.Item*.SmallImageExtracted.URL.text();
            loader.load(new URLRequest(url));
                  
            // instantiating postelement --> correct?
            var thumbnail:PostElement = new PostElement();
                  
            // syntax for stage.stageWidth & stage.stageHeight updated
            thumbnail.x = Math.random() * (stage.stageWidth - 10);
            thumbnail.y = Math.random() * (stage.stageHeight - 10);
            thumbnail.rotation = 78;
                  
            //adding the thumbnail with the loader inside
            thumbnail.addChild(loader);
            stage.addChild(thumbnail);
                                             
            // trace(loader);
            // trace(this.x);
         }
      }
   }
}

```

And the full (simplified) code for the **PostElement**

```auto
package 
{
   import flash.display.*;
   import flash.events.*;
   
   public class PostElement extends MovieClip 
   {
   
      public function PostElement() 
      {
         addEventListener(MouseEvent.MOUSE_DOWN, downHandler);
         stage.addEventListener(MouseEvent.MOUSE_UP, upHandler);
      }
      
      public function downHandler(event:MouseEvent):void 
      {
         startDrag();            
      }
      public function upHandler(event:MouseEvent):void 
      {
         stopDrag();
      }
   }
}

```

Hope this is easy to understand, i’m still very new at this programming business  
thanks in advance!
