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

flash actionscript : Using x and y of an area


Oggie
3/8/2004 7:46:31 PM
Ok I am new to this..... and here is my problem I need to set the x and y of
an area, lets say an image of a map, so each time this map is clicked on the
x y coordianace will define and record a value.....Example: (x=122 y=44)=
value.

Each vaule will be held until a calculate button is clicked and the sum of
all values is dived by the number of clicks to get an average.

Can this be done? and where do I start?
jeffczyz
3/8/2004 8:04:14 PM
On a click event you could add the x,y coordincates to an array. ON the
calculate button you can get the length of the array and then sum all of the
X's and Y's by looping through each item in the array.

Make sense?
Oggie
3/8/2004 8:20:26 PM
jeffczyz
3/8/2004 11:22:26 PM
Oggie,

I threw this together real quick in 2004. It assumes a couple things: Your map
that you are clicking on is a movie clip and the button you are click is a
movie clip.

I created 2 Arrays, 1 for X and 1 For Y. Each time the main movieclip map
Map_mc is clicked, it adds the x and y coordinates to the array.

Hope that helps.

Jeff

Place all of this code in Frame1 of the timeline:

var myAryX:Array = new Array();
var myAryY:Array = new Array();
var sumX:Number=0;
var sumY:Number=0;

Map_mc.onPress = function(){
myAryX.push(_root._xmouse);
myAryY.push(_root._ymouse);
}

calcButton_btn.onPress = function() {
for (i=0; i<myAryX.length;i++) {
sumX= sumX + Number(myAryX[i]);
sumY= sumY + Number(myAryY[i]);
}
trace("SumX:" + sumX + " SumY:" + sumY);
}
AddThis Social Bookmark Button