Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




Functions



I have finally got the hang of loading in content but what I want to know is how do I access functions on the main timeline. For example I load in home.swf into main.swf and I want to access a function on main.swf. Is this possible?



KirupaForum > Flash > ActionScript 3.0
Posted on: 02-27-2008, 12:43 PM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

Made Functions Using For Loop, Trace Returns Undefined When Running Functions?
ActionScript Code:
var navAreas:Array = new Array("LOL", "WOOT", "ROFL");for (var f:Number = 0; f < navAreas.length; f++) {    this["action" + f] = function () {        trace(navAreas[f]);    };        // should make functions action0, action1, action2.}action1(); // shou'd return WOOT, but returns undefined.  

Dynamic Functions - Creating Functions At Runtime Without So Many Ifs/elses...
Hi, nice to register after lurking for a while and seeing how smart people are on here......

I am writing some code that needs to be very efficient, yet flexible. This is in a class and when the class gets initialized a function is setup. I want this function to run straight through without doing any time-consuming things such as calling other functions or routines, or doing any if/else logic/branching.

Now I know that you can setup a function at anytime during runtime such as:


Code:
var myFunction:Function = function() {trace('HELLO!')}
But what I am trying to do is to try and append code to a function based on logic, yet I don't want the function to be deciding this logic when it is running as it will only need deciding when the function is created.... imagine if it were a string it would be something like myFunction+="do somethingelse;" which would be the same as having initially setup myFunction as such:


Code:
var myFunction = function() {do something; do somethingelse;}
With this I seem to be having no luck

Here's an example where I setup the most compact/efficient function at runtime depending on what I want the function to do. Now this was fairly simple because when we create the function there are only a few possible variations, but I need someway of doing a function+= as my real code has quite a few variations and it would be a nightmare have a zillion if/else branches. REMEMBER I do not want any logic/decisions in the function itself as it to be the most efficient the function must be as compact as possible and run straight-through.


Code:
var dynamicFunction:Function;
//
// Setup the dynamic function & call it
// In this example outputs "Hello Jim" & "Goodbye Jim"
dynamicFunction = CrapSetupRoutine(true, true, "Jim");
dynamicFunction();
//
// Try and setup the dynamic function using a less ify/elsey (less complicated) routine & call it
// In this example it doesn't work if we try and make it say both Hello & Goodbye like above :(
dynamicFunction = SetupRoutineIWouldLike(true, true, "Jim");
dynamicFunction();
//
function CrapSetupRoutine(sayHello:Boolean, sayGoodbye:Boolean, yourName:String):Function {
var returnFunction:Function;
// Far too many ifs/elses...but remember the function created cannot have any if/else logic or calls to other functions
if (!sayHello and !sayGoodbye) {
returnFunction = function () {
trace("<dynamicFunction> sits bored");
};
} else if (sayHello and sayGoodbye) {
returnFunction = function () {
trace("Hello "+yourName);
trace("Goodbye "+yourName);
};
} else {
if (sayHello) {
returnFunction = function () {
trace("Hello "+yourName);
};
} else {
returnFunction = function () {
trace("Goodbye "+yourName);
};
}
}
return returnFunction;
}
//
//What I actually want the Setup function to resemble is this
function SetupRoutineIWouldLike(sayHello:Boolean, sayGoodbye:Boolean, yourName:String):Function {
var returnFunction:Function;
// the ifs/elses are as minimal as possible, which is good
if (!sayHello and !sayGoodbye) {
returnFunction = function () {
trace("<dynamicFunction> sits bored");
};
} else {
if (sayHello) {
returnFunction = function () {
trace("Hello "+yourName);
};
}
if (sayGoodbye) {
// the += below doesn't work.....so the question is how to append to it?????
returnFunction += function () {
trace("Goodbye "+yourName);
};
}
}
return returnFunction;
}
// The end
P.S. I knew the += would never work as this is a function and not a string. But at least if you think of the function as a string you'll get what I'm trying to do.....I suspect if it can be done it involves casting or something and maybe using strings initially??

Multiple Functions Or Long Functions With For.. Statements?
Which is better? A long function with a couple of for... statements, or multiple functions with only one for... statement in it?

Andy

Class Functions Not Able To See Other Member Functions/variables?
I am having a problem which has crept up on me a few times now. I am trying to call another member function within the same class, but Flash is unable to recognize it. This also happens when I try to read values of come variables.

For example, here I am trying to set the private boolean member variable to the state of the checkbox.

//NOTE: This is an EventListener. Does this change something major?

private function CheckBoxClick( evt )
{
_enabled = _root["test_sp"].content[_checkBoxName].selected;
trace( _checkBoxName + " checked: " + _root["test_sp"].content[_checkBoxName]._y );
}

This will output the following: "undefined checked: undefined"

Now in the function directly above it, I have the following function:

public function SetYPosition(pos:Number)
{
trace( _checkBoxName );
_root["test_sp"].content[_checkBoxName]._y = pos;
}

And this function will correctly output the checkbox name as well as update the position.

If I try adding the function call "SetYPosition(500);" to the first function (CheckBoxClick), the function will never be called as if Flash cannot see it.

In the past I have avoided this by using the global instance of the class such as _global.settings.function(blah), but the class I am working on now does not have a global instance.

Any ideas? This is really annoying!

Thanks!!!































Edited: 06/27/2007 at 03:30:12 PM by JoMasta

[F8] Running Functions From Within Functions In A Class
For some reason, whenever I try to run a private function from within another private function in a class, it doesn't work.


Code:
private function getVars(theVar) {
switch (theVar) {
case "m" :
return this.m;
break;
case "nI" :
return this.nI;
break;
case "rX" :
return this.rX;
break;
case "rY" :
return this.rY;
break;
case "cX" :
return this.cX;
break;
case "cY" :
return this.cY;
break;
case "s" :
return this.s;
break;
case "a" :
return this.a;
break;
default :
return "";
}
}



Code:
private function cSpeed():Void {
// ccX is just a placeholder for the cX variable
// so that the function can use it.
var ccX:Number = cX;
m.onMouseMove = function() {
s = (this._xmouse-ccX)/1500;
getVars("m");
}
}


I just used getVars("m") for the hell of it...just to see if it would work...but it didn't. Any idea why not?

[F8] Calling Functions Within OnEvent Functions.
Ive just stumbled upon an annoying problem, Im writing a custom class which, in its constructor attaches a movie clip to a main one (passed in as a parameter).
this all works fine.
My problem arises when i try to, also in the constructor, create an onRollOver event on the movieclip i attached earlier (its stored in a field).

The onRollOver event works fine, calling the trace statement ive been using, but it won't call any function which i ask for.


this is the code where im having issues:


Code:

function Corner(xPosition:Number, yPosition:Number, circ:Circle, deep:Number, baseClip:MovieClip)
{
this.image = baseClip.attachMovie("Corner","CornerX",deep);
this.image._x = xPosition;
this.xPos = xPosition;
this.image._y = yPosition;
this.yPos = yPosition;

this.circle = circ;

this.image.onRollOver = function()
{
trace("debugOne"); //this trace statement works fine

this.otherFunction(); //Problem is here, The code wont call this function for some reason
}

this.depth = deep;
}

function otherFunction()
{
trace("debugTwo");
}
any ideas why its not calling my function?

[F8] Functions Inside Functions? Urgent
Hi, is this in any way valid?


Code:
this.onRelease = function(){
_root.mainbutton(){
freeze == false;
}
i have a set of buttons id like to play their animations when i press a button. Can this be done?

Any help or pointers would be greatly appreciated, thanks!

Declaring Functions In Other Functions And Callbacks
Hi - I'm curious to know if the following situation is possible (I haven't gotten it to work yet).

I'd like to load a series of images, and in the callback, place them in different positions in my array. Instead of writing a separate callback for each image, I'd like to do something like the following:

But it looks like each version of the function gets the end version of "i", not the version of i that existed when the function was declared.

Is something like this at all possible?







Attach Code

public function loadImages():void
{
for (var i:int = 0; i < 4; i++)
{
function myCallback(e:Event):void
{
myArray[i] = Bitmap(e.target.loader.content);

}
loadImageWithCallback(image, myCallback);
}
}

Functions Passed As Arguments To Other Functions
FLASH MX 2004 - AS2.0

I have a function with 4 necessary arguments (aka parameters) in order to perform the actions. I would like to have the ability to pass the same function to itself as an argument (sort of like a recursive function) along with its arguments. Basically I want to "base" to engage an onMotionFinished event handler if there is another function passed as an argument. Something like...


PHP Code:



   function base (arg1, arg2, arg3 arg4, {arg5:another function, arg6:arg5s arg).....}){  //do the stuff  instructions = blahblahblah  if (arg5 is present){     instructions.onEventHandler = function(){         //perform function which is arg5...argN     }  } } 




Would there be a way to use listeners to do this or the AsBroadcaster? Thanks

Functions Trough Functions...
Hi, I have some problems with relative/absolute functions...
The code is:

--------Main.fla:


Code:
import Bus;

var aBus:Bus=new Bus(wooz);

function wooz()
{
trace("wooz!!");
trace(this);
}

this.onMouseUp=function()
{
wooz();
}

wooz();
aBus.TryCallback();

---Bus.as



Code:
class Bus
{
var _couleur:String;
private var _Func:Function;

function Bus(Func:Function)
{
trace("exec func...");
_Func=Func;
}

function TryCallback()
{
_Func();
}
}
I would like to have an output like this:

wooz!!
_level0
wooz!!
_level0



...But i obtain this


wooz!!
_level0
wooz!!
[object Object]

I would like to keep _level0 as this, and not object, who aBus

Can U help me please???

thanks

Trace A Functions Name From Within Functions
I am setting up a series of function. I want to use the function name as a variable inside each function like this:

var thisFunction;

function functionName(){
thisFunction = this.name
trace(thisFunction)
}

I want to set funcName to the the name of the function, someName.
Thanks in advance!

Functions Inside Functions?
Hello all -

The following code is in a external AS file that is called in the first frame of the movie. When I have it play outside of a function, it works fine. As soon as I put inside a function, it does not work. The code is


ActionScript Code:
var _mcl:MovieClipLoader = new MovieClipLoader();
var _listener:Object = new Object();
_listener.onLoadInit = function(_mc:MovieClip)
{
    trace("Done loading...");
}
_mcl.addListener(_listener);


this._mcl.removeMovieClip(clip_1);
this.createEmptyMovieClip("clip_1", this.getNextHighestDepth());
_mcl.loadClip("back.swf", clip_1);

I am new to AS, so I am trying to figure out if something in this code is not allowed when I put it into a function. I tested the function using trace statements to make sure it was being called and it was, so the problem seems to lie in this code. Does anybody know why this code will not work when put in a function? Thanks!

Functions Calling Other Functions
what i need to do is call a set of functions several times in sequence with different parameters each time. here's what i've got

Code:
/////photoload code////
this.fadeSpeed = 10;
this.fadeSpeed2 = 10;
var picToLoad = "";
var whereToLoad = "";

MovieClip.prototype.changePhoto = function(ddd,whatwhat) {
this.picToLoad = ddd;
this.whereToLoad = whatwhat;
trace("this.picToLoad = ddd **** "+this.picToLoad+" + "+ddd);
trace("this.whereToLoad = whatwhat ***** "+this.whereToLoad+" + "+whatwhat);
this.onEnterFrame = fadeOut;
};
MovieClip.prototype.fadeOut = function() {
if (this.whereToLoad._alpha>this.fadeSpeed) {
this.whereToLoad._alpha -= this.fadeSpeed;
} else {
this.loadPhoto2();
}
};
MovieClip.prototype.fadeOut2 = function(xox) {
trace("fadeOut2 function called");
this.whichToFade = xox;
if (this.whichToFade._alpha>this.fadeSpeed2) {
this.whichToFade._alpha -= this.fadeSpeed2;
}
};
MovieClip.prototype.fadeOut3 = function() {
trace("this.whichToFade = "+this.whichToFade);
if (this.whichToFade._alpha>this.fadeSpeed) {
this.whichToFade._alpha -= this.fadeSpeed;
}
};
MovieClip.prototype.loadPhoto = function() {
// specify the movieclip to load images into
var p = _root.sectImg;
//------------------------------------------
p._alpha = 0;
p.loadMovie(this.pathToPics+this.pArray[this.pIndex]);
//this.onEnterFrame = loadMeter;
};
MovieClip.prototype.loadPhoto2 = function() {
// specify the movieclip to load images into
var p = this.whereToLoad;
//------------------------------------------
p._alpha = 0;
p.loadMovie(this.picToLoad);
this.onEnterFrame = loadMeter;
};
MovieClip.prototype.loadMeter = function() {
var i, l, t;
l = this.whereToLoad.getBytesLoaded();
t = this.whereToLoad.getBytesTotal();
if (t>0 && t == l) {
this.onEnterFrame = fadeIn;
} else {
trace(l/t);
}
};
MovieClip.prototype.fadeIn = function() {
if (this.whereToLoad._alpha<100-this.fadeSpeed) {
this.whereToLoad._alpha += this.fadeSpeed;
} else {
this.whereToLoad._alpha = 100;
this.onEnterFrame = null;
}
}
and then i've written the following to run the above functions:


Code:
MovieClip.prototype.controlPhoto = function(props) {
var ddd;
var whatwhat;
trace("arguments.length = " + arguments.length);
trace("props = "+props);
trace("arguments = "+arguments);
for (var cpi = 0; cpi<arguments.length; cpi++) {
trace("------ "+ cpi + " ------");
trace("arguments[cpi] = "+arguments[cpi]);
var my_array:Array = arguments[cpi];
my_array.slice();
trace(my_array[0]+" *** "+my_array[1]);
ddd=my_array[0];
whatwhat=my_array[1];
this.changePhoto(ddd,whatwhat);
}
}
and i'm calling this function like this:

Code:
curr_item.onRelease = function() {
_root.controlPhoto([this.img1,sectImg],[this.img2,leadImg]);
}
but what happens is only the last set of parameters actually get loaded. everything else seems to be skipped over. any help is appreciated!
thanks,
david

Mc Functions Inside Functions
I created an empty movie clip. The object in the clip is drawn with actionscript.

I wanted for the object to do different things when different keys were pressed. Like so:

ActionScript Code:
clip.onKeyDown = function() {if (Key.getCode() == Key.DOWN) {clip.onEnterFrame = function() {_root.callFunction();}} else if (Key.getCode() == Key.UP) {clip.onEnterFrame = function() {_root.callFunction();}}}

It's a simple example showing that the onEnterFrame function does about the same thing for each keys. Am i doing this right, or can the onEnterFrame function be defined once and i can call it from the onKeyDown function?

Thanks,
Jerome

Functions Calling Other Functions
what i need to do is call a set of functions several times in sequence with different parameters each time. here's what i've got

Code:
/////photoload code////
this.fadeSpeed = 10;
this.fadeSpeed2 = 10;
var picToLoad = "";
var whereToLoad = "";

MovieClip.prototype.changePhoto = function(ddd,whatwhat) {
this.picToLoad = ddd;
this.whereToLoad = whatwhat;
trace("this.picToLoad = ddd **** "+this.picToLoad+" + "+ddd);
trace("this.whereToLoad = whatwhat ***** "+this.whereToLoad+" + "+whatwhat);
this.onEnterFrame = fadeOut;
};
MovieClip.prototype.fadeOut = function() {
if (this.whereToLoad._alpha>this.fadeSpeed) {
this.whereToLoad._alpha -= this.fadeSpeed;
} else {
this.loadPhoto2();
}
};
MovieClip.prototype.fadeOut2 = function(xox) {
trace("fadeOut2 function called");
this.whichToFade = xox;
if (this.whichToFade._alpha>this.fadeSpeed2) {
this.whichToFade._alpha -= this.fadeSpeed2;
}
};
MovieClip.prototype.fadeOut3 = function() {
trace("this.whichToFade = "+this.whichToFade);
if (this.whichToFade._alpha>this.fadeSpeed) {
this.whichToFade._alpha -= this.fadeSpeed;
}
};
MovieClip.prototype.loadPhoto = function() {
// specify the movieclip to load images into
var p = _root.sectImg;
//------------------------------------------
p._alpha = 0;
p.loadMovie(this.pathToPics+this.pArray[this.pIndex]);
//this.onEnterFrame = loadMeter;
};
MovieClip.prototype.loadPhoto2 = function() {
// specify the movieclip to load images into
var p = this.whereToLoad;
//------------------------------------------
p._alpha = 0;
p.loadMovie(this.picToLoad);
this.onEnterFrame = loadMeter;
};
MovieClip.prototype.loadMeter = function() {
var i, l, t;
l = this.whereToLoad.getBytesLoaded();
t = this.whereToLoad.getBytesTotal();
if (t>0 && t == l) {
this.onEnterFrame = fadeIn;
} else {
trace(l/t);
}
};
MovieClip.prototype.fadeIn = function() {
if (this.whereToLoad._alpha<100-this.fadeSpeed) {
this.whereToLoad._alpha += this.fadeSpeed;
} else {
this.whereToLoad._alpha = 100;
this.onEnterFrame = null;
}
}
and then i've written the following to run the above functions:


Code:
MovieClip.prototype.controlPhoto = function(props) {
var ddd;
var whatwhat;
trace("arguments.length = " + arguments.length);
trace("props = "+props);
trace("arguments = "+arguments);
for (var cpi = 0; cpi<arguments.length; cpi++) {
trace("------ "+ cpi + " ------");
trace("arguments[cpi] = "+arguments[cpi]);
var my_array:Array = arguments[cpi];
my_array.slice();
trace(my_array[0]+" *** "+my_array[1]);
ddd=my_array[0];
whatwhat=my_array[1];
this.changePhoto(ddd,whatwhat);
}
}
and i'm calling this function like this:

Code:
curr_item.onRelease = function() {
_root.controlPhoto([this.img1,sectImg],[this.img2,leadImg]);
}
but what happens is only the last set of parameters actually get loaded. everything else seems to be skipped over. any help is appreciated!
thanks,
david

Using Functions To Define Functions
Hi all,

I'm trying to recode an MX script to F5, and its not working.

on a mc 'mcGoalie' i have the code;

onClipEvent(enterframe){
this.moveGoalie';
}

on root timeline:

function moveGoalie(){
....
}

so at the beginning, the prototype is not defined, so nothing happens.
then on a button (to start the game) i have the code

on(press){
Movieclip.prototype.moveGoalie=_root.moveGoalie();
}

then to stop

on(press){
Movieclip.prototype.moveGoalie=undefined;
}

which works.

problem is, i want a general startGame function to get everything going.

function startGame(){
Movieclip.prototype.moveGoalie=_root.moveGoalie();
}

then on start button

on(press){
_root.startGame();
}

which doesn't work.
can use use functions (here startGame) to define other functions and Movieclip prototypes? if not anyone know of a work around?

cheers

s[H]ura

Functions
Can functions be "called" in frames? I've experimented with "calling" functions within buttons...no prob there, but if I want to "call" it in the last frame of a clip, for example, will it work?

red penguin

A Bit Of Help With Functions
hey all, i was wondering if anyone knew the easiest way to make "global" functions

ones that i could access from any movie clip, at anytime

i tried putting them all in a movie clip but i couldn't get them to execute right after.

Fun With Functions
I'm relatively new to this actionscript malarky, and am having a bit of trouble with functions: I want to be able to reference a number of instances with one 'word'. I presume to do this with functions rather than a variable. Any help may or may not be financially rewarded! M

Functions
Hi! long time no word but now I'm back

Have a question - how to delcare and call functions in Flash? I guess functions are useful just like in C or Pascal... so I want to use them... please give me some directions.


Thanks in advance....
Star

Functions
when you define a function from a movie clip, can you use it on all levels or just that specific mc?

Key Functions? Please Help.. 911
First off, thank you for any replys.

I am creating a Flight Sim, and using flash for a little bit of it. I need to know if it is possible to use a JoyStick with Flash.. Kinda like on key press, but with a Joystick. It there AS or anything to do this?? Maybe a plugin? Or would I have to use like VB6 or something?

Also, How do you do object collision? to where if something moves over another thing it performs an action. Like on MouseOver, but when you move a MC with Keys or JS.. so like... on MC over. So when the MC goes over a button it does something? Any ideas? Thank's for everything guys!

-Paradoxz

Functions?
I am trying to understand Functions alittle better but am haveing trouble (Obviouslly).
I want to make a function that would change the properties of a MC. I have a MC with a button in it.
on (press){
move();
}
Then I have the function set up on the main stage frame 1:
function (){
for (i=0;i<10;i++) {
_x = _x+i;
}
}

but that doesn't work. What am I doing wrong? Do I have to put something in the () on the button or the function? Can some one please explain this to me and show me a code that does work. Thi8s is just an example not really important work here, but I do want to understand it.

Ahh Help Please With Functions
hello:

Is it that difficult to call a function? Ok here goes, I have a movie clip that has a loadmovie(url) like this:
function mySong(){
loadmovie("/whatever.swf",_root.movieclipName);mySound = new Sound(); mySound.attachSound(whateversong);mySound.start. Ok thats the movieclip code I add the movie clip to my main stage and I have a button that I want to call the function...how can I do that Help please...thanks in advance

Functions
How to use to place MC's randomly on the stage? So far my code is:
---------------------------------------------------------
onClipEvent (enterFrame) {
this._x = random(300);
this._y = random(100);
}
---------------------------------------------------------
can anyone help with this?

Functions
Hello,
I am trying to make a function that will attachMovie() at a certian location then animate it. Like this:

function flare() {
attachMovie("flare","flare1",1);
_root["flare1"]._x = 200;
_root["flare1"]._y = 200;
if ( _root["flare1"]._x < 400) {
_root["flare1"]._x++;
}else{
removeMovieClip();
}
}
I know this script is not even close to being right. That's why I'm here.
Any input would be great. Thanks in advance.

Functions
I'm just wondering the proper set up for
a) creating a function
b) running that function

