October 29th, 2008 by Kyle
Tags: Flex, itemrenderer, popup
Posted in: Flex
I wrote a demo a while back for a customer to demonstrate the following scenario:
Here is the app:
Download a zipfile containing the source to this sample.
Browse the source of this example.
Or continue into the blog entry to see the source:
Here is the app code:
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" viewSourceURL="srcview/index.html">
<mx:Script>
<![CDATA[
import mx.managers.PopUpManager;
import mx.managers.PopUpManagerChildList;
import mx.events.ListEvent;
import mx.collections.ArrayCollection;
[Bindable]
private var catalog:ArrayCollection;
private var assets:Array = ["assets/putty.jpg", "assets/cantena.jpg", "assets/orb.jpg", "assets/globe.jpg", "assets/usbfan.jpg", "assets/hotsauce.jpg"];
private function initCatalog():void
{
catalog = new ArrayCollection();
for (var i:int=0;i<assets.length;i++){
var vo:MyVO=new MyVO(assets[i],assets[i]);
catalog.addItem(vo);
}
}
public function createPopup(event:ListEvent):void
{
var foo:String="bar";
var renderer:MyRenderer = event.itemRenderer as MyRenderer;
var pop:MyPopup = MyPopup(PopUpManager.createPopUp(this,MyPopup,false,PopUpManagerChildList.POPUP));
pop.vo=(event.target as TileList).selectedItem as MyVO;
pop.myparentDP=(event.target as TileList).dataProvider as ArrayCollection;
tilePopUps();
}
private function tilePopUps():void{
for (var i:int=0;i<systemManager.popUpChildren.numChildren;i++){
var o:* = systemManager.popUpChildren.getChildAt(i);
PopUpManager.centerPopUp(o)
if(i!=0){
o.x+=10*i;
o.y+=10*i;
}
}
}
]]>
</mx:Script>
<mx:TileList id="tileList"
dataProvider="{catalog}"
itemRenderer="MyRenderer"
columnCount="3"
columnWidth="140"
rowCount="1"
rowHeight="140"
themeColor="haloSilver"
verticalScrollPolicy="on"
itemClick="createPopup(event);"
creationComplete="initCatalog();"/>
</mx:Application>
Here is the itemRenderer:
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
horizontalAlign="center"
verticalAlign="middle">
<mx:Image source="{data.asset}" scaleX=".25" scaleY=".25"/>
<mx:Label text="{data.title}" />
</mx:VBox>
Here is the simple popup:
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml"
horizontalAlign="center"
verticalAlign="middle">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.managers.PopUpManager;
public var myparentDP:ArrayCollection;
[Bindable]
public var vo:MyVO;
private function removeItem():void{
var i:int = myparentDP.getItemIndex(vo);
if (i!=-1){
myparentDP.removeItemAt(i);
}
PopUpManager.removePopUp(this);
}
]]>
</mx:Script>
<mx:Image source="{vo.asset}" />
<mx:Label text="{vo.title}" />
<mx:HBox>
<mx:Button label="close" click="PopUpManager.removePopUp(this)"/>
<mx:Button label="remove item" click="removeItem()"/>
</mx:HBox>
</mx:TitleWindow>
Here is the type value object that populates the ArrayCollection:
{
[Bindable]
public class MyVO
{
private var _asset:String;
private var _title:String;
public function MyVO(title:String, asset:String)
{
this.title=title;
this.asset=asset;
}
public function set title(title:String):void{
_title=title;
}
public function get title():String{
return _title;
}
public function set asset(asset:String):void{
_asset=asset;
}
public function get asset():String{
return _asset;
}
}
}
3 Comments »











November 26th, 2008 at 4:05 pm
really nice example!
but is it possible to add a function to navigate to the prev/next image of the TileList?
January 20th, 2009 at 3:46 pm
[...] TileList with popup that deletes from dataProvider [...]
March 11th, 2009 at 7:19 pm
THANKS!