Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

include script

Status
Not open for further replies.

jefargrafx

Instructor
May 24, 2001
273
US
can you use the include action to include the script from one object into another...

say you have a script on one button and want the same script on another button? Or do you have to insert the script on both buttons from one external script file??

let me know jef
 
Flash has a "Function" action which works in much the same was as you described... Flash still has the "Call" action but from what I hear it is deprecated.

I have only used the "Function" action one time and it has been a while but if I remember correctly I set up a function complete with what I wanted it to do then called that function from various places in the movie.

Might be something you could look up in the Flash help files and get a good example of what it is and what it will do. Ya' Gotta Love It!
sleepyangelsBW.jpg
 
Here it is straight from the help files:


function

Syntax

function functionname ([argument0, argument1,...argumentN]){
statement(s)
}
function ([argument0, argument1,...argumentN]){
statement(s)
}
Arguments



Hope this helps...

functionname The name of the new function.

argument Zero or more strings, numbers, or objects to pass the function.

statements Zero or more ActionScript statements you have defined for the body of the function.

Description

Action; a set of statements that you define to perform a certain task. You can declare, or define, a function in one location and call, or invoke, it from different scripts in a movie. When you define a function, you can also specify arguments for the function. Arguments are placeholders for values on which the function will operate. You can pass a function different arguments, also called parameters, each time you call it.

Use the return action in a functions statement(s) to cause a function to return, or generate, a value.

Usage 1: Declares a function with the specified functionname, arguments, and statement(s). When a function is called, the function declaration is invoked. Forward referencing is permitted; within the same Action list, a function may be declared after it is called. A function declaration replaces any prior declaration of the same function. You can use this syntax wherever a statement is permitted.

Usage 2: Creates an anonymous function and returns it. This syntax is used in expressions, and is particularly useful for installing methods in objects.

Player

Flash 5 or later.

Example

(Usage 1) The following example defines the function sqr, which accepts one argument, and returns the square(x*x) of the argument. Note that if the function is declared and used in the same script, the function declaration may appear after using the function.

y=sqr(3);
function sqr(x) {
return x*x;
}
(Usage 2) The following function defines a Circle object:

function Circle(radius) {
this.radius = radius;
}
The following statement defines an anonymous function that calculates the area of a circle and attaches it to the object Circle as a method:

Circle.prototype.area = function () {return Math.PI * this.radius * this.radius}
Ya' Gotta Love It!
sleepyangelsBW.jpg
 
best to use a function in this case, ie:

frame1
function dave() {
trace ("you have pressed a button");
}

action on button(s)
on (release) {
dave();
}

dave
dave@pinkzeppelin.com

^^^^^^^^^^^^^^^^^^^^^​
 
never thoguth of using a function...of course

Dave? can you wrtie a function on the first frame of a movie and call it from anywhere within that movie?

thanks jef
 
remember you need to target the function like any other variable/mc. So if you define the function given above in frame1 on the main timeline, and you want to call the function from within another movie-clip then the action would be:

Code:
_root.dave();

dave
dave@pinkzeppelin.com

^^^^^^^^^^^^^^^^^^^^^​
 
yes...I figure that out, thanks for the advice

jef jef
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top