thanks for your help

Functions?
HI Everyone,

I am currently working on a dynamic map and have each country saved as a mc called "c1,c2,c3,c4,c5 etc".

The values of which are being updated through a text file whereby

0=inactive
1=black
2=white
3=yellow
4=pink
5=black

etc upto 20 colours

At the moment due to the volume of countries & colours involved , my actionscript is huge:-

// inactive
if (_root.c1text.countytext == "0") {
setProperty ("_root.c1", _visible, false);
} else {
setProperty ("_root.c1", _visible, true);
}
if (_root.c1text.countytext == "1") {
c1_color = new Color(c1);
c1_color.setRGB(0x000000);
}
if (_root.c1text.countytext == "2") {
c1_color = new Color(c1);
c1_color.setRGB(0xffffff);
}

etc

I am having to write this code for each value and each country.

Is there any way I can include a function whereby assigning a colour is shorter ie.

//country 1
if (_root.c1text.countytext == "0") {
function inactive();
}
if (_root.c1text.countytext == "1") {
function black();
}

Hope you can help!

Thanks in advance,

Duncan

Functions...
okay simple question, when i call a function like so:

doSomething();

does it know where to find that function, and in retrospect where do i put it. I believe I am to put it on the first frame of the movie, and as long it stays in that scene, anywhere I call it, the compiler will know that the funtion is on frame one of the movie... Please help me out, i ma quite advanced in the coding of flash, but i have never had the need to learn functions in flash....So i don't know the location of where the function should be.

