A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: [RESOLVED] using XML to set value for TIMER

Hybrid View

  1. #1
    Member
    Join Date
    Sep 2008
    Posts
    39

    resolved [RESOLVED] using XML to set value for TIMER

    OK, so in the project i'm building this is the code for my timer:
    var mytime:Number;
    var myTimer:Timer;

    mytime = 5;

    myTimer = new Timer(mytime*1000);
    What i want is mytime to be called from my xml file
    it also has to change for each image that shows up

    This seems to me like it should be SO easy but I can't figure it out for some reason. I call images / links and text all from this file and i can't seem to get this all to work.

    THANKS so much I really need to be pointed in the right direction because this needs to be done soon and i've spent way too much time on this one stupid thing.

    Thanks so much for any help / suggestions.

    here's my xml
    <?xml version="1.0" encoding="utf-8"?>
    <images>
    <pic>

    <brand>hero_logos/BSO_logo_w_type.png</brand>
    <thumb>hero_thumbs/flippingbrochure760x240.jpg</thumb>
    <largeimg>hero_large/flippingbrochure760x240.jpg</largeimg>
    <about>
    <![CDATA[As part of Opening Night at Symphony 2009, the Boston Symphony Orchestra introcudes an imaginateive new concept.]]>
    </about>
    <head>
    <![CDATA[Opening Night at Symphony - Electronic Program Book]]>
    </head>
    <subhead>
    <![CDATA[The Electronic Program Book]]>
    </subhead>
    <morelink>http://bso.org/bso/index.jsp?id=bcat5240070</morelink>
    <captiontext>
    <![CDATA[NEW! The Electronic Program Book]]>
    </captiontext>
    <date1>
    <![CDATA[none]]>
    </date1>
    <date2>
    <![CDATA[none]]>
    </date2>
    <date3>
    <![CDATA[none]]>
    </date3>
    </pic>



    <pic>



    <brand>hero_logos/BSO_logo_w_type.png</brand>
    <thumb>hero_thumbs/jameslevine760x240.jpg</thumb>
    <largeimg>hero_large/jameslevine760x240.jpg</largeimg>
    <about>
    <![CDATA[James Levine will conduct tomorrow's bla bla concert. - the more links work, the link comes from the xml file.]]>
    </about>
    <head>
    <![CDATA[James Levine Conducts]]>
    </head>
    <subhead>
    <![CDATA[September 2, 2009 8pm]]>
    </subhead>
    <morelink >http://bso.org/bso/mods/c_09_gen_images.jsp?id=39111</morelink>
    <captiontext>
    <![CDATA[James Levine - September 2, 2009 8pm]]>
    </captiontext>
    <date1>
    <![CDATA[<a href="http://bso.org/bso/mods/c_09_gen_images.jsp?id=39111">Date One, 2010 -2</a>]]>
    </date1>
    <date2>
    <![CDATA[<a href="http://bso.org/bso/mods/c_09_gen_images.jsp?id=39111">Date two, 2010 -2</a>]]>
    </date2>
    <date3>
    <![CDATA[&nbsp;]]>
    </date3>
    </pic>


    <pic>


    <brand>hero_logos/POPS.png</brand>
    <thumb>hero_thumbs/john_pizz_760.jpg</thumb>
    <largeimg>hero_large/john_pizz_760.jpg</largeimg>
    <about>
    <![CDATA[John Pizzarelli and the Boston Pops! Don't miss this amazing music and be there or else.]]>
    </about>
    <head>
    <![CDATA[John Pizzarelli will join the Boston Pops.]]>
    </head>
    <subhead>
    <![CDATA[May 2, 2009 8pm]]>
    </subhead>
    <morelink >http://bso.org/bso/mods/perf_detail.jsp?pid=prod2880025</morelink>
    <captiontext>
    <![CDATA[John PIzzarelli - May 2, 2009 8pm]]>
    </captiontext>
    <date1>
    <![CDATA[Date One, 2010 -3]]>
    </date1>
    <date2>
    <![CDATA[Date two, 2010 -3]]>
    </date2>
    <date3>
    <![CDATA[Date three, 2010 -3]]>
    </date3>
    </pic>


    <pic>


    <brand>hero_logos/TWD.png</brand>
    <thumb>hero_thumbs/juliafischer_760x240.jpg</thumb>
    <largeimg>hero_large/juliafischer_760x240.jpg</largeimg>
    <about>
    <![CDATA[&nbsp;]]>
    </about>
    <head>
    <![CDATA[&nbsp;]]>
    </head>
    <subhead>
    <![CDATA[&nbsp;]]>
    </subhead>
    <morelink ></morelink>
    <captiontext>
    <![CDATA[Julia Fischer - August 4, 2009]]>
    </captiontext>
    <date1>
    <![CDATA[Date One, 2010 -4]]>
    </date1>
    <date2>
    <![CDATA[Date two, 2010 -4]]>
    </date2>
    <date3>
    <![CDATA[none]]>
    </date3>
    </pic>

    <pic>


    <brand>hero_logos/SHALL.gif</brand>
    <thumb>hero_thumbs/sh_digital_760.jpg</thumb>
    <largeimg>hero_large/sh_digital_760.jpg</largeimg>
    <about>
    <![CDATA[We now offer digital Music subscriptions that you can buy and they are worth the money.]]>
    </about>
    <head>
    <![CDATA[Digital Music]]>
    </head>
    <subhead>
    <![CDATA[Now Available!]]>
    </subhead>
    <morelink >http://bso.org/bso/index.jsp?id=bcat5222</morelink>
    <captiontext>
    <![CDATA[Digital Music - Now Available!]]>
    </captiontext>
    <date1>
    <![CDATA[]]>
    </date1>
    <date2>
    <![CDATA[Date two, 2010 -5]]>
    </date2>
    <date3>
    <![CDATA[Date three, 2010 -5]]>
    </date3>
    </pic>
    <pic>


    <brand>hero_logos/TWD.png</brand>
    <thumb>hero_thumbs/shed_screen2_760.jpg</thumb>
    <largeimg>hero_large/shed_screen2_760.jpg</largeimg>
    <about>
    <![CDATA[New Tanglewood Sheds!]]>
    </about>
    <head>
    <![CDATA[Tanglewood now offers large hi def screens!]]>
    </head>
    <subhead>
    <![CDATA[New High Def Tanglewood Shed Screens!]]>
    </subhead>
    <morelink >http://bso.org/bso/index.jsp?id=bcat5240070</morelink>
    <captiontext>
    <![CDATA[New High Def Screens at Tanglewood!]]>
    </captiontext>
    <date1>
    <![CDATA[Date One, 2010 -6]]>
    </date1>
    <date2>
    <![CDATA[Date two, 2010 -6]]>
    </date2>
    <date3>
    <![CDATA[Date three, 2010 -6]]>
    </date3>
    </pic>
    <pic>


    <brand>hero_logos/TWD.png</brand>
    <thumb>hero_thumbs/tony_bennett_760.jpg</thumb>
    <largeimg>hero_large/tony_bennett_760.jpg</largeimg>
    <about>
    <![CDATA[This guy's gonna be at Tanglewood, some come see it and buy some tickets or else.]]>
    </about>
    <head>
    <![CDATA[Tony Bennett]]>
    </head>
    <subhead>
    <![CDATA[March 2, 2009 8pm]]>
    </subhead>
    <morelink >http://bso.org/bso/index.jsp?id=bcat5240070</morelink>
    <captiontext>
    <![CDATA[Tony Benett - March 2, 2009 8pm]]>
    </captiontext>
    <date1>
    <![CDATA[<a href="http://bso.org/bso/index.jsp?id=bcat5240070">Date One, 2010 -7</a>]]>
    </date1>
    <date2>
    <![CDATA[<a href="http://bso.org/bso/index.jsp?id=bcat5240070">Date two, 2010 -7</a>]]>
    </date2>
    <date3>
    <![CDATA[<a href="http://bso.org/bso/index.jsp?id=bcat5240070">Date three, 2010 -7</a>]]>
    </date3>
    </pic>
    </images>
    Last edited by laurabeth; 10-28-2009 at 09:25 PM.

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    Why don't you just add a node for each pic
    <myTime>5</myTime>
    and then after the xml file is loaded you call that node.
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Member
    Join Date
    Sep 2008
    Posts
    39
    Quote Originally Posted by cancerinform View Post
    Why don't you just add a node for each pic
    <myTime>5</myTime>
    and then after the xml file is loaded you call that node.
    That is what I tried to do..

    i had
    <displayTime>5</displayTime>

    and in my code i had tried different variations of
    mytime = Number(xmlData.pic.displayTime[current_index]);

    I know it's something really dumb why this isn't working
    I get the error message:
    RangeError: Error #2066: The Timer delay specified is out of range.
    at Error$/throwError()
    at flash.utils::Timer()
    Last edited by laurabeth; 10-29-2009 at 09:59 AM.

  4. #4
    Member
    Join Date
    Sep 2008
    Posts
    39

    OK ... progress maybe I still need help ugh

    Ok now i've tried

    var mytime:int;
    var myTimer:Timer;
    myTimer = new Timer(mytime*1000);
    myTimer.addEventListener(TimerEvent.TIMER, timedFunction);

    mytime = new Number(xmlData.pic.displayTime[current_index]);
    But the problem is this just continuously loops like so fast you don't even see anything. I only know it's looping continuously because of the traces.
    BUT
    I don't get any errors ...

    ohhhhhhh this is so frustrating! I know it's like so easy

  5. #5
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    You need to have a value for mytime before declaring the timer. Then you need to add the number of times, which I would set to 1.
    myTimer = new Timer(mytime*1000,1);
    Also stay consistent and cast the XML node with int.

    I don't know the rest of your code. So I can only guess.
    - The right of the People to create Flash movies shall not be infringed. -

  6. #6
    Member
    Join Date
    Sep 2008
    Posts
    39

    my code

    Thanks! I got it.
    This link kinda helped: http://www.wuup.co.uk/as3-quick-tips...nd-vice-versa/

    And like you said i wasn't assigning value to my variables in the right spot (not good at the correct terminology)
    THANKS!

    I had to first define my variables
    var myTimer:Timer;
    var mytimeString:String;
    var mytimeTotal:int;
    var speed_index:int;

    THEN in the xml loaded function I assigned values to them:
    function xmlLoaded(e:Event):void {
    xmlData = XML(xmlLoader.data);
    my_images=xmlData.pic;
    my_total=my_images.length();
    loadThumbs();//call the thumbs loading function


    mytimeString = new String(xmlData.pic.displayTime[speed_index]);
    mytimeTotal = new int(mytimeString);
    myTimer = new Timer(mytimeTotal*1000, 1);
    myTimer.addEventListener(TimerEvent.TIMER, timedFunction);

    trace(mytimeTotal);


    if (my_total >= 5) {


    TweenLite.to(left, 3, {alpha:1,ease:Circ.easeIn});//alpha in the left arrow
    TweenLite.to(right, 3, {alpha:1,ease:Circ.easeIn});//alpha in the right arrow
    }
    current_index=0;
    speed_index=0;
    loadBigImage();

    trace("xmlData has been loaded");
    }
    i'm not good at the lingo but thanks again!
    Last edited by laurabeth; 10-30-2009 at 01:48 PM.

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