Results 1 to 2 of 2

Thread: Array Question... i=0 or i=1

  1. #1
    Join Date
    Apr 2006
    Posts
    584
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Array Question... i=0 or i=1

    Hi all,

    I have an array the code looks like this

    Code:
    i = 1;
    frames = new Array(38, 40, 42, 44, 46, 48);
    this.onEnterFrame = function() {
        if (this._currentframe == frames[i]) {
            this["btn" + i].index = i+1;
            this["btn" + i].onRelease = function () {
               variable = this.index;
               this.play();
            		}
    		this["btn" + i].index = i;
    		this["btn" + i].onRelease = function() {
          	variable = this.index;
          	gotoAndPlay(51);
    		};
            this["btn" + i].onRollOver = function() {
                delete this.onEnterFrame;
                this.play();
            };
            this["btn" + i].onRollOut = function() {
                this.onEnterFrame = function() {
                    if (this._currentframe == 1) {
                        delete this.onEnterFrame;
                    } else {
                        this.gotoAndStop(this._currentframe - 1);
                    }
                };
            };
            i++;
        }
        if (this._currentframe == frames[frames.length]) {
            delete this.onEnterFrame;
        }
    };
    And this is what it calls when it gets to the frame

    Code:
    if (variable == 1) {
    	gotoAndStop("btn1");
    } else if (variable == 2) {
    	gotoAndStop("btn2");
    } else if (variable == 3) {
    	gotoAndStop("btn3");
    } else if (variable == 4) {
    	gotoAndStop("btn4");
    } else if (variable == 5) {
    	gotoAndStop("btn5");
    } else if (variable == 6) {
    	gotoAndStop("btn6");
    }
    The problem is if I make 'i=o' the btn1 doesn't work... If I make 'i=1' btn6 doesn't work... I'm racking my brain but can't work this one out!

  2. #2
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    remove your i =1 up top there.

    Replace the code section to add the following:

    Code:
    this.onEnterFrame = function() {
        for (var i:Number=0; i<6; ++i){
        if (this._currentframe == frames[i]) {
            this["btn" + i].index = i+1;
            this["btn" + i].onRelease = function () {
               variable = this.index;
               this.play();
    Then add your extra "}" at the end

    Remember like most other languages counting starts at 0, not 1 so when you have 6 buttons, your highest number = 5.

    Hope it helps
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •