Flash CS3 - Flash CS4

Free tutorials and scripts for all.
Actionscript 3.0

xml gallery

This is a discussion on xml gallery within the Actionscript 3.0 newbies forums, part of the Flash CS3 eng category; I'm relatively new to this and having a difficult time. I'm trying to build an image gallery with ...


Go Back   Forum Flash CS3 Flash CS4 > English Forums > Flash CS3 eng > Actionscript 3.0 newbies

Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-03-08, 01:13
Junior Member
 
Join Date: Mar 2008
Posts: 4
Rep Power: 0
z1784 is on a distinguished road
xml gallery

I'm relatively new to this and having a difficult time. I'm trying to build an image gallery with xml that has 2 columns of thumbnails to pick from. Once I have that though, the remove child function is causing havoc by deleting the bottom thumbnails and still allowing the images from the other column to remain on the stage-stacking up.

If anyone could help me build the thumbnails this way from one xml doc or tell me how to better remove the image from the stage while loading the next one clicked, I would be very appreciative.

Code:
var imageLoader:Loader;
var xml:XML;
var xmlList:XMLList;
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.load(new URLRequest("images.xml"))

xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);

function xmlLoaded(event:Event):void

{
    xml = XML(event.target.data);
    xmlList = xml.children();
    
    for(var i:int = 0; i < xmlList.length(); i++)
    {
        imageLoader = new Loader();
        imageLoader.load(new URLRequest(xmlList[i].attribute("thumb")));
        imageLoader.x = 5;
        imageLoader.y = i * 70 + 5;
        imageLoader.name = xmlList[i].attribute("source")
        addChild(imageLoader);
        imageLoader.addEventListener(MouseEvent.CLICK, showPicture);
    }
}

function showPicture(event:MouseEvent):void
{
    removeChild(imageLoader);
    imageLoader = new Loader();
    imageLoader.load(new URLRequest(event.target.name));
    imageLoader.x = 200;
    addChild(imageLoader);

    
}

var imageLoader2:Loader;
var xml2:XML;
var xmlList2:XMLList;
var xmlLoader2:URLLoader = new URLLoader();
xmlLoader2.load(new URLRequest("images2.xml"))

xmlLoader2.addEventListener(Event.COMPLETE, xmlLoaded2);

function xmlLoaded2(event:Event):void

{
    xml2 = XML(event.target.data);
    xmlList2 = xml2.children();
    
    for(var j:int = 0; j < xmlList2.length(); j++)
    {
        imageLoader2 = new Loader();
        imageLoader2.load(new URLRequest(xmlList2[j].attribute("thumb")));
        imageLoader2.x = 70;
        imageLoader2.y = j * 70 + 5;
        imageLoader2.name = xmlList2[j].attribute("source")
        addChild(imageLoader2);
        imageLoader2.addEventListener(MouseEvent.CLICK, showPicture2);
    }
}

function showPicture2(event:MouseEvent):void
{
    removeChild(imageLoader2);
    imageLoader2 = new Loader();
    imageLoader2.load(new URLRequest(event.target.name));
    imageLoader2.x = 200;
    addChild(imageLoader2);

    
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #2 (permalink)  
Old 13-03-08, 12:04
Administrator
 
Join Date: Jul 2007
Location: Cesena
Posts: 4,350
Blog Entries: 1
Rep Power: 6
Flep is on a distinguished road
Re: xml gallery

Hi and welcome

Before you remove a Loader, check if it is null:
Code:
if(imageLoader2!=null)
     removeChild(imageLoader2)
;
__________________

 


I recommend: Essential Actionscript 3.0

- Non rispondo ai messaggi privati con domande tecniche. Apri una discussione sul forum !
- I do not reply technicians pvt messages. Open a thread !
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 13-03-08, 23:16
Junior Member
 
Join Date: Mar 2008
Posts: 4
Rep Power: 0
z1784 is on a distinguished road
Re: xml gallery

Thanks. I tried what you added, but I'm still having some problems. The bottom thumbnails are still disappearing and the each column properly removes an image when another image in the column is clicked, but crossing to the other column causes the images to stack up on the stage. I really appreciate your looking at this.


Here's what I tried:

Code:
var imageLoader:Loader;
var xml:XML;
var xmlList:XMLList;
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.load(new URLRequest("images.xml"))

xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);

function xmlLoaded(event:Event):void

{
    xml = XML(event.target.data);
    xmlList = xml.children();
    
    for(var i:int = 0; i < xmlList.length(); i++)
    {
        imageLoader = new Loader();
        imageLoader.load(new URLRequest(xmlList[i].attribute("thumb")));
        imageLoader.x = 5;
        imageLoader.y = i * 70 + 5;
        imageLoader.name = xmlList[i].attribute("source")
        addChild(imageLoader);
        imageLoader.addEventListener(MouseEvent.CLICK, showPicture);
    }
}

function showPicture(event:MouseEvent):void
{
   if(imageLoader2!=null)
     removeChild(imageLoader2)
    if(imageLoader!=null)
     removeChild(imageLoader)
    imageLoader = new Loader();
    imageLoader.load(new URLRequest(event.target.name));
    imageLoader.x = 200;
    addChild(imageLoader);
    addChild(imageLoader2);

    
}

var imageLoader2:Loader;
var xml2:XML;
var xmlList2:XMLList;
var xmlLoader2:URLLoader = new URLLoader();
xmlLoader2.load(new URLRequest("images2.xml"))

xmlLoader2.addEventListener(Event.COMPLETE, xmlLoaded2);

function xmlLoaded2(event:Event):void

