Skip navigation
nateyboy044
Currently Being Moderated

Is actionscript processed sequential (line by line)?

Jul 18, 2007 2:26 PM

Ok, so long story short, I have a loop that fills three different arrays. As soon as the loop finishes, on the next line, a function is called that loads dynamic images into movie clips. However, this isn't working as I thought. Instead, the function is being called at the same time as the loop is running. Therefor, the first few images don't show up and I get undefined errors. However, if I delay the function being called by 50ms, I don't get the error. This means that it is a timing problem and that flash is executing the loop and the function call at the same time.

Does anybody have any experience/advice on what or why this might be happening?

Thanks in advance.

Edit: Also, my entire movie is implemented using actionscript in the first frame of the movie.
 
Replies
  • Currently Being Moderated
    Jul 18, 2007 2:47 PM   in reply to nateyboy044
    have you tried waiting one frame? maybe you have objects or movie clips that need to initialise first?

    just a thought

    can you explain in more detail what the loop and the function do?
     
    |
    Mark as:
  • Currently Being Moderated
    Jul 18, 2007 3:12 PM   in reply to nateyboy044
    Actionscript is handled in a top down fashion (typically) and for non-function encased code, is called as soon as that particular section of AS is loaded into the player. If you need to delay the call to this function, use a setInterval or Timer (depending on AS version). Just remember to clear the interval or timer after you are finished with it.
     
    |
    Mark as:
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    Jul 18, 2007 3:24 PM   in reply to nateyboy044
    most actionscript is executed sequentially (or synchronously), but some is asynchronous. one of the most common places to encounter asynchronous events is load event..
     
    |
    Mark as:
  • Currently Being Moderated
    Jul 18, 2007 7:40 PM   in reply to nateyboy044
    With things like this is is generally good to show your code. You describe what you think is happening, but perhaps it isn't what you think.
     
    |
    Mark as:
  • Currently Being Moderated
    Nov 15, 2007 12:23 AM   in reply to nateyboy044
    I've a question that could be similar to this:

    Let's say I want to make an object wiggle horizontally using a function(),

    function Wiggle(){
    object._x++;
    object._x--;
    }

    However, the object doesn't move at all.

    My idea is to make the object move a pixel right and then left when the function is executed. Is it possible to execute the code line by line rather than "tabulating" the result?
     
    |
    Mark as:
  • Currently Being Moderated
    Nov 15, 2007 6:34 AM   in reply to nateyboy044
    function Wiggle(){
    object._x++;
    object._x--;
    }


    It does both actually. You're just not seeing it because of how Flash
    works - the function happens in between frame cycles, so the object moves
    forward a pixel, then back a pixel, then the frame is redrawn - so the
    object does not appear to move. You can fix by doing one or the other,
    dependent on a simple flag:

    var flag = 0;
    function Wiggle(){
    flag++;
    if(flag % 2){
    object._x++;
    }else{
    object._x--;
    }
    }


    everytime you call wiggle you increment flag. If it's now an even number
    increment x, otherwise decrement.

    HTH

    --
    Dave -
    Head Developer
    http://www.blurredistinction.com
    Adobe Community Expert
    http://www.adobe.com/communities/experts/


     
    |
    Mark as:
  • Currently Being Moderated
    Nov 16, 2007 12:51 AM   in reply to nateyboy044
    Got it...thanks!
     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)