views:

558

answers:

1

My flex project has the following mxml file:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
xmlns:coverflow="com.dougmccune.coverflow.*"
layout="vertical" horizontalAlign="center" verticalAlign="middle"
viewSourceURL="srcview/index.html" xmlns:containers="com.dougmccune.containers.*"       xmlns:ns1="com.blitzagency.xray.logger.*" 
   creationComplete="init()">
<mx:Script>
 <![CDATA[
  import mx.events.FlexEvent;
  import generated.webservices.*;

  [Bindable]
  public var numResults: int = 0;

  private function init() : void
  {
   var service:ICarouselService = new CarouselService();
   service.addregisterSearchSetEventListener(registerSearchSetListener);


   // library_id
   service.registerSearchSet(1);

  }


  private function registerSearchSetListener(event:RegisterSearchSetResultEvent):void
  {
   var searchData:SearchMetaData = event.result;
   numResults = searchData.noOfResults;
   if(testpanel != null)
   {
    testpanel.title = "" + numResults;
   }
   //customerItem = new CustomerItem(custData.customerName, custData.customerLogo);
   //g.add(customerItem);
  }
 ]]>
</mx:Script>
<mx:Style>
 Panel {
    borderColor: #99CDEE;
    borderAlpha: 1;
    borderThickness: 1;
    borderThicknessLeft: 1;
    borderThicknessTop: 0;
    borderThicknessBottom: 1;
    borderThicknessRight: 1;
    roundedBottomCorners: false;
    cornerRadius: 5;
    headerColors: #b5e6f3, #81b3e6;
    dropShadowEnabled: false;
    titleStyleName: "mypanelTitle";
    vertical-align:middle;
    horizontal-align:center;
 }

 .mypanelTitle {
    letterSpacing: 1;
    color: #333333;
    fontSize: 12;
    fontWeight: bold;
 }
</mx:Style>


 <mx:VBox id="box" verticalGap="0" height="306" width="100%" maxWidth="600" maxHeight="300" >

  <containers:CoverFlowContainer id="coverflow" width="100%" height="244" 
   horizontalGap="40" borderStyle="inset" backgroundColor="0x000000"
   segments="6" reflectionEnabled="true">


   <mx:Panel width="200" height="200" title="ZOMGZ! Look at the 3D!">
    <mx:DateChooser width="90%" height="90%"/>
   </mx:Panel>

   <mx:Panel id="testpanel" width="200" height="200" title="Mxml title">
    <mx:DataGrid width="100%" height="100%">
     <mx:columns>
      <mx:DataGridColumn headerText="Column 1" dataField="col1"/>
      <mx:DataGridColumn headerText="Column 2" dataField="col2"/>
      <mx:DataGridColumn headerText="Column 3" dataField="col3"/>
     </mx:columns>
    </mx:DataGrid>
   </mx:Panel>

   <mx:Panel id="buttonpanel" width="200" height="200" title="Mxml title">
    <mx:Button id="myButton" label="Change title" click="buttonpanel.title = ('hello') "/>
   </mx:Panel>


   <!-- here we're dispatching an UPDATE_COMPLETE event every frame. This is so our PV3D material will
     update itself properly for this component, since we want the animation to show correctly.
     -->
   <mx:Panel width="200" height="200" title="Showing Animation" 
    enterFrame="event.currentTarget.dispatchEvent(new FlexEvent(FlexEvent.UPDATE_COMPLETE))">
    <mx:ProgressBar width="90%" indeterminate="true" trackHeight="30" labelPlacement="center" />
   </mx:Panel>

  </containers:CoverFlowContainer>
  <mx:Grid width="100%">
   <mx:GridRow width="100%" height="100%">
    <mx:GridItem width="33%" height="100%" horizontalAlign="left">
     <mx:Text text="1" id="textLeft"/>
    </mx:GridItem>
    <mx:GridItem width="33%" height="100%" horizontalAlign="center">
     <mx:Text text="{coverflow.selectedIndex + 1}" id="textCenter"/>
    </mx:GridItem>
    <mx:GridItem width="33%" height="100%" horizontalAlign="right">
     <mx:Text text="{coverflow.numChildren}" id="textRight"/>
    </mx:GridItem>
   </mx:GridRow>
  </mx:Grid>
  <mx:HScrollBar id="scrollbar" width="600" pageSize="1" maxScrollPosition="{coverflow.numChildren - 1}"
   scrollPosition="{coverflow.selectedIndex}" 
   scroll="coverflow.selectedIndex = Math.round(scrollbar.scrollPosition)" />
  <mx:HBox width="100%">
   <mx:Text text="Text" textAlign="left"/>
   <mx:Spacer width="100%"/>
   <mx:Text text="Text" textAlign="center"/>
   <mx:Spacer width="100%"/>
   <mx:Text text="Text" textAlign="right"/>
  </mx:HBox>

 </mx:VBox> 
            </mx:Application>

So I've created a dummy web service using Java and it is running on tomcat. Using the wsdl file's url I generated the actionscript classes in this project for the web service.

Now I'm calling one of the web service's methods (registerSearchSet(1)) which returns a number. At the moment it just returns 1234.

After launching the application the panel's title says "Mxml title" and then after about two minutes it changes to "1234".

Any insights into why there is a delay? Is there a better way I should be doing this?

UPDATE: It seems now that the panel's title is being updated straight away there is no delay anymore. This is strange as I haven't changed the code, I have just closed flex builder for a few hours!

I would still be interested in hearing about best practises when using SOAP, Flex and tomcat.

Thanks.

A: 

Just out of curiosity, why are you manually dispatching an update-complete event on enterFrame like that? I don't have a running sample of your entire app, so I can't be sure it's related to the behavior you're experiencing per se, but that just smells somehow wrong to me. What happens with the Web Service call when you remove that attribute?

Also, have you tried setting a breakpoint on your result handler, or even using a trace statement just inside it, to see when the result actually comes back, to determine whether the delay is happening before or after the network trip occurs?

What you need to do is isolate where the delay is happening -- before the request, during the request or after the request -- and then go from there. What happens with your CPU while all this is happening? Do you notice a spike while you're running? There's no real magic to the way WebService calls work, so there's got to be something going on either on your machine, on your server, or in the code you've written or are using elsewhere in your project.

Christian Nunciato
I did try and isolate the delay before by setting a breakpoint where the title is set to numResults and running the project in debug mode. The server call seems to execute straight away without delay as the numResults variable has the 1234 value straight away.I don't see where I am "manually dispatching an update-complete event on enterFrame" .. could you point this out please?Also I have updated the question
Patrick Kiernan
<mx:Panel width="200" height="200" title="Showing Animation" enterFrame="event.currentTarget.dispatchEvent(new FlexEvent(FlexEvent.UPDATE_COMPLETE))"> <-- Here
Christian Nunciato
Ok, that isn't related to this problem. That is to show a progress bar working. Thanks
Patrick Kiernan
Yeah, sorry I couldn't help -- it looks like the problem kind of went away anyway. Cheers.
Christian Nunciato
No problem, thanks
Patrick Kiernan