A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: [F8] Dirty Code

  1. #1
    Member
    Join Date
    Nov 2006
    Posts
    32

    [F8] Dirty Code

    I cannot figure out why I need a function within a function to simply go to the next function (that's a lot of functions).

    This is the code as it seems it should be:

    var stepRepeat:Number
    for (var i:Number = stepRepeat; i > 0; i--) {
    thisClip.duplicateMovieClip("thisClip"+i, i, {_y:i*20});
    if (i >= step) {nextFunction();}
    };

    nextFunction = function() {
    trace("nextFunction has been reached");
    };

    But, to get it to work, I have to add… onLoad = function() {nextFunction();}


    var stepRepeat:Number
    for (var i:Number = stepRepeat; i > 0; i--) {
    thisClip.duplicateMovieClip("thisClip"+i, i, {_y:i*20});
    if (i >= step) {onLoad = function(){nextFunction();}}
    };

    nextFunction = function() {
    trace("nextFunction has been reached");
    };

    Anyone have an idea?

  2. #2
    anyone else hear that? flashpipe1's Avatar
    Join Date
    Jan 2003
    Location
    Upstate NY
    Posts
    1,930
    Not sure, but I think you just need to name your function and call the function by name...something like:

    Code:
    var stepRepeat:Number;
    for (var i:Number = stepRepeat; i>0; i--) {
    	thisClip.duplicateMovieClip("thisClip"+i, i, {_y:i*20});
    	if (i>=step) {
    		tempName();
    	}
    }
    function tempName() {
    	trace("tempName has been reached");
    }
    Hope that helps!!
    Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.

  3. #3
    Member
    Join Date
    Nov 2006
    Posts
    32
    That's what I thought too!

    I just named mine "nextFunction" as a sample name instead of "tempName".

    I really don't understand this problem. It must have something to do with using a loop. If I create a sequence of functions, I can "run" through them with no problem by simply calling the next function, i.e… tempName();

    Appreciate your feedback!

  4. #4
    Member
    Join Date
    Nov 2006
    Posts
    32
    Learned some more things. It apparently has something to do with the "if" command.

    Try placing this into flash and testing movie:

    // this does not work
    var callFunction1:Number = 6
    if (callFunction1 == 6) {thisFunction(); trace("why doesn't this work");}

    // this works
    var callFunction2:Number = 6
    if (callFunction2 == 6) {onLoad = function(){thisFunction();}; trace("why does this work");}

    thisFunction = function() {trace("function reached");};


    Strange. Any help in understanding this would be greatly appreciated. Thanks!

  5. #5
    Member
    Join Date
    Nov 2006
    Posts
    32

    Figured it out…

    "if" will not run a function when a swf is loaded unless the function is encapsulated inside of a onLoad function:



    // step 1 :: define variable
    var myVariable:Number = 6

    // step 2 :: encapsulate in an ON LOAD function
    onLoad = function() { if (myVariable == 6) {myFunction();} };

    // step 3 :: define function
    myFunction = function() { trace("function reached"); };



    FYI for anyone who needs it…

  6. #6
    Senior Member
    Join Date
    Nov 2004
    Location
    Toronto, Canada
    Posts
    194
    delete this
    Last edited by Ogre11; 04-13-2007 at 05:35 PM.

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