Thanks in advance:
~Zakarus2001

Functions
I'm used to coding in C++ so the one aspect of Actionscript which still confuses me is finding the right place for Actionscript code. Basically I have several movieclips with the same code on each, so I wanted to place the code into a function. Where should I place the function so all the movieclips have access to it and how would I call it? Thanks.

Not Getting Along With Functions....
I've got this code:

function Slide(xt, z){
xDist=xt-z._x;
speed=6;
z._x+=xDist/speed;
}

in the first frame of the main stage. then i've got this code:

onClipEvent(enterFrame){
Slide(0, this);
}

in an MC on the main stage. the function doesnt work. i don't know why... i've never had very good luck with functions and i'm not even sure if the z variable included in this one is necessary (it determines a target for the changes in the function to be applied to). This function should *in theory* easy the object that calls it from its current location to the supplied variable 'xt' or x target. I'm basically stuck and my reference book is 47 miles away at the moment so... Any help would be appreciated.

HELP WITH FUNCTIONS
hi i have written this function but im having trouble with it, what it does is when u allpy this script onto a button, that is in side a movie clip


Code:
_root.target = 200
it resizes the button like a spring, natural effect. now the script works when i had code it, but now ive put it into a script i cant get it to work. any ideas guys?



this function is below
[code]


function test () {
target = 100;
friction = 0.8;
ratio = 0.3;
speed = 0;

if (target != this._xscale) {
speed = (speed*friction)+(target-this._xscale)*ratio;
this._xscale = speed+this._xscale;
this._yscale = speed+this._yscale;
}
}

