利用Flex的TileList控件创建一个简单的图片展示(相册)的例子

和前面的 利用Flex的HorizontalList控件创建一个简单的图片展示(相册)很相似,这个例子展示了如何利用Flex的TileList控件,Image控件和PopUpManager类来创建一个简单的图片展示(相册)。
下面是具体的例子以及源代码:
Download: main.mxml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!-- http://blog.flexexamples.com/2008/03/08/creating-a-simple-image-gallery-with-the-flex-tilelist-control/ -->
  3. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
  4.         layout="vertical"
  5.         verticalAlign="middle"
  6.         backgroundColor="white">
  7.     <mx:Style>
  8.         global {
  9.             modal-transparency: 0.9;
  10.             modal-transparency-color: white;
  11.             modal-transparency-blur: 9;
  12.         }
  13.     </mx:Style>
  14.     <mx:Script>
  15.         <![CDATA[
  16.             import mx.effects.Resize;
  17.             import mx.events.ResizeEvent;
  18.             import mx.events.ListEvent;
  19.             import mx.controls.Image;
  20.             import mx.events.ItemClickEvent;
  21.             import mx.managers.PopUpManager;
  22.             private var img:Image;
  23.             private function tileList_itemClick(evt:ListEvent):void {
  24.                 img = new Image();
  25.                 // img.width = 300;
  26.                 // img.height = 300;
  27.                 img.maintainAspectRatio = true;
  28.                 img.addEventListener(Event.COMPLETE, image_complete);
  29.                 img.addEventListener(ResizeEvent.RESIZE, image_resize);
  30.                 img.addEventListener(MouseEvent.CLICK, image_click);
  31.                 img.source = evt.itemRenderer.data.@fullImage;
  32.                 img.setStyle("addedEffect", image_addedEffect);
  33.                 img.setStyle("removedEffect", image_removedEffect);
  34.                 PopUpManager.addPopUp(img, this, true);
  35.             }
  36.             private function image_click(evt:MouseEvent):void {
  37.                 PopUpManager.removePopUp(evt.currentTarget as Image);
  38.             }
  39.             private function image_resize(evt:ResizeEvent):void {
  40.                 PopUpManager.centerPopUp(evt.currentTarget as Image);
  41.             }
  42.             private function image_complete(evt:Event):void {
  43.                 PopUpManager.centerPopUp(evt.currentTarget as Image);
  44.             }
  45.         ]]>
  46.     </mx:Script>
  47.     <mx:WipeDown id="image_addedEffect" startDelay="100" />
  48.     <mx:Parallel id="image_removedEffect">
  49.         <mx:Zoom />
  50.         <mx:Fade />
  51.     </mx:Parallel>
  52.     <mx:XML id="xml" source="gallery.xml" />
  53.     <mx:XMLListCollection id="xmlListColl" source="{xml.image}" />
  54.     <mx:TileList id="tileList"
  55.             dataProvider="{xmlListColl}"
  56.             itemRenderer="CustomItemRenderer"
  57.             columnCount="4"
  58.             columnWidth="125"
  59.             rowCount="2"
  60.             rowHeight="100"
  61.             themeColor="haloSilver"
  62.             verticalScrollPolicy="on"
  63.             itemClick="tileList_itemClick(event);" />
  64. </mx:Application>
下面是自定义的ItemRenderer设置文件:
Download: CustomItemRenderer.mxml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!-- http://blog.flexexamples.com/2008/03/08/creating-a-simple-image-gallery-with-the-flex-tilelist-control/ -->
  3. <mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
  4.         horizontalAlign="center"
  5.         verticalAlign="middle">
  6.     <mx:Image source="{data.@thumbnailImage}" />
  7.     <mx:Label text="{data.@title}" />
  8. </mx:VBox>
接下来是图片定义的XML文件:
Download: gallery.xml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!-- http://blog.flexexamples.com/2008/03/08/creating-a-simple-image-gallery-with-the-flex-tilelist-control/ -->
  3. <gallery>
  4.     <image title="Flex"
  5.         thumbnailImage="assets/fx_appicon-tn.gif"
  6.         fullImage="assets/fx_appicon.jpg" />
  7.     <image title="Flash"
  8.             thumbnailImage="assets/fl_appicon-tn.gif"
  9.             fullImage="assets/fl_appicon.jpg" />
  10.     <image title="Illustrator"
  11.             thumbnailImage="assets/ai_appicon-tn.gif"
  12.             fullImage="assets/ai_appicon.jpg" />
  13.     <image title="Dreamweaver"
  14.             thumbnailImage="assets/dw_appicon-tn.gif"
  15.             fullImage="assets/dw_appicon.jpg" />
  16.     <image title="ColdFusion"
  17.             thumbnailImage="assets/cf_appicon-tn.gif"
  18.             fullImage="assets/cf_appicon.jpg" />
  19.     <image title="Flash Player"
  20.             thumbnailImage="assets/fl_player_appicon-tn.gif"
  21.             fullImage="assets/fl_player_appicon.jpg" />
  22.     <image title="Fireworks"
  23.             thumbnailImage="assets/fw_appicon-tn.gif"
  24.             fullImage="assets/fw_appicon.jpg" />
  25.     <image title="Lightroom"
  26.             thumbnailImage="assets/lr_appicon-tn.gif"
  27.             fullImage="assets/lr_appicon.jpg" />
  28.     <image title="Photoshop"
  29.             thumbnailImage="assets/ps_appicon-tn.gif"
  30.             fullImage="assets/ps_appicon.jpg" />
  31. </gallery>
下面是执行实例(可以右键察看源代码):

你可能感兴趣的:(职场,休闲)