A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Beginner doesn't get this actionscript concept

  1. #1
    Junior Member
    Join Date
    Mar 2002
    Posts
    10

    Beginner doesn't get this actionscript concept

    Hi Folks,

    I am attempting to learn the basics(very basic!) of flash programming and global variables.
    Here's the scenario:
    *********************************************

    Frame one contains this actionscript:
    var length=0;

    Frame two contains this actionscript:
    length=length+1;
    trace("length in second frame is");
    trace(length);
    bar._xscale=length;

    Frame three contains this actionscript:
    length=length+1;
    trace("length in third frame is");
    trace(length);
    bar._xscale=length;
    if (length == 100) {
    stop()
    }
    gotoAndPlay(2);
    **********************************

    Irrelevant of what I am trying to do, in frame three I expected the movie to stop once the global variable "length" reached 100 but this is not the case, the movie continues on.

    Now if I make the following in frame 3:
    ***************************

    if (length == 100) {
    stop()
    }
    else{
    gotoAndPlay(2);
    }
    ***************************

    instead of:
    ***********************
    if (length == 100) {
    stop()
    }
    gotoAndPlay(2);
    ***********************

    all works properly.

    Can someone explain to me what I am not understanding in regards to how actionscripting works? Obviously I am missing what seems to be a VERY IMPORTANT concept in actionscripting.

    Thanks,
    Greg
    gpl@maine.rr.com
    libman

  2. #2
    Senior Member
    Join Date
    Jun 2003
    Location
    Florida
    Posts
    289
    try this
    Frame one contains this actionscript:
    code:
     
    var length=0;



    Frame two contains this actionscript:
    code:

    _root.length++;
    trace("length in second frame is");
    trace(_root.length);
    _root.bar._xscale=_root.length;



    Frame three contains this actionscript:
    code:

    _root.length++;
    trace("length in third frame is");
    trace(_root.length);
    _root.bar._xscale=_root.length;
    if (_root.length == 100) {
    stop()
    }
    //this goto will not work because of the stop action before it
    gotoAndPlay(2);



    Sometimes absolute paths are necessary for Flash to find varialbles and MCs

    Let me know if this works; I did really quick.
    If it was easy, everyone would do it.

  3. #3
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    Hi,

    flash will process all the actionscript in a frame before carrying out actions such as gotoAndPlay,

    hence where you have something like this,

    code:

    if (length == 100) {
    stop();
    }
    gotoAndPlay(2);



    when length is 100 flash will try to execute both the stop(); and gotoAndPlay commands, the gotoAndPlay is reached last so it overrides whatever had gone before.

    by adding the else condition,

    code:

    if (length == 100) {
    stop();
    } else {
    gotoAndPlay(2);
    }



    you prevent the gotoAndPlay from being executed in the case where length is 100.

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