Adobe Dreamweaver Forums



Last 10 THreads :         CS4 No Quiz Templates (Last Post : jessediaz - Replies : 4 - Views : 5 )           »          Director Stage when Publishing (Last Post : openspark - Replies : 1 - Views : 2 )           »          Compatible issue with ie6 (Last Post : JoeyD1978 - Replies : 1 - Views : 2 )           »          captions for photos (Last Post : Walt F. Schaefer - Replies : 1 - Views : 2 )           »          Uncatchable Error 2101 (Last Post : M4G1C14N - Replies : 1 - Views : 2 )           »          File Transfer (Last Post : aruvasavi - Replies : 2 - Views : 3 )           »          Objects "Framed" when moving layer (Last Post : VegasMirage@adobeforums.com - Replies : 2 - Views : 3 )           »          Creating images to look like original oil paintings? (Last Post : Ian_Courtney@adobeforums.com - Replies : 0 - Views : 1 )           »          Opening a file in navpane from toolbar (Last Post : ChrisRousset - Replies : 0 - Views : 1 )           »          Help importing PNG sequence (Last Post : []MULISH - Replies : 0 - Views : 1 )           »         


User Info Statistics
Go Back   Adobe Dreamweaver Forums > Macromedia Software > Flex
 
Tags:



Reply
  #1 (permalink)  
Old 11-03-2008, 04:37 AM
Handycam
 
Posts: n/a
Diggs:
Default Adding a roll-over 'close' button on a component

I have a class that extends the image class. When the user clicks a button, a
handler creates an instance of this class. The class has methods to allow for
dragging, etc.

I would like to add a "close button" for the object, when the user rolls over
the object it appears, and clicking it removes the object. I'm not sure how to
integrate that into my AS class file. Or should I have made this an mxml
component?


package assets
{
import flash.events.MouseEvent;
import mx.controls.Image;
import mx.effects.SoundEffect;
import mx.events.MoveEvent;
import mx.core.Application;

public class ItemImage extends Image
{
public var filePath:String;
public var clickSound:SoundEffect = new SoundEffect(this);
public var createSound:SoundEffect = new SoundEffect(this);
public var deleteSound:SoundEffect = new SoundEffect(this);
private var sfxPath:String = '/assets/flash/sewing-room/';
private var deleted:Boolean = false;

public function ItemImage(fp:String)
{
super();
filePath = fp;
this.source = filePath;
this.addEventListener(MouseEvent.MOUSE_DOWN, dragMe);
this.addEventListener(MouseEvent.MOUSE_UP, dropMe);
this.addEventListener(MouseEvent.CLICK, clickedMe);
this.toolTip = "Drag to wherever you like. Click and release to bring to
front.";
clickSound.source = sfxPath+"assets/sfx/tink.mp3";
createSound.source = sfxPath+"assets/sfx/pop.mp3";
deleteSound.source = sfxPath+"assets/sfx/blow.mp3";
createSound.play();
}


private function dragMe(e:MouseEvent):void {
this.startDrag();
this.alpha = .5;
Application.application.trashCan.visible = true;
}

private function dropMe(e:MouseEvent):void {
this.stopDrag();
this.alpha = 1;
if (this.x > 486 && this.y > 256){
parent.removeChild(this);
deleted = true;
deleteSound.play();
}
Application.application.trashCan.visible = false;
}

private function clickedMe(e:MouseEvent):void {
if (!deleted){
parent.setChildIndex(this, parent.numChildren-1);
clickSound.play();
}
}

}
}



Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-03-2008, 04:38 AM
SujitG
 
Posts: n/a
Diggs:
Default Re: Adding a roll-over 'close' button on a component

Hi,

I modified your code a bit to add a button on mouse roll over. Please find the
code attached.

Hope this helps.

package assets
{
import flash.events.MouseEvent;

import mx.containers.Canvas;
import mx.controls.Button;
import mx.controls.Image;
import mx.core.Application;
import mx.effects.SoundEffect;

public class ItemImage extends Canvas
{
public var filePath:String;
public var clickSound:SoundEffect = new SoundEffect(this);
public var createSound:SoundEffect = new SoundEffect(this);
public var deleteSound:SoundEffect = new SoundEffect(this);
private var sfxPath:String = '/assets/flash/sewing-room/';
private var deleted:Boolean = false;

private var img:Image;
private var btn:Button;

public function ItemImage(fp:String)
{
super();
filePath = fp;

img = new Image();
img.source = filePath;
img.addEventListener(MouseEvent.MOUSE_DOWN, dragMe);
img.addEventListener(MouseEvent.MOUSE_UP, dropMe);
img.addEventListener(MouseEvent.CLICK, clickedMe);
img.addEventListener(MouseEvent.ROLL_OVER, showCloseButton);
img.addEventListener(MouseEvent.ROLL_OUT, hideCloseButton);
img.toolTip = "Drag to wherever you like. Click and release to bring to
front.";
addChild(img);

btn = new Button();
btn.label = "Close me";
btn.x = 0;
btn.y = 0;
btn.visible = false;
btn.includeInLayout = false;
addChild(btn);

clickSound.source = sfxPath+"assets/sfx/tink.mp3";
createSound.source = sfxPath+"assets/sfx/pop.mp3";
deleteSound.source = sfxPath+"assets/sfx/blow.mp3";
createSound.play();

}

private function showCloseButton(event:MouseEvent):void
{
btn.visible = true;
btn.includeInLayout = true;
}

private function hideCloseButton(event:MouseEvent):void
{
btn.visible = false;
btn.includeInLayout = false;
}

private function dragMe(e:MouseEvent):void {
img.startDrag();
img.alpha = .5;
Application.application.trashCan.visible = true;
}

private function dropMe(e:MouseEvent):void {
img.stopDrag();
img.alpha = 1;
if (img.x > 486 && img.y > 256){
parent.removeChild(img);
deleted = true;
deleteSound.play();
}
Application.application.trashCan.visible = false;
}

private function clickedMe(e:MouseEvent):void {
if (!deleted){
parent.setChildIndex(img, parent.numChildren-1);
clickSound.play();
}
}

}
}

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



© Camley Interactive (camley.info) 2008 - all logos and images are copywrite their respective owners.
Proud member of the Camley Interactive Network
All times are GMT. The time now is 04:44 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
Inactive Reminders By Mished.co.uk