While working on a project, I needed to highlight the selected thumbnail of an image, and this is how I added border dynamically to that MovieClip. Follow these steps before adding the AS3 code:
- Draw a rectangle on stage and convert it into a new MovieClip by selecting it and pressing F8.
- Name it a “Box” and check the box Export for Action Script
- Close the MovieClip now, we are done with the drawing here.
Add this AS3 code on the first frame in Actions Panel:
//let's create a function to add borders
function addBorder(myMC):void{
var mc:MovieClip = new MovieClip();
mc.graphics.lineStyle(2, 0x434B54);
mc.graphics.drawRect(0, 0, myMC.width/2+105, myMC.height/2+20);
mc.graphics.endFill();
myMC.addChild(mc);
}
//create Box movieClip to attach border
var myBox:Box = new Box();
myBox.width = 300;
myBox.height = 200;
myBox.x = 50;
myBox.y = 100;
//put it on stage
addChild(myBox);
//attach border
addBorder(myBox);
You can add borders to any other MovieClip using the same logic.
Hope that helps.
Cheers!




Thank you.