{
    xml2 = XML(event.target.data);
    xmlList2 = xml2.children();
    
    for(var j:int = 0; j < xmlList2.length(); j++)
    {
        imageLoader2 = new Loader();
        imageLoader2.load(new URLRequest(xmlList2[j].attribute("thumb")));
        imageLoader2.x = 70;
        imageLoader2.y = j * 70 + 5;
        imageLoader2.name = xmlList2[j].attribute("source")
        addChild(imageLoader2);
        imageLoader2.addEventListener(MouseEvent.CLICK, showPicture2);
    }
}

function showPicture2(event:MouseEvent):void
{
   if(imageLoader!=null)
     removeChild(imageLoader)
    if(imageLoader2!=null)
     removeChild(imageLoader2) 
    imageLoader2 = new Loader();
    imageLoader2.load(new URLRequest(event.target.name));
    imageLoader2.x = 200;
    addChild(imageLoader2);
    addChild(imageLoader);

    
}
If I didn't add the second addChild to each function, it returned an error for it being undefined.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 14-03-08, 02:47
Junior Member
 
Join Date: Mar 2008
Posts: 4
Rep Power: 0
z1784 is on a distinguished road
Re: xml gallery

I spent much of the evening trying to figure this out, and I'm wondering if I'm asking the wrong question. Is there a way to have flash pull my ten thumbnails from the xml and arrange them into two columns? Right now, I'm using two xml documents and using different x values for each to simulate this. When I just use one, I can easily load and unload the images, so it feels like my problem comes from using two xml docs.

Thanks for your help.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 15-03-08, 16:12
Administrator
 
Join Date: Jul 2007
Location: Cesena
Posts: 4,350
Blog Entries: 1
Rep Power: 6
Flep is on a distinguished road
Re: xml gallery

Have a look to this sample and try to change the var columns value:
Attached Files
File Type: fla dispose.fla (55.4 KB, 51 views)

__________________

 


I recommend: Essential Actionscript 3.0

- Non rispondo ai messaggi privati con domande tecniche. Apri una discussione sul forum !
- I do not reply technicians pvt messages. Open a thread !
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

photoFlow

  #6 (permalink)  
Old 16-03-08, 01:17
Junior Member
 
Join Date: Mar 2008
Posts: 4
Rep Power: 0
z1784 is on a distinguished road
Re: xml gallery

It worked great. Thanks so much.

Here's the code I used:

Code:
var imageLoader:Loader;
var xml:XML;
var xmlList:XMLList;
var xmlLoader:URLLoader = new URLLoader();


var numClips:int=10;
var columns:int=2;




xmlLoader.load(new URLRequest("images.xml"))
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);

function xmlLoaded(event:Event):void
{
    xml = XML(event.target.data);
    xmlList = xml.children();
    
 for(var i:int = 0; i < xmlList.length(); i++)
    {
        imageLoader = new Loader();
        imageLoader.load(new URLRequest(xmlList[i].attribute("thumb")));
        imageLoader.x = 10+( i % columns )*65;
        imageLoader.y = 10+(Math.floor(i/columns)*65);;
        imageLoader.name = xmlList[i].attribute("source")
        addChild(imageLoader);
        imageLoader.addEventListener(MouseEvent.CLICK, showPicture);
  
   
        
    
}}

function showPicture(event:MouseEvent):void
{
   if(imageLoader)
     {removeChild(imageLoader)}
    imageLoader = new Loader();
    imageLoader.load(new URLRequest(event.target.name));
    imageLoader.x = 200;
    addChild(imageLoader);
    
    
    
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-10-08, 18:30
Junior Member
 
Join Date: Sep 2008
Posts: 1
Rep Power: 0
Caesar1982 is on a distinguished road
Re: xml gallery

Pardon me if my english is not so good, I'm a poor French guy, and I just started learning AS(3) as well...so don't get to rough on me ok.. but I really need your help. Anyone.

I have a main flash movie that consists of basically two main layers with one mc on each, one for a background(photoShow_mc), and the second one on top(mainMenus_mc) in which I run most of dynamic areas and scripting related to my menus movieclip buttons...so far nothing too hard there.

Now, by CLICKING one of the menu(IN the first frames of the timeline of mainMenus_mc), it will GOTOANDPLAY the sequence of frame(in mainMenus_mc) requested by frame labels and to stop to frame the next stop (let say in the mid-part of the timeline of mainMenus_mc), where I want it to load a external .swf, that should be removed as the section is closed by calling another sequence of frames again(what about referring to the end of the timeline in mainMenus_mc again), from where the guest is returned to the main frame label where you choose the menus again(beginning of mainMenus_mc).

Now, I've figured out for now that the easiestis by creating an opening sequence for each menu section(which is easiest and better for my purposes too) which bring all to a(many) stop frame where I request a loaderX++ to load the .swf URLattached to the menu section called. So far, I got it all. Now, all the menus get to close with the same closing section sequence. At first try, it was easy because I had only one loader request which I removed by using stage.removeChild(loaderX) on the first frame of the closing sequence. But now with more than 20 sections(which means 20 different .swf to load independently and on different time on the timeline, I just do know where to go from here.

anyway, anyone can help me get over this issue Please. It means a lot to me.
Thx
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads

Thread Thread Starter Forum Replies Last Post
Reflect Gallery Flep Utilità di FlepStudio 87 29-09-08 19:47
Reflect Gallery Flep FlepStudio utilities 8 04-09-08 21:03
Elastic Gallery Flep FlepStudio utilities 17 20-08-08 13:00
xml gallery - scroll motown advanced Actionscript 3.0 1 09-02-08 13:28
gallery swf+jpeg bliyrskel AIUTO utilità free 3 01-02-08 08:06


All times are GMT. The time now is 05:06.


Powered by vBulletin versione 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC4
Forum SiteMap


FlepStudio
by Filippo Lughi
P.IVA 03605860406