Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 04-02-2010, 11:42 AM   #1
Leyon
Registered User
 
Join Date: Mar 2010
Posts: 25
Default Glow on selected object

I'm trying to make my objects selectable in the way that only one can be selected at a time. The object selected is shown with a simple glow tween. Right now I can get every item on the stage to glow as the glow doesn't dissappear when I click a new object. How do I make the glow only show up on the object that was just clicked?
Thanks!

ActionScript Code:
init();//places the cubes on the stage // place Items on stage function init():void {     for (var i:uint = 0; i < numOfItems; i++) {         var item:cube = new cube();         // public var angl:Number; is in Item class.         item.angl = i * ((Math.PI * 2) / numOfItems);         itemArray.push(item);         addChild(item);         item.addEventListener(Event.ENTER_FRAME, enterFrameHandler);         // listen for MouseEvents only on "icon"         // "icon" is an instance name for an mc inside the main mc "cube"         item.icon.addEventListener(MouseEvent.CLICK, select);         item.buttonMode=true;     } } // Positioning items in a circle function enterFrameHandler(event:Event):void {     event.target.x=Math.cos(event.target.angl)*radiusX+centerX;// x position of Item     event.target.y=Math.sin(event.target.angl)*radiusY+centerY;// y postion of Item     event.target.angl+=speed;// speed is updated by the speed variable which is set in the onMove function } function select(event:MouseEvent):void {     TweenMax.to(event.currentTarget, 0, {glowFilter:{color:0x0000ff, alpha:1, blurX:12, blurY:12,strength:1}});     var snd:cubeclick = new cubeclick();     snd.play(); }
Leyon is offline   Reply With Quote
Old 04-02-2010, 12:43 PM   #2
sparX
!Senior Member
 
Join Date: Jan 2010
Posts: 1,675
Default

There might be a better way,but one way off top of my head could be,

ActionScript Code:
var ect:DisplayObject; function select(event:MouseEvent):void {     if (ect) ect.filters = [];     ect = DisplayObject(event.currentTarget);     TweenMax.to(event.currentTarget, 0, {glowFilter:{color:0x0000ff, alpha:1, blurX:12, blurY:12,strength:1}});     var snd:cubeclick = new cubeclick();     snd.play(); }
sparX is offline   Reply With Quote
Old 04-02-2010, 01:08 PM   #3
henke37
Senior Member
 
henke37's Avatar
 
Join Date: Mar 2009
Location: Sweden
Posts: 10,684
Send a message via Skype™ to henke37
Default

How? You keep track of the stuff that should be cleared and then when it should be cleared, you do that.
__________________
Signature: I wrote a pair of articles about the timeline.
henke37 is offline   Reply With Quote
Old 04-02-2010, 01:12 PM   #4
Leyon
Registered User
 
Join Date: Mar 2010
Posts: 25
Default

You're awesome works perfectly
One more thing is that I would like the glow to disappear if I click a selected icon again. I'm guessing I should somehow write an if statement inside the select function that would remove the glow if the clicked object is the same that was just clicked...?
Leyon is offline   Reply With Quote
Old 04-02-2010, 02:02 PM   #5
sparX
!Senior Member
 
Join Date: Jan 2010
Posts: 1,675
Default

Im just pulling stuff out my behind here & making a terrible mess lol,but try this,or think of something cleaner..

ActionScript Code:
var ect:DisplayObject; var boo:Boolean; function select(event:MouseEvent):void {     if (ect) ect.filters = [];     if (ect == event.currentTarget && !boo) {          boo = true;          return;     }     else boo = false;     ect = DisplayObject(event.currentTarget);     TweenMax.to(event.currentTarget, 0, {glowFilter:{color:0x0000ff, alpha:1, blurX:12, blurY:12,strength:1}});     var snd:cubeclick = new cubeclick();     snd.play(); }

Have u looked thru the greensock docs?

