Groups | Blog | Home
all groups > flash actionscript > april 2004 >

flash actionscript : How do I trigger a function


Oggie
4/28/2004 7:32:30 PM
How do I get this script attached to a button component


on(click){
_parent.calculate();
}


To run this script attatched to a key frame in the time line

function calculate() {
totalX = 0;
totalY = 0;
averageX = 0;
averageY = 0;
totalZ = 0;
averageZ = 0;
for (i=0; i<_level0.XYArray["X"].length; i++) {

totalZ = totalZ + _level0.XYArray["X"][i] + _level0.XYArray["Y"][i];
}

averageZ = totalZ/_level0.XYArray["X"].length;

_parent.amountZ.text = averageZ;
}
_level0.XYArray = new Array();
_level0.XYArray["X"] = new Array();
_level0.XYArray["Y"] = new Array();
_level0.XYArray["Z"] = new Array();
_level0.counter = 0;


In a Flash form Application.


Note: This works in a reg flash doccument.
mandingo
4/28/2004 11:40:13 PM
Hi,

don't use ' i ' as the variable when posting to the web forums... the browser
interprets the bracketed 'i' as the italics tag and then the rest of the script
doesn't make sense.

use k or something else... oh don't use b either :)

By the way... what is this doing?

_level0.XYArray = new Array();
_level0.XYArray["X"] = new Array();
_level0.XYArray["Y"] = new Array();
_level0.XYArray["Z"] = new Array();

are you trying to create 4 new arrays? are you trying to set values to the
arrays? Is the first one supposed to be a holder for the other 3? Where are
you putting values into the arrays?

some more info would assist... because what you are after is simple... if the
button exists on the main timeline, then a simple:

on(release){
calculate();
}
should work...

cheers
AddThis Social Bookmark Button