Hello. I have a problem with a school exercise in
ActionScript 3.0. Below you can read a description:
I need to show 6 pictures from a display list on stage. All pictures have a 5px white border (DRAWN IN CODE), and dropshadow filter applied on the entire picture (including border). The positions for the pictures are generated randomly, including their rotation. As soon as you click on a picture, it becomes the first item in the display list. Then you can start dragging the pictures around and drop them somewhere else.
Most parts of the exercise I have coded so far. If you run my code like you see it below, it will work perfectly like it should (except for the white border). Guess what.. my problem is the white border! I have added comments in my code because I think that's going to be a part of how it will be solved, but as soon as I remove the comments and actually compile it, I get some weird stuff. Pretty hard to explain though, so I have provided my code and .fla file for you to check it out if you feel like helping me with this.
04_photos.zip ( 782.81k )
Number of downloads: 33CODE
init();
function init():void {
createPhoto(new Photo1());
createPhoto(new Photo2());
createPhoto(new Photo3());
createPhoto(new Photo4());
createPhoto(new Photo5());
createPhoto(new Photo6());
}
function createPhoto(photo:Sprite):void {
photo.filters = new Array(new DropShadowFilter());
photo.x = Math.round(Math.random() * (stage.stageWidth - photo.width));
photo.y = Math.round(Math.random() * (stage.stageHeight - photo.height));
photo.rotation = Math.round(Math.random() * 30 - 15);
photo.addEventListener(MouseEvent.MOUSE_DOWN, startDragHandler);
/* ToDo: draw a 5px white border with dropshadow applied
*
* var border:Sprite = new Sprite();
* border.filters = new Array(new DropShadowFilter());
* border.graphics.beginFill(0xffffff);
* border.graphics.drawRect(photo.x - 5, photo.y - 5, photo.width + 10, photo.height + 10);
* border.graphics.endFill();
* border.rotation = photo.rotation;
* addChild(border);
*
*/
addChild(photo);
}
function startDragHandler(evt:MouseEvent):void {
evt.target.startDrag();
stage.addEventListener(MouseEvent.MOUSE_UP,stopDragHandler);
addChildAt(DisplayObject(evt.target), 6);
}
function stopDragHandler(evt:MouseEvent):void {
evt.target.stopDrag();
stage.removeEventListener(MouseEvent.MOUSE_UP,stopDragHandler);
}
This post has been edited by skater_00: 15 Oct, 2008 - 05:39 PM