A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: How do functions work?

  1. #1
    Senior Member Gloo pot's Avatar
    Join Date
    Aug 2005
    Location
    Australia Mate!
    Posts
    874

    How do functions work?

    Im just learning how to use functions properly but i kinda got no were.
    To me this script look fine but obviuosly not because it dont work.
    Can any one give me some insight on why?

    Code:
    onClipEvent (enterFrame) {
    	r = function () {
    		if (this._rotation != 90) {
    			this._rotation += 5;
    		}
    	};
    }
    on (release) {
    	r;
    }
    92.7 Fresh FM for all your South Aussies - Doof Doof music FTW people!

  2. #2
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    i don't have flash on this computer so i have no idea if this will work, never seen that done before. Hmmmm

    maybe it's the calling of the function which is wrong.
    you have:
    on(release){
    r
    }
    try this:
    on(release){
    r()
    }

    you could also try declaring the function differently, like:
    "function r(){}" rather than "r = function(){}"

    my impression of a function is that it can be run as long as it is continuously being called. Chuck a trace command in their to see if the function is actually being called.
    Last edited by mr_malee; 12-11-2005 at 03:24 AM.
    lather yourself up with soap - soap arcade

  3. #3
    Senior Member Gloo pot's Avatar
    Join Date
    Aug 2005
    Location
    Australia Mate!
    Posts
    874
    I will try that, is there another way of doing why i am trying?
    92.7 Fresh FM for all your South Aussies - Doof Doof music FTW people!

  4. #4
    Senior Member Gloo pot's Avatar
    Join Date
    Aug 2005
    Location
    Australia Mate!
    Posts
    874
    I tryed it and it did exacly the same thing as
    on(release){
    if (this._rotation != 90) {
    this._rotation += 5;
    }
    };
    And that only rotated 5 degree. I would like i loop that function. Any ideas
    92.7 Fresh FM for all your South Aussies - Doof Doof music FTW people!

  5. #5
    avatar free
    Join Date
    Jul 2002
    Location
    UK
    Posts
    835
    First of all, it's probably not a good idea to keep registering the function r inside an onEnterFrame event. Put it in an onLoad event if need be so it's only made once.

    Second, you are calling this inner function in an onRelease event, so it will only be called when you release the key/button/mouse ( whatever release is for, can't remember. )

    So, if you want r() to be called every frame ( continuously ) then it needs to be called in an onEnterFrame event.

    Hope that helped.
    jonmack
    flash racer blog - advanced arcade racer development blog

  6. #6
    Senior Member Gloo pot's Avatar
    Join Date
    Aug 2005
    Location
    Australia Mate!
    Posts
    874
    Yea i understand, but i want the function to run after i release my MC. My code only runs the function for 1 frame but it would usealy last about 30.

    So what i need.
    On release of my MC
    run r function untill its complete.
    92.7 Fresh FM for all your South Aussies - Doof Doof music FTW people!

  7. #7
    skylogic.ca MD004's Avatar
    Join Date
    Oct 2003
    Location
    Canada
    Posts
    366
    Code:
    on (release) {
    	this.onEnterFrame = function () {
    		if (this._rotation != 90) {
    			this._rotation += 5;
    		}
    	}
    }
    That's how I'd do it, but then you probably want it to stop eventually so you can use "delete this.onEnterFrame;" wherever you want it to stop.

    ~MD

  8. #8
    Senior Member Gloo pot's Avatar
    Join Date
    Aug 2005
    Location
    Australia Mate!
    Posts
    874
    Thanks for that.
    92.7 Fresh FM for all your South Aussies - Doof Doof music FTW people!

  9. #9
    Senior Member The Helmsman's Avatar
    Join Date
    Aug 2005
    Location
    _root
    Posts
    449
    code:

    // define function
    function r():Void {
    if (this._rotation != 90) {
    this._rotation += 5;
    }
    }

    // define event
    <btn name>.onRelease = function():Void {
    r();
    }


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