Functions
Hi can any one help'

I have a menu in a movieclip which on click (Not rollover)opens a box then if you click on another link it closes the 1st box before opening the new box.

How can you check that on clicking of a link it checks to see if the closing animation has finished before opening the new animation ?

I have tried a timer but wanted to know if their was a function i could use which checks the current frame and then moves to the next relevant section in the movieclip when the first section has played its closing animation.

manythanks
flash newbie

Functions?
Hey guys,
One last question. I have this equation that makes an object move from a location to a target location. This is my first attempt at making a function which ultimately ended up looking like this

function move(object, destination){
_root.object._x=_root.object._x+(_root.destination ._x-_root.object._x)/10;
_root.object._y=_root.object._y+(_root.destination ._y-_root.object._y)/10;
}

However, im sure that there is something wrong with the syntax. I tried to pass the object and destination parameter through but it doesnt seem to work like that. Can anyone find the error in this code. Everyone's help is much appreciated. Thanks

Functions...
Hi all =)

Ok. I have an mc, and 2 buttons. one to start it, one to stop it.. that all works fine

i want another button, to work like an "on / off" button. When pressed the first time, the mc (instance name=cubes) fades into view, NOT playing. Then, when button is pressed again, the cubes fade out...

i assume you do this using _alpha. ... but i've no idea how to actually make the function

