flex-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From phil gottfried <p...@rwcdigitalgraphics.com>
Subject Re: Clickable images
Date Tue, 30 Sep 2014 19:43:53 GMT
		
how about a helper function to make it easy to add icon image buttons.
the example shows all icons with the same click handler.
the currentTarget is used to get the clicked icon's id.




		/**
		 * create a clickable icon with listener  - example use<br><br>
		 * 
		 * niA:Image=makeAnIconButton("niA",'icons/redDot.png',24,24,0,0,"niA",buttonClick);<br>
		 * niB:Image=makeAnIconButton("niB",'icons/blueDot.png',24,24,25,0,"niB",buttonClick);<br>
		 * <br>
		 * parentContainer.addElements(niA);<br>
		 * parentContainer.addElements(niB);<br>
		 * 
		 * //the currentTarget will be a spark image and its id will indicate which icon was clicked<br>
		 * //the target will be the spark image skin<br>
		 * function buttonClick(event:MouseEvent):void {<br>
		 * 		icon:Image=Image(currentTarget);//<br>
		 * 		switch(icon.id) {		<br>
		 * 			case "niA":			<br>
		 * 			break;				<br>
		 * 			case "niB":			<br>
		 * 			break;				<br>
		 * 		}	//					<br>
		 * }		//					<br>
		 * 
		 * <br><br>
		 * 
		 * @param id the id of the new image component
		 * @param icon a string with the icon asset locations.  ie a folder in the flex project
with a valid image source file
		 * @param iconWidth the icon width - the icon will be scaled if not this size
		 * @param iconHeight the icon height - the icon will be scaled if not this size
		 * @param iconX the x position within the parent container, if it is in absolute position
mode
		 * @param iconY the y position within the parent container, if it is in absolute position
mode
		 * @param tip text displayed on hover
		 * <br>
		 * note: the x,y are the top/left of the icon and the container must be in absolute position
mode<br>
		 * <br><br>
		 * @return x the image create. ie a spark image
		 */
		public function makeAnIconButton(id:String,icon:String,iconWidth:Number,iconHeight:Number,iconX:Number=0,iconY:Number=0,tip:String=null,click:Function=null):Image
{
			var x:Image=new Image();
			if(id!="") {//use this in an event handler to see which one was clicked
				x.id=id;
			}
			x.source=icon;
			if(tip!=null) x.toolTip=tip;
			x.x=iconX;
			x.y=iconY;
			if(click!=null) x.addEventListener(MouseEvent.CLICK,click);
			return x;
		}



Phil Gottfried
Art Director
RWC Digital Graphics
2920 Edith Lane
Haltom City, Texas 76117
Ph: 817 831 2300
Fx: 817 831 2302
phil@rwcdigitalgraphics.com

Upload your files here!  http://www.rwcdigitalgraphics.com/rwc_10.html

http://upload.youload.com/hJw7d0w691TNQ1UrZ9j5gw==/







Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message