# Layers and Actionscript problem

i’m new to flash, so if you kindly respond, i wish to thank you ahead of time.

here’s what i have…
layer 1: a rectangle which i have drawn with the rectangle option from ‘tools’
layer 2: actionscript which draws a circle
layer 3: actionscript which uses startdrag to attach the rectangle to my
mouse cursor

when i test the movie, the rectangle appears to pass behind the actionscript generated circle…

i would like the reverse to happen, the rectangle seeming to pass infront of or above the actionscript generated circle.

can this be done?

here’s the code of my layers…

layer 1: (no code) drawn rectangle movieclip named ‘rect’

layer 2: actionscripted circle

MovieClip.prototype.drawCircle = function(r, x, y) {
this.moveTo(x+r, y);
a = Math.tan(22.5 * Math.PI/180);
for (var angle = 45; angle<=360; angle += 45) {
// endpoint:
var endx = rMath.cos(angleMath.PI/180);
var endy = rMath.sin(angleMath.PI/180);
// control:
// (angle-90 is used to give the correct sign)
var cx =endx + raMath.cos((angle-90)Math.PI/180);
var cy =endy + r
a*Math.sin((angle-90)*Math.PI/180);
this.curveTo(cx+x, cy+y, endx+x, endy+y);
}
}
xPos = 30;
yPos = 28;

_root.createEmptyMovieClip(“circle_mc”, 1);
circle_mc.lineStyle(1, 0x000000, 100);
circle_mc.beginFill(0x0000ff, 100);
circle_mc.drawCircle(37, xPos, yPos);
circle_mc.endFill();
circle_mc.onPress = function() {
trace(“pressed”);
};

layer 3: startDrag(_root.rect, true);

thanks in advance…
j.

Hi Buddy,

Here is attching the solution (.fla) file with your code and littile change done.

If you wont get attchment…then also no worry…

The solution to your problem is attachmovie. Wait I will tell you,

1. Delete rectangle from the stage,
2. Open Library Window, you can see you rectangle just right click on it and goto Linkage and at Identifier type: rectangle
3. Check yest to 1st and 3rd checkboxes down their (if they are not) in the Linkage window.
4. Come back to the stage.
5. And at the second layer paste this code:(look at the extreme bottom of code) you will find i have attched the same MC (rectangle) and set its index value to (2) which is greater than circles index value (1).

cheers
Ashish

MovieClip.prototype.drawCircle = function(r, x, y) {
this.moveTo(x+r, y);
a = Math.tan(22.5 * Math.PI/180);
for (var angle = 45; angle<=360; angle += 45) {
// endpoint:
var endx = rMath.cos(angleMath.PI/180);
var endy = rMath.sin(angleMath.PI/180);
// control:
// (angle-90 is used to give the correct sign)
var cx =endx + raMath.cos((angle-90)Math.PI/180);
var cy =endy + r
a*Math.sin((angle-90)*Math.PI/180);
this.curveTo(cx+x, cy+y, endx+x, endy+y);
}
}
xPos = 30;
yPos = 28;
_root.createEmptyMovieClip(“circle_mc”, 1);
circle_mc.lineStyle(1, 0x000000, 100);
circle_mc.beginFill(0x0000ff, 100);
circle_mc.drawCircle(37, xPos, yPos);
circle_mc.endFill();
circle_mc.onPress = function() {
trace(“pressed”);
};

_root.attachMovie(“rectangle”,“rect”, 2);
startDrag(rect, true);

thanks for the help! i’m going to give that a try. really appreciate it!