any help / advice, greatly appreciated.
thanks

Functions?
Hey guys,
If I have a function declared on the main timeline, can i declare it in a movie clip that is on the main timeline ?

New To Functions
Thanks for coming in.

Right now I am trying to create a function that will mess with a movie clip's properties. I am trying to use the "this" command line but it isn't working...

Here's the code:


Code:
function appleMove (bob){
bob._rotation = 100;
}


and then on the movie clip I have this


Code:
onClipEvent(enterFrame){
appleMove (this);
}


what am I doing wrong?

-Kac

Functions
Could someone tell me how to execute a funtion in a parent movie clip. Ie. _root.functionname(); , is what i mean, obviously that doesnt work though.

Functions Again...
hi all,

i posted a question about a week ago regarding functions, but have had little success.

i have included a fla for you to have a look at on flash 5.

my problem is, how can i make a function that rotates multiple mc's?

i have this in my first frame

function test(){
_root.box1._rotation = random (360);
}

and in the seccond frame i have 2 mc's (box1, and box2)

on those boxs i have the function call of:

test();

my problem is, i want multiple mc's with a simple line of code like the above rotation code, and apply it to all of the boxs.
ive tried using:

this._rotation = random (360);

but that spins my whole project arround

any ideas?

also what would happen if i used test(); beyond the _root?

