Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

Results 1 to 5 of 5

Thread: Enterframe being executed only once....

  1. #1

    Enterframe being executed only once....

    Code:
    stop();
    var numOfItems=1;
    var radiusX =30;
    var radiusY = 75;
    var centerX = Stage.width / 2;
    var centerY = Stage.height / 2;
    var speed = 0.05;
    
    for(var i=0;i<numOfItems;i++)
    {
        var logo=this.attachMovie("logo_mc","logo_"+i,i+1);
        logo.angle = i*((Math.PI*2)/numOfItems);
        logo.onEnterFrame=move_function();
    }
    
    
    function move_function()
    {
        this._x = Math.cos(this.angle)*radiusX+CenterX;
        this._y = Math.sin(this.angle)*radiusY+CenterY;
        this.angle+= this._parent.speed;
    }
    I have the following code in one of the frames in my game...but for some reason the move_function() is being called only once....why is this happening, and how do i fix it?
    MY BLOG

    I need a SPRITER who can do pixel arts for an arcade fighter project. If you can help out, please pm me.
    I also need someone who can write simple xml files.


  2. #2
    because it's happening only when it enters frame.

    put it inside a:

    onEnterFrame = function{

    }


    And it'll be called all the time.

  3. #3
    you don't need the brackets

    ie

    Code:
     logo.onEnterFrame=move_function;
    not

    Code:
     logo.onEnterFrame=move_function();

  4. #4
    Thanks neilmmm, it worked perfectly...but i dont understand how it worked? what is the difference with () and removing them? oh...and if i cannot use those braces, how will i pass parameters to the function?
    MY BLOG

    I need a SPRITER who can do pixel arts for an arcade fighter project. If you can help out, please pm me.
    I also need someone who can write simple xml files.


  5. #5
    207
    posts
    Registered User
    Code:
    logo.onEnterFrame=move_function();
    executes the function and assigns the return value to onEnterFrame

    Code:
    logo.onEnterFrame=move_function;
    Assigns the function itself to onEnterFrame.

    You can only pass parameters at the time the function is executed.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012