they probably have a simple method for this type of thing to hang off the tween itself,u could probably get the object to go wash your car & take out the trash as well while its tweening from what ive seen of the greensock stuff

i just dont use tweens that much so dont know...

Last edited by sparX; 04-02-2010 at 02:09 PM. Reason: sorry wrote something twice....duh 'e' as well...
sparX is offline   Reply With Quote
Old 04-02-2010, 03:03 PM   #6
sparX
!Senior Member
 
Join Date: Jan 2010
Posts: 1,675
Default

Heres a cleaner version without the silly boolean stuff...

ActionScript Code:
var ect:DisplayObject; function select(event:MouseEvent):void {     if (ect) ect.filters = [];     if (ect != event.currentTarget) {         TweenMax.to(event.currentTarget, 0, {glowFilter:{color:0x0000ff, alpha:1, blurX:12, blurY:12,strength:1}});         ect = DisplayObject(event.currentTarget);     }     else ect = null;     var snd:cubeclick = new cubeclick();     snd.play(); }
sparX is offline   Reply With Quote
Old 04-03-2010, 11:42 AM   #7
Leyon
Registered User
 
Join Date: Mar 2010
Posts: 25
Default

again, awesome
Just wondering if I got this right, since I really want to understand the code as well.

This apparently controls the fact that only one item can be selected at a time but what does filters actually do?
ActionScript Code:
if (ect) ect.filters = [];

so basically we're telling it to check if what is clicked is the event.currentTarget and if it isn't then turn on the glow. The event.currentTarget is whatever object that calls this function and this is stored until the function is called again?
ActionScript Code:
if (ect != event.currentTarget) { TweenMax.to(event.currentTarget, 0, {glowFilter:{color:0x0000ff, alpha:1, blurX:12, blurY:12,strength:1}}); ect = DisplayObject(event.currentTarget);      }

and if it is the curentTarget then we clear everything, so that we can select/deselect the same object over and over?
ActionScript Code:
else ect = null;
Leyon is offline   Reply With Quote
Old 04-03-2010, 12:30 PM   #8
sparX
!Senior Member
 
Join Date: Jan 2010
Posts: 1,675
Default

ActionScript Code:
if (ect) ect.filters = [];

this just says,'if' the value of ect is 'true'(ie not 'null'), then clear the filters property of the DisplayObject referenced by 'ect'.

The glowFilter u are applying becomes one of the objects that is part of the array that is passed to set the filters property of the DisplayObject.In this case the array consists of just one element & that element is simply the glowFilter object.

To clear the filters applied u just clear the filters property of the DisplayObject in question,ie pass an empty array([]) to set the filters to no filters or u could simply say ect.filters = null; .
I dont know if one way is more correct than the other,but both work in my experience.Perhaps setting to null would be more correct.


ActionScript Code:
if (ect != event.currentTarget) {      TweenMax.to(event.currentTarget, 0, {glowFilter:{color:0x0000ff, alpha:1, blurX:12, blurY:12,strength:1}});      ect = DisplayObject(event.currentTarget);      }

This just says,'if' the reference to the Displayobject we stored at 'ect' is NOT the same as the 'currentTarget' property of the event object,then apply the glowFilter via TweenMax, & then, store a reference to this object we applied the filter to at 'ect',so we can remember who got the glowFilter.

U could simply set a glowFilter in this case,because your not necessarily 'tweening' the process(ie your duration is set to 0),like,

ActionScript Code:
var gf:GlowFilter = new GlowFilter(0xFF,1,12,12,1); event.currentTarget.filters = [gf];//put this in place of tween

ActionScript Code:
else ect = null;

Yes,on this bit,just remove the reference(ect = null) to last object 'filtered' so it can be 'refiltered' if selected again.Obviously because it is determined by 'else',then if the last object selected was indeed NOT the same as 'currentTarget' in the 'if' check,then this statement will be bypassed & a reference to the filtered object can be retained at 'ect'.

Last edited by sparX; 04-03-2010 at 12:39 PM.
sparX is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:39 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.