Link to home
Start Free TrialLog in
Avatar of akulavi
akulavi

asked on

TileList Dynamic DataProvider Problem

I am using Flex 3.0, ASP.NET and SQL-SERVER 2005. I am generating XML from ASP.NET. When I am viewing the xml through aspx it is working fine.In my flex application i want to make an image gallery with tilelist and image control. When I am setting the httpservice 's url  as xml file then images are coming. But when i am trying to set the httpservice 's url as .aspx file which will return xml dynamically then images are not coming. I am giving you the .mxml file. Pls. tell me where is the problem. Its urgent.
<?xml version="1.0"?>
<!-- Simple example to demonstrate the MenuBar control. -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="initCollections();"  width="870">
<mx:HTTPService id="result_create" url="http://localhost:2166/huntbags/cataloguegenerate.aspx" useProxy="false" method="GET" showBusyCursor="true" resultFormat="e4x" result="httpService_result(event)" fault="httpService_fault(event);" >
	<mx:request xmlns="">
		<productrange>{producthid.text}</productrange>
	</mx:request>
</mx:HTTPService>
	<mx:Script>
        <![CDATA[
 
            import mx.events.MenuEvent;
            import mx.controls.Alert;
            import mx.collections.*;
            import mx.controls.Image;
            import mx.events.ListEvent;
            import mx.events.ResizeEvent;
            import mx.managers.PopUpManager;
            import mx.rpc.events.ResultEvent;
            import mx.rpc.events.FaultEvent;
 
 
 
            [Bindable]
            public var menuBarCollection:XMLListCollection;
    		private function httpService_result(evt:ResultEvent):void {
    			Alert("HAY...");
                var xmlList:XMLList = XML(evt.result).gallery.image;
                xmlListColl = new XMLListCollection(xmlList);
            }
            private function httpService_fault(evt:FaultEvent):void {
            	var title:String = evt.type + " (" + evt.fault.faultCode + ")";
                var text:String = evt.fault.faultString;
                Alert.show(text, title);
                xmlListColl.removeAll();
            }
 
 
            private var menubarXML:XMLList =
                <>
                    <menuitem label="Product Range">
                        <menuitem label="Wallet" data="Wallet"/>
                        <menuitem label="Office Bags" data="Office Bags"/>
                        <menuitem label="Ladies Bags" data="Ladies Bags"/>
                    </menuitem>
                  
                </>;
 
            // Event handler for the MenuBar control's itemClick event.
            private function menuHandler(event:MenuEvent):void  {
               /*  Alert.show("Label: " + event.item.@label + "\n" + 
                    "Data: " + event.item.@data, "Clicked menu item"); */
                    producthid.text=event.item.@data;
                    result_create.send();
            }
 
            // Event handler to initialize the MenuBar control.
            private function initCollections():void {
                menuBarCollection = new XMLListCollection(menubarXML);
            }
            
            
            
            
            
            //For TILELIST
            
            
            private var fullImg:Image;
 
            private function init(obj:Object = null):void {
                if (obj == null) {
                    panel.title = "";
                    img.source = null;
                } else {
                    panel.title = String(obj.@title).toUpperCase();
                    img.source = obj.@fullImage;
                }
            }
 
            private function horizontalList_change(evt:ListEvent):void {
                init(evt.target.selectedItem);
            }
 
            private function horizontalList_itemRollOver(evt:ListEvent):void {
                init(evt.itemRenderer.data);
            }
 
            private function horizontalList_itemRollOut(evt:ListEvent):void {
                if (horizontalList.selectedIndex == -1) {
                    init(null);
                } else {
                    init(horizontalList.selectedItem);
                }
            }
            
            private function horizontalList_doubleClick(evt:MouseEvent):void {
                var obj:Object = evt.currentTarget.selectedItem;
                fullImg = new Image();
                fullImg.source = obj.@fullImage;
                fullImg.toolTip = "Click to close pop up";
                fullImg.buttonMode = true;
                fullImg.useHandCursor = true;
                fullImg.addEventListener(ResizeEvent.RESIZE, fullImg_resize);
                fullImg.addEventListener(MouseEvent.CLICK, fullImg_click);
                PopUpManager.addPopUp(fullImg, this, true);
            }
            
            private function fullImg_resize(evt:ResizeEvent):void {
                PopUpManager.centerPopUp(fullImg);
            }
            
            private function fullImg_click(evt:MouseEvent):void {
                PopUpManager.removePopUp(fullImg);
            }
            
            
         ]]>
    </mx:Script>
	
	<!--<mx:XML id="xml" source="{result_create.lastResult.gallery.image}" />-->
    <mx:XMLListCollection id="xmlListColl" />
    
    <mx:Panel id="panel"
            layout="absolute"
            styleName="opaquePanel"
            height="100%" width="543">
 
        <mx:MenuBar labelField="@label" itemClick="menuHandler(event);" 
            dataProvider="{menuBarCollection}"  width="120" x="10" y="2"/>
        <mx:ControlBar width="523" height="416" y="28">
        <mx:TileList id="horizontalList" dataProvider="{xmlListColl}"
                    labelField="lbl"
                    iconField="src"
                    itemRenderer="CustomItemRenderer"
                    columnCount="3"
                    columnWidth="125"
                    rowHeight="100"
                    horizontalScrollPolicy="on"
                    change="horizontalList_change(event);"
                    itemRollOver="horizontalList_itemRollOver(event);"
                    itemRollOut="horizontalList_itemRollOut(event);"
                    doubleClickEnabled="true"
                    doubleClick="horizontalList_doubleClick(event);"  width="194" height="394"/>
        <mx:Image id="img"
                scaleContent="true"
                maintainAspectRatio="true"
                width="250"
                height="250"
                completeEffect="Fade" />
        <mx:Label visible="true" text="dd" id="producthid" name="producthid"/>
           
        </mx:ControlBar>    
    </mx:Panel>
 