thanks heaps

Functions For You :)
Let's share our functions to help everyone code faster!

I made this function for randomizing the contents of an array.

Used it for games and stuff....

function arrayRandomize(originalOrder, itemNum, randomOrder) {
for (i=0, j=itemNum; i<itemNum; i++, j--) {
var k = random(j);
randomOrder[i] = originalOrder[k];
originalOrder.splice(k, 1);
}
return randomOrder;
}

Functions
okay ive heard that a couple of times but i dont know what it means.
the function thing in as. can someone explain it to me? im not very new to programming, but new to flash, and altho i could probly use it i dont know how it works.
thank you =)

Functions
I need some help with the script... I'm trying to make a soundwve in a grid. The wave is static. The grid, waves and axes are made by curveTo and lineTo commands. But I need to change some variables and call this script to refresh itself, so that the curve/wave changes its position. The variables need to change when I click at different piano tones/notes in this flash file and to call a method/function that refreshes and draws the curve with its new parameters. I've never wrote any code in flash before, so I don't now how to do this. The script I have is:

Clear();
int (x1 = 150);
int (y1 = 20);
int (gridx = 80);
int (gridy = 10);

lineStyle (2, 0x0000ff, 100);
moveTo(100,170);
lineTo(600,170);
moveTo(100,20);
lineTo(100,320);


