Help with dynamic button click inside titleWindow
Hi Everyone, Your Help is much appreciated
I am building a flex application and I want the user to click on a button and
send them to another website. Basically I am creating a tileList that holds
thumbnails (created using item renederer) and on click a popup with the same
image and button will be created. I get errors when I click the link button.
This is what I have so far:
// This is my custom item renderer
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
horizontalAlign="center"
verticalAlign="middle">
<mx:Image source="{data.@thumbnailImage}" />
<mx:Label text="{data.@title}" />
</mx:VBox>
// My TileList
<mx:TileList id="tileList"
dataProvider="{xmlListCollection}"
itemRenderer="CustomItemRenderer"
maxColumns="4"
columnWidth="140"
rowCount="2"
rowHeight="140"
verticalScrollPolicy="off"
horizontalScrollPolicy="off"
itemClick="tileList_itemClick(event);" />
// This is my code
private function tileList_itemClick(evt:ListEvent):void {
// Set the TitleWindow
myTitleWindow = new TitleWindow();
myTitleWindow.title = evt.itemRenderer.data.@title;
myTitleWindow.width = 350;
myTitleWindow.height = 600;
myTitleWindow.showCloseButton = true;
// Set the Image
img = new Image();
img.maintainAspectRatio = true;
img.buttonMode = true;
img.useHandCursor = true;
img.source = evt.itemRenderer.data.@fullImage;
img.addEventListener(MouseEvent.CLICK , image_click);
//Set the Label
myLabel = new Label();
myLabel.text = evt.itemRenderer.data.@title;
myLabel.setStyle("fontWeight","bold");
// Here I set the Button but its not functioning
var btn:Button = new Button();
btn.label = evt.itemRenderer.data.@link;
btn.buttonMode = true;
btn.addEventListener(MouseEvent.CLICK,clickHandler );
myTitleWindow.addChild(img);
myTitleWindow.addChild(myLabel);
myTitleWindow.addChild(btn);
PopUpManager.addPopUp(myTitleWindow, this, true);
PopUpManager.centerPopUp(myTitleWindow);
}
// This is the Part I can't get it to work
private function clickHandler(e:MouseEvent):void{
var url:String = "http://" + data.@link;
var myRequest:URLRequest = new URLRequest(url);
navigateToURL(myRequest,'_blank');
}
My xml looks like this
<gallery>
<image title="Image One"
thumbnailImage="assets/big.jpg"
fullImage="assets/small.jpg"
link="www.google.com"
description = "Search Google"/>
</gallery>
|