FORUMS: list search recent posts

Actionscript Function questions

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
RobotHero
Actionscript Function questions
on Oct 4, 2006 at 2:20:30 am

I'm getting back into Flash after a long absence, and there's two things I'm wondering about with functions.

If I define a function in a frame's actionscript, can I call it from another object? I don't understand how the scope of something like that would be handled.


But more importantly, is there a way I can have a function change the value of a parameter, so that the value of the variable used when the function was called? Some other programming languages have this, but I don't remember how to do it in Actionscript.



Return to posts index

Sher Ali
Re: Actionscript Function questions
on Oct 4, 2006 at 3:46:58 pm

First you can reference functions from anywhere and from any obect. What you have to do is to specify the correct path of the function being called.

For the first part of your question let say you have defined a function on the root timeline and there is also an object( e.g. movieclip ) on the root timeline and inside that movieclip there is a button which you want that when pressed should call the function on the root timeline.

in a keyframe at the root timeline use this script


function myFunction(){
trace("Yes! I have been called successfully.");
}

_root.myMC.myButton.onRelease = function(){

_root.myFunction();

};


For the second part I think you want like this


_root.myMC.myButton.onRelease = function() {
var b=5;
a=_root.myFunction(b);
trace(a);
}
function myFunction(c){
return ++c;
}



Return to posts index

RobotHero
Re: Actionscript Function questions
on Oct 4, 2006 at 7:05:14 pm

For the first part, I feel like an idiot, because it turns out I was just spelling the function name wrong.

For the second part, I already knew how to return values. I was wondering if there was something like reference parameters, in C++:
http://www.fredosaurus.com/notes-cpp/functions/refparams.html


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]