for(int (t=0); t<9; t++){
moveTo(x1,160);
lineTo(x1,180);
x1 = x1 + 50;
}
for (int (u=0); u<7; u++)
{
moveTo(90,y1);
lineTo(110,y1);
y1= y1 + 50;
}
moveTo(100,170);
curveTo( 150, 320, 200, 170 );
curveTo( 250, 20, 300, 170 );
curveTo( 350, 320, 400, 170 );
curveTo( 450, 20, 500, 170 );


//Grid
lineStyle (1, 0x000033, 30);
for(int (tellerx=0); tellerx < 55; tellerx++)
{
moveTo(gridx, 10);
lineTo(gridx,330);
gridx = gridx + 10;
}

for(int (tellery=0); tellery < 33; tellery++)
{
moveTo(80, gridy);
lineTo(620,gridy);
gridy = gridy + 10;
}
I need the curve to change postition when a new tone/note is clicked.

I also need the amplitude to change its value when volume "100%", "75%", "50%", "25%" and "Off" is clicked.

Please help me with this...

Help With Functions
Hello, i'm not completely new to actionscript, but i'm not very good at it either. In actionscript you can use functions but so far it doesn't work for me. How would I use functions to do a username and password thing in flash? I have 2 input text boxes in the first frame of the movie and a 2nd frame which says "Correct!"