</mx:Application>

Open in new window

Avatar of evcr
evcr
Flag of United Kingdom of Great Britain and Northern Ireland image

can you show us what the aspx output data looks like.
Avatar of akulavi
akulavi

ASKER

sure
aspx generated xml - output will be like this :

<gallery>
<image title="a" label="a" thumbnailimage="../images/img1" fullimage="../images/img1full" />
<image title="a" label="a" thumbnailimage="../images/img2" fullimage="../images/img2full" />
<image title="a" label="a" thumbnailimage="../images/img3" fullimage="../images/img3full" />
<image title="a" label="a" thumbnailimage="../images/img4" fullimage="../images/img4full" />
</gallery>

Couple of things:

1. Add the next line to the top of your code:
import mx.utils.ObjectUtil;
In your result handler add this line:
trace(ObjectUtil.toString(evt.result));
Run the application, is the data traced in the console window the same as you posted above?

2. Is the aspx expecting to receive any variables from Flex in order to respond with that data? if so you need to post URLVariables in your send().

Also, you have the tilelist itemRenderer set to CustomItemRenderer although that is not defined anywhere, so your example code fails.

Avatar of akulavi

ASKER

1. As per your comments I have already added, but in console window nothing is showing .
2. In <httpservice>, I had already mentioned the variable which i need to pass to aspx.
3. CustomItemRenderer is already there. I am giving you its copy.

Pls help me urgently .. I have already crossed the deadline of the project..
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/03/08/creating-a-simple-image-gallery-with-the-flex-tilelist-control/ -->
<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>

Open in new window

can you show me some of the aspx code? i started making a dummy one to test with then remembered what an unpleasant language it is :-)
Avatar of akulavi

ASKER

