A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Scripting Question - My head hurts :)

  1. #1
    Junior Member
    Join Date
    Apr 2005
    Location
    Ottawa, ON, CA
    Posts
    8

    Scripting Question - My head hurts :)

    Hello Folks!

    I have searched the forum to the best of my ability and don't seem to see the answer to this question though I am quite sure I am probably missing something simple here What I have is a simple window on a clients web site that displays announcements with a link to a URL for more information if applicable. Right now it works just fine but I would like to modify it so that the end user can simply update an XML file by themselves and the Flash app will reflect the changes.

    I have got the new version to load / read the XML and drill down to get the information to populate the variables with no problem. That part works fine.

    What I am having trouble with is a simple counter that I would like to count from zero up to a defined number (the number of items in the XML file) and then start over again and repeat forever. I am able to get the number of entries from the XML with no problem - It is just getting the counter to run more than once that is giving me the problem.

    Code snippet:

    var NumScreens = my_xml.childNodes.length;
    var Pause = 1000;
    var Step = 0;

    // Counts
    Step = getTimer()/ 1000;
    Step = int(Step);
    if(Step < NumScreens)
    {
    display();
    }

    // I would love to have the value of 'Step' count
    // up from 0 to 4 and then return to 0 and repeat
    // continually



    // This part is happy
    function display()
    {
    ...............

    I have attached the whole shebang if that will be of any help. If I am not explaining myself clearly or if I am going about this totally in the wrong way PLEASE feel free to post any and all suggestions!

    Thanks in advance - Going for a walk now to clear my head!
    Attached Files Attached Files

  2. #2
    Member MoonRise's Avatar
    Join Date
    Sep 2004
    Location
    Greenville SC
    Posts
    121

    Hope this gives some help

    Hey,

    First all, I'm not a great scripter, but know quit a bit about programming in other languages. I looked at your sample and if I'm not mistaking, you want it to repeat after it reaches the end of the XML file. At least that is when I start getting errors from your sample and I assume you want to control that. If that is what you are wanting to acheive, then look in the scripting language and see if it has a way to test for EOF (End Of File). This is how other languages I've dealt with handle imported files. Then you need to find a way to reset the "file pointer" back to the begining of the file. Please let me know if this gives any help at all.
    MoonRise

  3. #3
    Junior Member
    Join Date
    Apr 2005
    Location
    Ottawa, ON, CA
    Posts
    8
    MoonRise,

    Thanks for taking the time to take a look at this. It's appreciated! Like yourself, I would be happier in Perl or PHP and a test for EOF would be the ticket and then just repeat the parse. However in 3DFA I am not able to find any real functions for dealing with external file out side of the initial loading of the XML file in the startup script of the movie. AGAIN - I may be missing the whole big picture here but it looks as if once the XML is loaded, you don't really step through it but rather poke away with the childNodes[x] syntax and get the value you want. That's why I went the route of a counter to generate the 'x' value to put in the 'poke' Perhaps there is a way of having an external script in another language push the info to 3DFA? If that is the case then I will be OK as well.

    I need to do some more learning with this software, I can see, but thanks again for the input!!

  4. #4
    Senior Member
    Join Date
    May 2005
    Posts
    163
    jmclaren wrote:

    Code snippet:

    var NumScreens = my_xml.childNodes.length;
    var Pause = 1000;
    var Step = 0;

    // Counts
    Step = getTimer()/ 1000;
    Step = int(Step);
    if(Step < NumScreens)
    {
    display();
    }

    // I would love to have the value of 'Step' count
    // up from 0 to 4 and then return to 0 and repeat
    // continually



    // This part is happy
    function display()
    {
    You need to make sure that the result is a number from 0 to NumScreens or else you will get an array bounds error since you will be trying to access a node that does not exist. Also your Step calculation will keep increasing since getTimer() is always increasing and you will never go back through the list.

    To solve these problems you need to use NumScreens to limit the result of the calculation.

    Just replace
    PHP Code:
    Step getTimer()/ 1000
    with
    PHP Code:
    Step = (getTimer()/ 1000) % NumScreens
    This should keep the Step between 0 and NumScreens and loop through the nodes continuously.
    Last edited by ppedz; 01-28-2006 at 10:29 PM.

  5. #5
    Junior Member
    Join Date
    Apr 2005
    Location
    Ottawa, ON, CA
    Posts
    8
    Quote Originally Posted by ppedz
    jmclaren wrote:



    You need to make sure that the result is a number from 0 to NumScreens or else you will get an array bounds error since you will be trying to access a node that does not exist. Also your Step calculation will keep increasing since getTimer() is always increasing and you will never go back through the list.

    To solve these problems you need to use NumScreens to limit the result of the calculation.

    Just replace
    PHP Code:
    Step getTimer()/ 1000
    with
    PHP Code:
    Step = (getTimer()/ 1000) % NumScreens
    This should keep the Step between 0 and NumScreens and loop through the nodes continuously.
    ppedz,

    I am indebted to you. That is exactly what I was looking for and using that code, I have the full application working perfectly.

    Is there a resource dealing with 3DFA scripting specifically that I can read up on or is this based on sounder knowledge of JavaScripting that I am also in need of?

    Regardless - Many many thanks for the clear and working solution!!!

    Cheers!

  6. #6
    Senior Member
    Join Date
    May 2005
    Posts
    163
    Is there a resource dealing with 3DFA scripting specifically that I can read up on or is this based on sounder knowledge of JavaScripting that I am also in need of?
    This is just standard programming stuff and is not language specific. Now that you know it just put it in you bag of tricks and maybe it will come in handy again someday.

    Just keep learning and you'll find out how little you really know. And once you understand it, it changes and you have to learn it again.

    I'm glad I could help.

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