Then I have a button that is supposed to start the function but it does nothing for me. This is the code on the first frame that I added:

Code:
function checkPass (user,pass) {
if (!user == "me" && !pass == "none") {
_root.gotoAndPlay(2);
}
}
stop();


then on the button I have:


Code:
on (release) {
userpass = checkPass(me,none);
}


I have no idea how to make this work. I don't really need a "wrong password" screen seeing as how if someone helps me figure this out i will most likely be able to do it on my own but so far i'm stumped.

Thanks in advance!
~Epsilon

Functions
Hi,
How to make a function ?

what is the argument ?

return ...

Thanks

Functions
I'd like to do a function for opening URL's in a new window that I can use from anywhere in my movie. If I declare it

function openLink( document ){
prelink = "JavaScript:NewWindow=window.open('";
postlink = "', 'newWin', 'width=400, height=300, left=0, top=0, toolbar=No, location=No, scrollbars=No, status=No, resizable=No, fullscreen=No'); NewWindow.focus(); void(0);";
sUrl = prelink + document + postlink;

getURL (sUrl);
}


then where should I place the declaration in the movie? If I just place it in the beginning of the layer of where I'm using it it doesn't work...

/M

Functions
i am working on a matching game from a flash game book. the game recognizes when a pair is matched however, i need it to read that pair and launch specific movies, i can't seem to do that. i'm assuming i have not been able to set up the proper function. any help would be much appreciated. to download the file go to http://www.manningproductions.com/matching2.fla

Functions
i am working on a matching game from a flash game book. the game recognizes when a pair is matched however, i need it to read that pair and launch specific movies, i can't seem to do that. i'm assuming i have not been able to set up the proper function. any help would be much appreciated. to download the file go to http://www.manningproductions.com/matching2.fla

Functions
Does anybody have like a handbook on what the funtions and what each action does in flash (only the actions) and i dont know how people configure stuff through the action panel? do you have to be good in math?

Functions Within Functions
Please help - I've recently started using Actionscript and I'm trying to make this code work on the main timeline. What am I doing wrong? Can you not call functions within functions, and if not, how do I get round the problem? Here is the code:

_root.islandmain.onEnterFrame = function() {
_root.islandmain.islandbutton.onRollOver = function() {
left = true;
};
_root.islandmain.islandbutton.onRollOut = function() {
left = false;
};
};

Any help would be greatly appreciated. Many thanks,

James.

Functions
Hi,

I'm completely new to functions and am having some trouble with syntax. Could anyone check and see if anything appears wrong?

What I want to do here is have a function that changes the movieclip named after a variable called "root.section" to alpha = 20%

So basically I have a button, and once I click it it sets _root.section to "home", for example, and then calls this function so that the movie clip that has the name "home" changes to alpha= 20%.

hope this was clear enough... I also would be grateful if you could tell me how I should call this function; from the button or the movie clip?


Code:
function check() {
with ([_root.section]) {
_alpha = 20;
}
}
-S.

PS: any good tutorials on functions and function calling would be a lot of help too.

Thanks in advance.

Copyright © 2005-08 www.BigResource.com, All rights reserved