I am attaching the code
Private Sub GenerateXML(ByVal catid As String)
        Dim sqlcmd As SqlCommand
        Dim connstring As String
        connstring = ConfigurationSettings.AppSettings("ConnectionString")
        Dim cn As New SqlConnection(connstring)
        cn.Open()
        sqlcmd = New SqlCommand("catalogue_allrecordsforflex", cn)
        sqlcmd.CommandType = CommandType.StoredProcedure
        sqlcmd.Parameters.Add("@catid", SqlDbType.VarChar, 15).Value = catid
        Dim sqldtr1 As New SqlDataAdapter(sqlcmd)
        Dim dst1 As New DataSet
        dst1.Clear()
        sqldtr1.Fill(dst1, "POLO")
        Dim i As Integer
        Response.Write("<?xml version='1.0' encoding='utf-8' ?>")
        Response.Write("<gallery>")
        For i = 0 To dst1.Tables(0).Rows.Count - 1
            Dim imgid As String = dst1.Tables(0).Rows(i).Item(0)
            Dim imgtitle As String = dst1.Tables(0).Rows(i).Item(1)
            Dim imgcode As String = dst1.Tables(0).Rows(i).Item(2)
            Dim imgname As String = dst1.Tables(0).Rows(i).Item(3)
            Response.Write("<image title='" & imgtitle & "' code='" & imgcode & "' name='" & imgname & "' thumbnailImage='../images/" & imgname & "' fullImage='../images/" & imgname & "' />")
        Next
        cn.Close()
        Response.Write("</gallery>")
    End Sub
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim catname As String = Request.Form("productrange")
        If catname = "" Then
            catname = "Ladies Bags"
        End If
        Dim sqlcmd As SqlCommand
        Dim connstring As String
        connstring = ConfigurationSettings.AppSettings("ConnectionString")
        Dim cn As New SqlConnection(connstring)
        cn.Open()
        sqlcmd = New SqlCommand("category_returniddependonname", cn)
        sqlcmd.CommandType = CommandType.StoredProcedure
        sqlcmd.Parameters.Add("@catname", SqlDbType.VarChar, 150).Value = catname
        Dim sqldtr As New SqlDataAdapter(sqlcmd)
        Dim dst As New DataSet
        dst.Clear()
        sqldtr.Fill(dst, "POLO")
        Dim CatId As String = dst.Tables(0).Rows(0).Item(0)
        cn.Close()
        GenerateXML(CatId)
    End Sub

Open in new window

this seems to work... it loads and shows the image tags in the tilelist.

I'll upload my test.aspx code in the next snippet

