Hi there,
I know this is a real newbie question, but I’ve been going over it for days, so before I tear all my hair out, I thought I’d see if anyone could give me some advice.
So I have an object, generated on each click of the mouse. It’s set up as a series of points with properties, with values for position randomly calculated, and set around where the user clicks the mouse. Lines are drawn from where the mouse is clicked out to each of these points, so it kind of looks like a star, but only lines, rather than a solid shape (like those old 50’s atom clocks?). So once clicked there’s an enter frame event listener on the object so that each of the points ‘wobble’ (using a randomly generated number) up and down around the original point.
For some reason, I can either set it so that on each new click of the mouse and newly generated object, the last one stops “wobbling” and only the new one does, or each new object moves to where the new object is, and maybe is still wobbling(?), but is underneath the new object. This way has the event.target as a new object in the wobble function, so I think it may be just a case of where the centre point is - i.e. saving the mouse x and y for each object individually, or perhaps I have too much of the setup function code repeated in my "wobble"function?
I think my brain has switched off for overthinking, and no amount of reading tutorials, or doing something completely different seems to help?
If this helps describe it at all… :
import flash.display.*;
import flash.events.*;
import flash.filters.*;
var numLines:int = 50;
var oneSlice:Number = Math.PI*2/numLines;
var radius:int = 100;
var shapeCount:int = 0;
var container:Sprite = new Sprite();;
this.addChild(container);
var originalXmouse:Number;
var originalYmouse:Number;
var wobble:Number = 10;
var points:Array = new Array();
for (var i:int=0; i<numLines; i++) {
points* = {x:stage.stageWidth/2, y:stage.stageHeight/2};
}
stage.addEventListener(MouseEvent.MOUSE_DOWN, drawShape);
function drawShape(evt:MouseEvent):void{
var shape:MovieClip = new MovieClip();;
var gr:Graphics = shape.graphics;;
shape.name = "shape"+shapeCount;
shape.Xmouse = stage.mouseX;
shape.Ymouse = stage.mouseY;
originalXmouse = shape.Xmouse;
originalYmouse = shape.Ymouse;
for (var i:int=0; i<numLines; i++) {
var angle:Number = oneSlice*i;
var point:Object = new Object();
point = points*;
point.spring = Math.random()*.5+.5;
point.xStart = Math.cos(angle)* radius * point.spring + shape.Xmouse;
point.yStart = Math.sin(angle)* radius * point.spring + shape.Ymouse;
}
//line shapes
gr.lineStyle(1, 1);
for (var k:int=0; k<numLines; k++) {
gr.moveTo(shape.Xmouse, shape.Ymouse);
gr.lineTo(points[k].xStart, points[k].yStart);
}
//blur
var blur:BlurFilter = new BlurFilter(4,4,1);
var filterArray:Array = new Array(blur);
shape.filters = filterArray;
container.addChild(shape);
trace(shape.name);
shape.addEventListener(Event.ENTER_FRAME, wobbleShape);
shapeCount++;
}
function wobbleShape(evt:Event):void{
var shapeMC:MovieClip = MovieClip(evt.target);
var shapeMCGr:Graphics = shapeMC.graphics;
for (var i:int=0; i<numLines; i++) {
var angle:Number = oneSlice*i;
var point:Object = new Object();
point = points*;
var randomNumber:Number = Math.random() *wobble;
point.xTarget = Math.cos(angle)* (radius + randomNumber)*point.spring + originalXmouse;
point.yTarget = Math.sin(angle)* (radius + randomNumber)*point.spring + originalYmouse;
}
shapeMCGr.clear();
shapeMCGr.lineStyle(1, 1);
for (var k:int=0; k<numLines; k++) {
shapeMCGr.moveTo(originalXmouse, originalYmouse);
shapeMCGr.lineTo(points[k].xTarget, points[k].yTarget);
}
}
I’d be really grateful to anyone who has any suggestions as to how to get it to work, how to put the code in an orderly fashion, and also an extra of getting each shape to float around the stage once clicked and created.
Thanks!
Emma