hi flexcoders;

The idea is I have a "container" swf, a "list" swf and an "add" swf.
When "container" swf is running, it first loads the "list" swf and
displays some buttons like "add". The "list" swf displays data in
several pages and you can change the page with a horizontal slide. When
"add" button is clicked, the "add" swf is loaded and displayed with some
buttons like "cancel", "submit" and "clear". And in "add" swf, when
"cancel" button is clicked, the "container" swf should display the "list"
swf with its current state.

It's really disturbing me because when "list" swf runs as a single swf,
page changing works ok, but when it's running as a loaded swf by
"container" swf, page changing gave me the following two errors:

TypeError: Error #1034: Type Coercion failed: cannot convert
mx.messaging.messages::[EMAIL PROTECTED] to
mx.messaging.messages.Message

TypeError: Error #1034: Type Coercion failed: cannot convert
mx.messaging.messages::[EMAIL PROTECTED] to
mx.messaging.messages.Message

I guess I must have missed something but I tried with no luck. And I
just couldn't figure out why the errors only occured when loaded.

Any help would be appreciated.

-xd

List.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*" layout="absolute" creationComplete="InitApp()">
      <mx:Script source="List.as"/>
      <mx:Panel title="List" width="95%">
            <mx:DataGrid id="dg" dataProvider="{svc.getList.result}" width="100%" rowCount="2">
                  <mx:columns>
                        <mx:DataGridColumn headerText="Name" dataField="apm_name"/>
                        <mx:DataGridColumn headerText="Description" dataField="apm_desc"/>
                  </mx:columns>
            </mx:DataGrid>
            <mx:HBox width="100%">
                  <mx:Spacer width="25%"/>
                  <mx:HSlider id="hsldPageNo" width="50%" minimum="1" maximum="{svc.getPageCounts.result}" tickInterval="1" snapInterval="1" dataTipPlacement="bottom" dataTipFormatFunction="pageToolTipFunc" change="pageChange(event);"/>
                  <mx:Spacer width="25%"/>
            </mx:HBox>
      </mx:Panel>
      <mx:RemoteObject id="svc" destination="ColdFusion" source="cf.ap"/>
</mx:Application>

List.as
import mx.events.SliderEvent;
public function InitApp():void {
      getInfo(0);
}
public function getInfo(nPageNo:int):void {
      svc.getList(nPageNo);
      svc.getPageCounts();
}
private function pageChange(event:SliderEvent):void {
      getInfo(event.currentTarget.value - 1);
}
private function pageToolTipFunc(val:String):String {
      return "page " + int(val);
}


Add.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*" layout="absolute">
      <mx:Script source="Add.as"/>
      <mx:Panel title="AddForm" width="95%">
            <mx:Form width="100%">
                  <mx:FormItem label="Name" required="true">
                        <mx:TextInput id="txtiName"/>
                  </mx:FormItem>
                  <mx:FormItem label="Description">
                        <mx:TextInput id="txtiDesc"/>
                  </mx:FormItem>
                  <mx:HBox width="100%">
                        <mx:Button label="Cancel" click="cancelAction();"/>
                        <mx:Spacer width="100%"/>
                        <mx:Button label="Reset" click="clearAction();"/>
                        <mx:Button label="Submit" click="addAction();"/>
                  </mx:HBox>
            </mx:Form>
      </mx:Panel>
</mx:Application>

Add.as
public function addAction():void {
      clearForm();
      if(this.automationParent) {
            var obj:Object = Object(this).automationParent.parentApplication;
            obj.afterAdd("addok");
      }
}
public function cancelAction():void {
      clearForm();
      if(this.automationParent) {
            var obj:Object = Object(this).automationParent.parentApplication;
            obj.afterAdd("cancel");
      }
}
public function clearAction():void {
      clearForm();
}
public function clearForm():void {
      txtiName.text = "";
      txtiDesc.text = "";
}


Container.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*" layout="absolute" backgroundColor="#FFFFFF">
      <mx:Script source="Container.as"/>
      <mx:VBox width="95%" height="95%" horizontalAlign="center">
            <mx:ViewStack id="vstk" width="100%" height="100%" change="changeDisplay(event);">
                  <mx:Panel id="cnvList" label="List" width="100%" height="100%">
                        <mx:Button label="Add" click="toAddForm();"/>
                        <mx:Loader id="ldrList" width="100%" height="100%" source="List.swf"/>
                  </mx:Panel>
                  <mx:Panel id="cnvAdd" label="Add" width="100%" height="100%">
                        <mx:Loader id="ldrAdd" width="100%" height="100%" source="Add.swf"/>
                  </mx:Panel>
            </mx:ViewStack>
      </mx:VBox>
</mx:Application>

Container.as
import mx.events.IndexChangedEvent;
public function toList():void {
      vstk.selectedIndex = 0;
}
public function toAddForm():void {
      vstk.selectedIndex = 1;
}
public function afterAdd(status:String):void {
      if(status == "addok")
            toList();
      if(status == "cancel")
            toList();
}
public function changeDisplay(e:IndexChangedEvent):void {
//      if(e.currentTarget.selectedIndex == 0)
//            e.currentTarget.selectedChild.getChildByName("ldrList").load();
}


ap.cfc
<cfcomponent>
      <cfset nCountsPerPage = 1>
      <cffunction name="getList" returntype="query" access="remote" output="false">
            <cfargument name="nPageNo" type="numeric" default="0">
            <cfset nSkipCounts = nPageNo * nCountsPerPage>
            <cfscript>
                  myQuery = QueryNew("apm_id, apm_name, apm_desc");
                  for(iRow = nSkipCounts + 1; iRow LE min(3, nSkipCounts + nCountsPerPage); iRow = IncrementValue(iRow)) {
                        QueryAddRow(myQuery);
                        QuerySetCell(myQuery, "apm_id", "id" & iRow);
                        QuerySetCell(myQuery, "apm_name", "name" & iRow);
                        QuerySetCell(myQuery, "apm_desc", "desc" & iRow);
                  }
            </cfscript>
            <cfreturn myQuery>
      </cffunction>
      <cffunction name="getPageCounts" returntype="numeric" access="remote" output="false">
            <cfreturn 3>
      </cffunction>
</cfcomponent>



--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




YAHOO! GROUPS LINKS




Reply via email to