<?xml version="1.0"?>
<!-- Simple example to demonstrate the MenuBar control. -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="initCollections();"  width="870">
<mx:HTTPService id="result_create" url="http://localhost:2166/huntbags/test.aspx" useProxy="false" method="POST" showBusyCursor="true" resultFormat="e4x" result="httpService_result(event)" fault="httpService_fault(event);" />
        <mx:Script>
        <![CDATA[
            import mx.events.MenuEvent;
            import mx.controls.Alert;
            import mx.collections.*;
            import mx.controls.Image;
            import mx.events.ListEvent;
            import mx.events.ResizeEvent;
            import mx.managers.PopUpManager;
            import mx.rpc.events.ResultEvent;
            import mx.rpc.events.FaultEvent;
            import mx.utils.ObjectUtil;
 
 
            [Bindable]
            public var menuBarCollection:XMLListCollection;
            [Bindable]            
            public var xmlListColl:XMLListCollection;
            
            private function httpService_result(evt:ResultEvent):void {               	
                trace(ObjectUtil.toString(evt.result));
                var xmlList:XMLList = XML(evt.result).image;
                xmlListColl = new XMLListCollection(xmlList);
                trace(ObjectUtil.toString(xmlListColl));
            }
            private function httpService_fault(evt:FaultEvent):void {
                var title:String = evt.type + " (" + evt.fault.faultCode + ")";
                var text:String = evt.fault.faultString;
                Alert.show(text, title);
                xmlListColl.removeAll();
            }
            private var menubarXML:XMLList =
                <>
                    <menuitem label="Product Range">
                        <menuitem label="Wallet" data="Wallet"/>
                        <menuitem label="Office Bags" data="Office Bags"/>
                        <menuitem label="Ladies Bags" data="Ladies Bags"/>
                    </menuitem>
                  
                </>;
 
            // Event handler for the MenuBar control's itemClick event.
            private function menuHandler(event:MenuEvent):void  {
               /*  Alert.show("Label: " + event.item.@label + "\n" + 
                    "Data: " + event.item.@data, "Clicked menu item"); */
                    producthid.text=event.item.@data;
					
					var resVars:URLVariables = new URLVariables; 
					resVars.productrange = producthid.text;
                    result_create.send(resVars);
            }
            // Event handler to initialize the MenuBar control.
            private function initCollections():void {
                menuBarCollection = new XMLListCollection(menubarXML);
            }
            //For TILELIST
            private var fullImg:Image;
 
            private function init(obj:Object = null):void {
                if (obj == null) {
                    panel.title = "";
                    img.source = null;
                } else {
                    panel.title = String(obj.@title).toUpperCase();
                    img.source = obj.@fullImage;
                }
            }
            private function horizontalList_change(evt:ListEvent):void {
             //   init(evt.target.selectedItem);
            }
            private function horizontalList_itemRollOver(evt:ListEvent):void {
                //init(evt.itemRenderer.data);
            }
            private function horizontalList_itemRollOut(evt:ListEvent):void {
                if (horizontalList.selectedIndex == -1) {
               //     init(null);
                } else {
               //     init(horizontalList.selectedItem);
                }
            }
            private function horizontalList_doubleClick(evt:MouseEvent):void {
                var obj:Object = evt.currentTarget.selectedItem;
                fullImg = new Image();
                fullImg.source = obj.@fullImage;
                fullImg.toolTip = "Click to close pop up";
                fullImg.buttonMode = true;
                fullImg.useHandCursor = true;
                fullImg.addEventListener(ResizeEvent.RESIZE, fullImg_resize);
                fullImg.addEventListener(MouseEvent.CLICK, fullImg_click);
                PopUpManager.addPopUp(fullImg, this, true);
            }
            private function fullImg_resize(evt:ResizeEvent):void {
                PopUpManager.centerPopUp(fullImg);
            }
            private function fullImg_click(evt:MouseEvent):void {
                PopUpManager.removePopUp(fullImg);
            }
         ]]>
    </mx:Script>
           
    <mx:Panel id="panel"
            layout="absolute"
            styleName="opaquePanel"
            height="100%" width="543">
 
        <mx:MenuBar labelField="@label" itemClick="menuHandler(event);" 
            dataProvider="{menuBarCollection}"  width="120" x="10" y="2"/>
        <mx:ControlBar width="523" height="416" y="28">
        <mx:TileList id="horizontalList" dataProvider="{xmlListColl}"
                    labelField="lbl"
                    iconField="src"
                    itemRenderer="CustomItemRenderer"
                    columnCount="3"
                    columnWidth="125"
                    rowHeight="100"
                    horizontalScrollPolicy="on"
                    change="horizontalList_change(event);"
                    itemRollOver="horizontalList_itemRollOver(event);"
                    itemRollOut="horizontalList_itemRollOut(event);"
                    doubleClickEnabled="true"
                    doubleClick="horizontalList_doubleClick(event);"  width="194" height="394"/>
        <mx:Image id="img"
                scaleContent="true"
                maintainAspectRatio="true"
                width="250"
                height="250"
                completeEffect="Fade" />
        <mx:Label visible="true" text="dd" id="producthid" name="producthid"/>       
        </mx:ControlBar>    
    </mx:Panel>
 </mx:Application>
 
8< snip ---------CustomItemRenderer.mxml
 
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/03/08/creating-a-simple-image-gallery-with-the-flex-tilelist-control/ -->
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
        horizontalAlign="center"
        verticalAlign="middle">
    <mx:Image source="{'../images/' + data.@thumbnailimage}" />
    <mx:Label text="data.@title" />
</mx:VBox>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of evcr
evcr
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of akulavi

ASKER

Only I need to change the following lines in CustomeItemRendere.
 
   

changed  form