# Layers and Actionscript problem

**URL:** <https://forum.kirupa.com/t/layers-and-actionscript-problem/56969>\
**Category:** flash\
**Created:** [July 9, 2004, 7:06am UTC](https://forum.kirupa.com/t/layers-and-actionscript-problem/56969 "2004-07-09T07:06:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![frippdullah](https://avatars.discourse-cdn.com/v4/letter/f/94ad74/32.png) [@frippdullah](https://forum.kirupa.com/u/frippdullah)\
**Post date:** [July 9, 2004, 7:06am UTC](https://forum.kirupa.com/t/layers-and-actionscript-problem/56969/1 "2004-07-09T07:06:58Z")

</div>

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 = r_Math.cos(angle_Math.PI/180);  
var endy = r_Math.sin(angle_Math.PI/180);  
// control:  
// (angle-90 is used to give the correct sign)  
var cx =endx + r_a_Math.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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 9, 2004, 7:25am UTC](https://forum.kirupa.com/t/layers-and-actionscript-problem/56969/2 "2004-07-09T07:25:56Z")

</div>

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 = r_Math.cos(angle_Math.PI/180);  
var endy = r_Math.sin(angle_Math.PI/180);  
// control:  
// (angle-90 is used to give the correct sign)  
var cx =endx + r_a_Math.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);

> [@frippdullah](#):
>
> 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 = r_Math.cos(angle_Math.PI/180);  
> var endy = r_Math.sin(angle_Math.PI/180);  
> // control:  
> // (angle-90 is used to give the correct sign)  
> var cx =endx + r_a_Math.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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 9, 2004, 3:19pm UTC](https://forum.kirupa.com/t/layers-and-actionscript-problem/56969/3 "2004-07-09T15:19:39Z")

</div>

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