A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: active links in XML - FLASH

  1. #1
    Junior Member
    Join Date
    Aug 2006
    Posts
    5

    active links in XML - FLASH

    I've had some help building this image viewer in flash. it uses xml to manage the images and caption text.

    The problem i'm having is I need to make the (download pdf) a working link, at the moment it is just text. the guy that helped me is on holiday so I'm stuck!

    the url is: http://www.danielatkinson.com/test/

    thanks.

    the xml file is as follows..(this line duplicated for 20 images)
    <images>
    <image img="images/large/test_1.jpg" thumb="images/sml/test_t1.jpg" caption="download pdf"/>
    </images>

    the action script in frame 1 looks like this..

    #include "lmc_tween.as"

    stop();
    var stageWidth:Number = Stage.width+320;
    var preloadNum = Math.round(Math.floor(stageWidth/84))
    var loadArray:Array = new Array()
    var listArray:Array = new Array()
    var numImages:Number
    var menuWidth:Number
    var init:Boolean = false;
    var currentLoad:Number = 0
    _global.selectDisabled = true;



    this.createEmptyMovieClip("images",10);
    images._y = 132;
    images._x = 335;
    this.createEmptyMovieClip("menu",20);
    menu._y = 564;
    menu._x = 0;
    menu.createEmptyMovieClip("menu1",1);
    menu.menu1._x = 593;
    menu.createEmptyMovieClip("menu2",2);



    myXML = new XML();
    myXML.ignoreWhite = true;
    myXML.onLoad = function(success)
    {
    if(success)
    {
    var xPos = 0;
    numImages = this.firstChild.childNodes.length;
    menuWidth = numImages*84;

    for(x=0;x<this.firstChild.childNodes.length;x++)
    {
    listArray.push(x);

    }

    for(x=0;x<this.firstChild.childNodes.length;x++)
    {
    if(x%2)
    {
    loadArray.push(listArray[listArray.length-1]);
    listArray.pop();
    }
    else
    {
    loadArray.push(listArray[0]);
    listArray.splice(0,1)
    }
    }

    for(x=0;x<this.firstChild.childNodes.length;x++)
    {

    menu.menu1.attachMovie("thumb","thumb"+x,x+1);
    menu.menu1["thumb"+x]._alpha = 0;
    menu.menu1["thumb"+x]._x = xPos;
    menu.menu1["thumb"+x].iPos = x;
    xPos += 84;
    }


    menu.menu2._x = 593 - menuWidth
    xPos = 0;

    for(x=0;x<this.firstChild.childNodes.length;x++)
    {
    menu.menu2.attachMovie("thumb","thumb"+x,x+1);
    menu.menu2["thumb"+x]._alpha = 0;
    menu.menu2["thumb"+x]._x = xPos;
    menu.menu2["thumb"+x].iPos = x;
    xPos += 84;
    }


    loadImage()
    }

    }

    myXML.load('test.xml');

    var myImageLoader = new MovieClipLoader ();
    var myThumbLoader = new MovieClipLoader ();

    myImageLoader.onLoadComplete = function (targetMC)
    {
    myThumbLoader.loadClip(myXML.firstChild.childNodes[loadArray[currentLoad]].attributes.thumb,menu.menu1["thumb"+loadArray[currentLoad]].image);
    myThumbLoader.loadClip(myXML.firstChild.childNodes[loadArray[currentLoad]].attributes.thumb,menu.menu2["thumb"+loadArray[currentLoad]].image);
    targetMC._parent.gotoAndStop(2)
    currentLoad++
    if(currentLoad < numImages) loadImage()

    }

    myThumbLoader.onLoadComplete = function (targetMC)
    {
    //targetMC._parent.gotoAndStop(2);
    if ((currentLoad+1) == preloadNum || (currentLoad+1) == numImages) {
    if (!init) {
    gotoAndStop('main')
    }
    }

    }

    function loadImage()
    {
    var perc = -690+((currentLoad+1)/preloadNum)*614;
    loader.bar._x = perc
    images.attachMovie("mainImage","image"+loadArray[currentLoad],currentLoad+1);
    images["image"+loadArray[currentLoad]]._x = 2000;
    if(myXML.firstChild.childNodes[loadArray[currentLoad]].attributes.caption)
    {
    images["image"+loadArray[currentLoad]].captionText.text = myXML.firstChild.childNodes[loadArray[currentLoad]].attributes.caption;
    }
    myImageLoader.loadClip(myXML.firstChild.childNodes[loadArray[currentLoad]].attributes.img,images["image"+loadArray[currentLoad]].imageHolder);
    }

  2. #2
    Senior Member donaldparkerii's Avatar
    Join Date
    May 2005
    Location
    San Diego
    Posts
    616
    just add a url attribute in your xml file, and attach it to the button when you load the image

  3. #3
    Junior Member
    Join Date
    Aug 2006
    Posts
    5
    thanks, how excactly do I add a url attribute to the xml?
    sorry if I sound like a goose! i'm not much of a coder

  4. #4
    Senior Member donaldparkerii's Avatar
    Join Date
    May 2005
    Location
    San Diego
    Posts
    616
    Here is how you add the attribute to the xml
    <image img="images/large/test_1.jpg" thumb="images/sml/test_t1.jpg" caption="download pdf" url="pdfs/file.pdf"/>

    in your loadImage function captionText.text should be in a movie clip, lets call it caption_mc, so that you can assign a onRelease function to load the pdf.

    images["image"+loadArray[currentLoad]].caption_mc.captionText.text = myXML.firstChild.childNodes[loadArray[currentLoad]].attributes.caption;
    images["image"+loadArray[currentLoad]].caption_mc.onRelease = function(){
    getURL(myXML.firstChild.childNodes[loadArray[currentLoad]].attributes.url, "_pdf");
    }

    This should be right but i dont know, because i havent tested it.

  5. #5
    Junior Member
    Join Date
    Aug 2006
    Posts
    5
    thanks, but i'm not having any luck with it. I've attached the source files if you want have look? cheers!
    Attached Files Attached Files

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