A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Flash XML Slideshow/Gallery

  1. #1
    Junior Member
    Join Date
    Jul 2009
    Posts
    20

    Flash XML Slideshow/Gallery

    Hello,

    i am relatively new to flash and actionscript 3 but i have been recently making a website and i have got to a stage where one page is pulling in SWF's via an XML document. There are left and right arrows which load up the next/previous SWF. The right arrow works fine, it loads the next one up and then due to some AS3 code when it gets to the end it loops back around. The left arrow goes back a frame until it comes to the beginning and it wont loop to the end. I just cant get that code to work so i was hoping someone could help me with that.

    Below is a copy of the code that i am using. I am aware that i need to create the event listener for the arrow and i am fine with that, its just the function to go with it that i am struggling with.

    Thanks anyone for any help/advice in advance :-)

    var xmlRequest:URLRequest = new URLRequest("swf_files.xml");
    var xmlLoader:URLLoader = new URLLoader(xmlRequest);
    var imgData:XML;
    var imageLoader:Loader;
    var rawImage:String;

    var imgNum:Number = 0;
    var checkSec:Timer = new Timer(100);
    var numberOfChildren:Number;

    xmlLoader.addEventListener(Event.COMPLETE, xmlLoadedF);
    right.addEventListener(MouseEvent.CLICK, nextImgF);
    left.addEventListener(MouseEvent.CLICK, "event goes here");

    function xmlLoadedF(event:Event):void{
    checkSec.start();
    checkSec.addEventListener(TimerEvent.TIMER, checker1);
    imgData = new XML(event.target.data);
    }

    function packagedF():void{
    checkSec.removeEventListener(TimerEvent.TIMER, checker1);
    rawImage = imgData.image[imgNum].imgURL;
    numberOfChildren = imgData.*.length();
    imageLoader = new Loader;
    imageLoader.load(new URLRequest(rawImage));
    center_stage.addChild(imageLoader);

    }

    function checker1(event:TimerEvent):void{
    if(imgNum == 0){
    packagedF();
    }else if(imgNum < numberOfChildren) {
    imageLoader.unload();
    packagedF();

    }else{
    imageLoader.unload();
    imgNum = 0;
    packagedF();


    }
    }



    function nextImgF(event:MouseEvent):void{
    checkSec.addEventListener(TimerEvent.TIMER, checker1);
    imgNum++;
    }

  2. #2
    Junior Member
    Join Date
    Jul 2009
    Posts
    20
    I'm sorry, is this the wrong place to be asking this question? :-)

  3. #3
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    No, it's just a boring question and you didn't use proper formatting so it takes effort to read through your code. Also, Sunday night is not usually a very active time here.

    I'm not sure why you're using a Timer since you remove the event listener every time you go to the next slide.

    But prevImgF could be just like nextImgF with imgNum-- instead of ++. I'd suggest parsing all the urls out after first loading the xml and putting them in an array to avoid all the xml processing every time. But your way should work too.
    By the way, you should not create a new imageLoader every time, you'll end up with a lot of empty loaders on stage. This will create a memory leak over time, and probably slow things down.

  4. #4
    Junior Member
    Join Date
    Jul 2009
    Posts
    20
    Hi, thanks for the reply but as i said i am relatively new to Flash hence the mistakes above. I will take what you said on board though and modify my code. Sorry for posting "boring" questions too but i find asking for help in the community a lot more helpful to my learning than other methods.

  5. #5
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    I was just teasing you about the boringness. But slideshows are a dime a dozen. They are an excellent introduction to Flash and AS3 though. In fact, I wrote a small tutorial about object oriented programming to develop Yet Another eXtensible Slideshow framework. You might find it useful, or you might not.
    A preview of the sort of stuff you can build using the yaxs framework
    http://cosmodro.me/blog/2009/jun/23/...-yaxs-preview/

    And the tutorial and framework:
    http://cosmodro.me/blog/2009/jul/3/b...eshow-framewo/

  6. #6
    Junior Member
    Join Date
    Jul 2009
    Posts
    20
    Ha yeah i am getting that feeling, just unfortunately each one is different in a very small way. Thank you again for your reply and advice though and the tutorial too!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center