10 Replies Latest reply on Apr 21, 2010 8:16 PM by mroiler

    ActionScript Error:Type Coercion failed?

    mroiler

      I get an error using this code. I am using flex 4.

      <fx:Declarations>

           <s:HTTPService id="formSend" url=[my website url]" method="POST" contentType="application/x-www-form-urlencoded" resultFormat="text"> 
                  <mx:request> 
                      <num>{num.text}</num> 
                      <type>{type.selectedItem}</type> 
                      <comment>{comment.text}</comment>
                  </mx:request> 
              </s:HTTPService>

      <fx:Declarations>

      <mx:Form x="6" y="8" id="devForm" height="265">
                          <mx:FormItem label="Login #(found on home page):">
                              <s:TextInput id="num"/>
                          </mx:FormItem>
                          <mx:FormItem label="Type of request/comment:">
                              <s:DropDownList dataProvider="{ddlData}" id="type"/>
                          </mx:FormItem>
                          <mx:FormItem label="Description of widget/tab or comment:">
                              <s:TextArea editable="true" id="comment"/>
                          </mx:FormItem>
                          <mx:FormItem>
                              <s:Button id="button"
                                        click="formSend.send()" label="Submit"/>
                          </mx:FormItem>
                      </mx:Form>

       

       

      TypeError: Error #1034: Type Coercion failed: cannot convert []@de455f1 to mx.collections.IList.
          at mx.binding::Binding/defaultDestFunc()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\b inding\Binding.as:270]
          at Function/http://adobe.com/AS3/2006/builtin::call()
          at mx.binding::Binding/innerExecute()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\bind ing\Binding.as:475]
          at Function/http://adobe.com/AS3/2006/builtin::apply()
          at mx.binding::Binding/wrapFunctionCall()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\ binding\Binding.as:385]
          at mx.binding::Binding/execute()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\binding\B inding.as:321]
          at mx.binding::BindingManager$/executeBindings()[E:\dev\4.0.0\frameworks\projects\framework\ src\mx\binding\BindingManager.as:153]
          at mx.core::UIComponent/executeBindings()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\ core\UIComponent.as:10691]
          at mx.core::Container/createComponentFromDescriptor()[E:\dev\4.0.0\frameworks\projects\frame work\src\mx\core\Container.as:4373]
          at mx.core::Container/createComponentsFromDescriptors()[E:\dev\4.0.0\frameworks\projects\fra mework\src\mx\core\Container.as:4160]
          at mx.core::Container/createChildren()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\cor e\Container.as:3187]
          at mx.containers::FormItem/createChildren()[E:\dev\4.0.0\frameworks\projects\framework\src\m x\containers\FormItem.as:479]
          at mx.core::UIComponent/initialize()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\ UIComponent.as:7250]
          at mx.core::Container/initialize()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\Co ntainer.as:3129]
          at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::childAdded()[E:\dev\4.0.0\frameworks\projects\ framework\src\mx\core\UIComponent.as:7142]
          at mx.core::Container/http://www.adobe.com/2006/flex/mx/internal::childAdded()[E:\dev\4.0.0\frameworks\projects\ framework\src\mx\core\Container.as:3951]
          at mx.core::Container/addChildAt()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\Co ntainer.as:2616]
          at mx.containers::Form/addChildAt()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\contai ners\Form.as:293]
          at mx.core::Container/addChild()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\Cont ainer.as:2534]
          at mx.containers::Form/addChild()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\containe rs\Form.as:282]
          at mx.core::Container/createComponentFromDescriptor()[E:\dev\4.0.0\frameworks\projects\frame work\src\mx\core\Container.as:4371]
          at mx.core::Container/createComponentsFromDescriptors()[E:\dev\4.0.0\frameworks\projects\fra mework\src\mx\core\Container.as:4160]
          at mx.core::Container/createChildren()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\cor e\Container.as:3187]
          at mx.core::UIComponent/initialize()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\ UIComponent.as:7250]
          at mx.core::Container/initialize()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\Co ntainer.as:3129]
          at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::childAdded()[E:\dev\4.0.0\frameworks\projects\ framework\src\mx\core\UIComponent.as:7142]
          at mx.core::UIComponent/addChildAt()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\ UIComponent.as:6848]
          at spark.components::Group/addDisplayObjectToDisplayList()[E:\dev\4.0.0\frameworks\projects\ spark\src\spark\components\Group.as:1825]
          at spark.components::Group/http://www.adobe.com/2006/flex/mx/internal::elementAdded()[E:\dev\4.0.0\frameworks\project s\spark\src\spark\components\Group.as:1416]
          at spark.components::Group/setMXMLContent()[E:\dev\4.0.0\frameworks\projects\spark\src\spark \components\Group.as:512]
          at spark.components::Group/set mxmlContent()[E:\dev\4.0.0\frameworks\projects\spark\src\spark\components\Group.as:452]
          at spark.components::SkinnableContainer/set mxmlContent()[E:\dev\4.0.0\frameworks\projects\spark\src\spark\components\SkinnableContai ner.as:604]
          at spark.components::SkinnableContainer/createDeferredContent()[E:\dev\4.0.0\frameworks\proj ects\spark\src\spark\components\SkinnableContainer.as:986]
          at spark.components::SkinnableContainer/createContentIfNeeded()[E:\dev\4.0.0\frameworks\proj ects\spark\src\spark\components\SkinnableContainer.as:1014]
          at spark.components::SkinnableContainer/createChildren()[E:\dev\4.0.0\frameworks\projects\sp ark\src\spark\components\SkinnableContainer.as:827]
          at mx.core::UIComponent/initialize()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\ UIComponent.as:7250]
          at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::childAdded()[E:\dev\4.0.0\frameworks\projects\ framework\src\mx\core\UIComponent.as:7142]
          at mx.core::UIComponent/addChildAt()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\ UIComponent.as:6848]
          at spark.components::Group/addDisplayObjectToDisplayList()[E:\dev\4.0.0\frameworks\projects\ spark\src\spark\components\Group.as:1825]
          at spark.components::Group/http://www.adobe.com/2006/flex/mx/internal::elementAdded()[E:\dev\4.0.0\frameworks\project s\spark\src\spark\components\Group.as:1416]
          at spark.components::Group/setMXMLContent()[E:\dev\4.0.0\frameworks\projects\spark\src\spark \components\Group.as:512]
          at spark.components::Group/set mxmlContent()[E:\dev\4.0.0\frameworks\projects\spark\src\spark\components\Group.as:452]
          at spark.components::SkinnableContainer/set mxmlContent()[E:\dev\4.0.0\frameworks\projects\spark\src\spark\components\SkinnableContai ner.as:604]
          at spark.components::SkinnableContainer/createDeferredContent()[E:\dev\4.0.0\frameworks\proj ects\spark\src\spark\components\SkinnableContainer.as:986]
          at mx.containers::ViewStack/instantiateSelectedChild()[E:\dev\4.0.0\frameworks\projects\fram ework\src\mx\containers\ViewStack.as:1251]
          at mx.containers::ViewStack/commitProperties()[E:\dev\4.0.0\frameworks\projects\framework\sr c\mx\containers\ViewStack.as:750]
          at mx.containers::TabNavigator/commitProperties()[E:\dev\4.0.0\frameworks\projects\framework \src\mx\containers\TabNavigator.as:568]
          at mx.core::UIComponent/validateProperties()[E:\dev\4.0.0\frameworks\projects\framework\src\ mx\core\UIComponent.as:7772]
          at mx.managers::LayoutManager/validateProperties()[E:\dev\4.0.0\frameworks\projects\framewor k\src\mx\managers\LayoutManager.as:572]
          at mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\4.0.0\frameworks\projects\frame work\src\mx\managers\LayoutManager.as:730]
          at mx.managers::LayoutManager/doPhasedInstantiationCallback()[E:\dev\4.0.0\frameworks\projec ts\framework\src\mx\managers\LayoutManager.as:1072]

        • 1. Re: ActionScript Error:Type Coercion failed?
          David_F57 Level 5

          hi,

           

          type.selecteditem is a pointer you need to get the the selected items value.

           

          David.

          1 person found this helpful
          • 2. Re: ActionScript Error:Type Coercion failed?
            mroiler Level 1

            So what am I supposed to change?

            • 3. Re: ActionScript Error:Type Coercion failed?
              David_F57 Level 5

              hi,

               

              Sorry I must have been half asleep and didn't finish the post, as I normally would

               

              becuase you have an object (xml only understands string) you need to typecast the value, if it is a simple object like the one you have it casts directly to a string, if its a complex object you would obviously go deeper to the value you need.

               

               

              String(type.selectedItem) , in your xml request definition.

               

               

              David

              1 person found this helpful
              • 4. Re: ActionScript Error:Type Coercion failed?
                mroiler Level 1

                I still get the same error. Is this what you meant?

                 

                 

                <s:HTTPService id="formSend" url="[my website url]" method="POST" contentType="application/x-www-form-urlencoded" resultFormat="text"> 
                            <mx:request> 
                                <num>{num.text}</num> 
                                <type>String(type.selectedItem)</type> 
                                <comment>{comment.text}</comment>
                            </mx:request> 
                        </s:HTTPService>

                • 5. Re: ActionScript Error:Type Coercion failed?
                  David_F57 Level 5

                  hi,

                   

                  If the data you are retreiving is not complex ie the selecteditem object is a string then its ok, you should probably be retreiveing the value from the array anyway,

                   

                  Before you get any run errors are you getting any warnings in your code. The following code works ok...I just use vars for the num and comment so I could have values.

                   

                  [Bindable] private var arr:ArrayCollection = new ArrayCollection([{id:"1",name:"David"},{id:"2",name:"Peter"}]);

                  private var idNum:int=10;

                  private var myComment:String="the comments";

                  <fx:Declarations>
                  <s:HTTPService id="formSend" url="{myURL}" method="POST" contentType="application/x-www-form-urlencoded" resultFormat="e4x"> 
                  <mx:request> 
                  <num>idNum</num> 
                  <type>arr[myList.selectedIndex].name</type> 
                  <comment>myComment</comment>
                  </mx:request> 
                  </s:HTTPService>
                  </fx:Declarations>
                  <s:DropDownList id="myList" x="505" y="288" dataProvider="{arr}" labelField="name"></s:DropDownList>

                  • 6. Re: ActionScript Error:Type Coercion failed?
                    mroiler Level 1

                    As soon as I click on the Tab with the form I get that error. I guess I may of missed out some code this is the rest. The xml file at data/ddl.xml is at the bottom.

                     

                    <fx:Declarations>
                            <s:HTTPService id="formSend" url="[my site url]" method="POST" contentType="application/x-www-form-urlencoded" resultFormat="text"> 
                                <mx:request> 
                                    <num>{num.text}</num> 
                                    <type>{type.selectedItem}</type> 
                                    <comment>{comment.text}</comment>
                                </mx:request> 
                            </s:HTTPService>
                            <s:HTTPService id="ddlData" url="data/ddl.xml"/>
                        </fx:Declarations>
                        <mx:TabNavigator width="100%" height="100%" x="0" y="0">

                     

                         (I also have other tabs)


                            <s:NavigatorContent label="Add" width="100%" height="100%" skinClass="components.AppSkin2">
                                <s:Panel x="10" y="10" width="461" height="308" title="Request a widget, tab or place a comment.">
                                    <mx:Form x="6" y="8" id="devForm" height="265">
                                        <mx:FormItem label="Login #(found on home page):">
                                            <s:TextInput id="num"/>
                                        </mx:FormItem>
                                        <mx:FormItem label="Type of request/comment:">
                                            <s:DropDownList dataProvider="{ddlData}" id="type"/>
                                        </mx:FormItem>
                                        <mx:FormItem label="Description of widget/tab or comment:">
                                            <s:TextArea editable="true" id="comment"/>
                                        </mx:FormItem>
                                        <mx:FormItem>
                                            <s:Button id="button"
                                                      click="formSend.send()" label="Submit"/>
                                        </mx:FormItem>
                                    </mx:Form>
                                </s:Panel>
                            </s:NavigatorContent>
                        </mx:TabNavigator>

                     

                     

                     

                    <?xml version="1.0" encoding="utf-8"?>

                    <types>

                          <type>Add a Tab</type>

                         <type>Add a  Widget</type>

                         <type>Comment</type>

                    </types>

                    • 7. Re: ActionScript Error:Type Coercion failed?
                      David_F57 Level 5

                      hi,

                       

                      Your dropdown list is wrong you are pointing to a http service rather than its result.

                       

                      I was thinking that the error was in the send service but its actually the recieved data(as in you aren't pointing to it)

                       

                                              <s:DropDownList dataProvider="{ddlData}" id="type"/> 

                       

                       

                      David.

                      • 8. Re: ActionScript Error:Type Coercion failed?
                        mroiler Level 1

                        I've lost the error after making it ddlData.lastResult.types.type but As soon as I click to type in another field or submit it, the value dissapears.

                        • 9. Re: ActionScript Error:Type Coercion failed?
                          David_F57 Level 5

                          hi,

                           

                          Hard to say at this point if all your data is showing up in the first instance(make sure the droplist is populated correctly) I would say you need to look at data persistence. Try storing the retreived info into an arraycollection and see if you get data persistence.

                           

                           

                          David.

                          • 10. Re: ActionScript Error:Type Coercion failed?
                            mroiler Level 1

                            Made it an Array collection in the actual file and got rid of the HTTP Service and it worked perfectly. Thanks!