dcsimg
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [F8] "For" Statement is making me confused...Please Help

  1. #1
    Member
    Join Date
    Aug 2006
    Location
    Australia
    Posts
    64

    [F8] "For" Statement is making me confused...Please Help

    Hi guys and girls,

    I'm trying to move a number of MCs from one point to another with the FOR statement. It recognises the Starting position and sets it for all of the MCs, however they do not animate...

    The MCs are all on the same ._y value, all moving at the same speed and to the same ._y value.

    I also don't quite follow why if I would set the code to

    Code:
    var origPos = btn_07._y;
    to
    Code:
    var origPos = btn_00._y;
    The MCs go down even further...40px down and not 20px

    I understand that the For Statement repeats it self X (set) number of times.

    Below is the Full Code...
    Code:
    for (a=0; a!=8; a++) {
    	var origPos = btn_07._y;
    	var startPos = origPos+20;
    	this["btn_0"+a]._y = startPos;
    	onEnterFrame = function () {
    		if (this["btn_0"+a]._y != origPos) {
    			this["btn_0"+a]._y--;
    		}
    	};
    }

  2. #2
    Member
    Join Date
    Jul 2007
    Posts
    77
    Try this...

    Code:
    var origPos = btn_07._y;
    var startPos = origPos+20;
    for (a=0; a<8; a++) {
    	this["btn_0"+a]._y = startPos;
    }
    onEnterFrame = function () {
    for (a=0; a<8; a++) {
    	this["btn_0"+a]._y = startPos;
    		if (this["btn_0"+a]._y > origPos) {
    			this["btn_0"+a]._y--;
    		}
    	};
    }
    Last edited by ugoDesigns; 08-15-2007 at 09:58 PM.

  3. #3
    Member
    Join Date
    Aug 2006
    Location
    Australia
    Posts
    64

    [Resolved]

    It was because I didn't define the MCs to the onEnterFrame function..*sigh*

    Thanks for your help though

    [code]
    var origPos = btn_00._y;
    var startPos = origPos+20;
    for (a=0; a<8; a++) {
    this["btn_0"+a]._y = startPos;
    }

    for (a=0; a<8; a++) {
    this["btn_0"+b]._y = startPos;
    this["btn_0"+a].onEnterFrame = function () { //<<<<<<<<<<<//
    if (btn_00._y>origPos) {
    this._y--;
    }
    };
    }
    [code]

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