Welcome to Dream.In.Code
Getting Help is Easy!

Join 136,408 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,461 people online right now. Registration is fast and FREE... Join Now!




Drag & Drop, depth management

 
Reply to this topicStart new topic

Drag & Drop, depth management, Display 6 pictures on stage. Pictures can be moved.

skater_00
15 Oct, 2008 - 08:40 AM
Post #1

D.I.C Head
Group Icon

Joined: 30 Apr, 2008
Posts: 173



Thanked: 4 times
Dream Kudos: 50
My Contributions
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.

Attached File  04_photos.zip ( 782.81k ) Number of downloads: 33


CODE
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
User is offlineProfile CardPM
+Quote Post

skater_00
RE: Drag & Drop, Depth Management
19 Oct, 2008 - 07:08 AM
Post #2

D.I.C Head
Group Icon

Joined: 30 Apr, 2008
Posts: 173



Thanked: 4 times
Dream Kudos: 50
My Contributions
*bump*

Anyone?
User is offlineProfile CardPM
+Quote Post

CyanBlue
RE: Drag & Drop, Depth Management
19 Oct, 2008 - 12:11 PM
Post #3

D.I.C Head
Group Icon

Joined: 1 Sep, 2006
Posts: 83



Thanked: 1 times
My Contributions
How about this???
as
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());
var photoWidth:Number = photo.width;
var photoHeight:Number = photo.height;

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);

addChild(photo);

var border:Sprite = new Sprite();
border.mouseEnabled = false;
photo.addChildAt(border, 0);

border.graphics.beginFill(0xffffff);
border.graphics.drawRect(-5, -5, photoWidth + 10, photoHeight + 10);
border.graphics.endFill();
border.filters = new Array(new DropShadowFilter());
}

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);
}

User is online!Profile CardPM
+Quote Post

skater_00
RE: Drag & Drop, Depth Management
19 Oct, 2008 - 11:11 PM
Post #4

D.I.C Head
Group Icon

Joined: 30 Apr, 2008
Posts: 173



Thanked: 4 times
Dream Kudos: 50
My Contributions
Thanks, CyanBlue! The border is fine now. Really helped me a lot!
User is offlineProfile CardPM
+Quote Post

CyanBlue
RE: Drag & Drop, Depth Management
20 Oct, 2008 - 02:35 AM
Post #5

D.I.C Head
Group Icon

Joined: 1 Sep, 2006
Posts: 83



Thanked: 1 times
My Contributions
Glad to help... wink2.gif
User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 12:09PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month