Context in FlashBuilder gives error Type 1136: Incorrect number of arguments. Expected 1.

timkindberg's Avatar

timkindberg

01 Nov, 2010 08:48 PM

In an MXML file I have this code from Joel Hooks Service tutorial:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
           xmlns:s="library://ns.adobe.com/flex/spark" 
           xmlns:mx="library://ns.adobe.com/flex/mx" 
           width="300" height="300"            
           xmlns:local="*" 
           xmlns:components="components.*"
           creationComplete="application1_creationCompleteHandler(event)">
<fx:Script>
<![CDATA[
    import components.SearchResultsView;        
    import mx.events.FlexEvent;     

    protected function application1_creationCompleteHandler(event:FlexEvent):void
    {
        var context:ServiceExampleContext = new ServiceExampleContext(this);
        var searchResultsView:SearchResultsView = new SearchResultsView();
        addElement(searchResultsView);
    }

]]>
</fx:Script>
<fx:Declarations>
    <local:ServiceExampleContext contextView="{this}"/>
</fx:Declarations>
<components:SearchResultsView/>
</s:Application>

I keep getting the error Type 1136: Incorrect number of arguments. Expected 1. because the Context class needs 1 parameter to be passed to the constructor and MXML cannot pass parameters to constructors.

How are people getting around this?

  1. Support Staff 1 Posted by Shaun Smith on 01 Nov, 2010 10:08 PM

    Shaun Smith's Avatar

    Hi Tim,

    Where does that code come from? It looks pretty broken to me - everything is doubled up (both the context initialization and the SearchResultsView addition). Try deleting the script block and creationComplete handler and updating to the latest version of Robotlegs. It should look something like this:

    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" 
               width="300" height="300"            
               xmlns:local="*" 
               xmlns:components="components.*">
    <fx:Declarations>
        <local:ServiceExampleContext contextView="{this}"/>
    </fx:Declarations>
    <components:SearchResultsView/>
    </s:Application>

    Context class needs 1 parameter to be passed to the constructor and MXML cannot pass parameters to constructors.

    The Context should not have any required constructor arguments when working with MXML (unless you are working with a pre-1.0.0 version of Robotlegs). Perhaps the tutorial you are following is very old?

  2. 2 Posted by timkindberg on 02 Nov, 2010 12:41 PM

    timkindberg's Avatar

    Hi Shaun, Thank you for the quick reply! I'm sorry, I had added the Script block because it was the only way I could get it to work. It's from Joel Hooks Service tutorial. I meant to delete it before posting.

    I have the robotlegs-framework-v1.3.0.swc in my libs folder, so unless the swc was compiled incorrectly I have the latest version.

    I just commented out the Script block and published and it works in the HTML publish but I still get the error (red overlay X icon) on my MXML file in FlashBuilder 4. I'm pretty OCD, does that ever go away or I just have to live with it? itching neck

    Also a quick side question. In that tutorial he calls a class called HTMLStringTools, which I would assume is in the as3corelib.swc, but it's not there. A search for it on the internet literally returns only 2 results, neither helpful. Do you know where the heck he could be getting that class from?

  3. Support Staff 3 Posted by Shaun Smith on 02 Nov, 2010 01:26 PM

    Shaun Smith's Avatar

    I had added the Script block because it was the only way I could get it to work

    Hmm.. something is very wrong then. It should work fine without it. It's redundant and makes your root mxml file look pretty gross.

    it works in the HTML publish but I still get the error (red overlay X icon) on my MXML file in FlashBuilder 4. I'm pretty OCD, does that ever go away or I just have to live with it? itching neck

    Not a chance mate! I doubt there is a single RL user who would be okay with any errors/warnings - something is definitely wrong with your setup. You should have 0 constructor arguments in your concrete Context. Make sure to "clean" your FB project.

    Joel is obviously uber busy at the mo, but hopefully he'll pop by soon and offer some input.

  4. 4 Posted by timkindberg on 02 Nov, 2010 01:36 PM

    timkindberg's Avatar

    That was it. I still had the constructor arguments in my actual constructor class. I just deleted the constructor completely and only kept the startup function. I thought the Context constructor parameter was mandatory, I didn't think I was allowed to delete it. So now I know.

    Now I am able to delete the Script tag and only have the MXML declaration of Context and the SearchResultsView component.

    You've been very helpful :) It turns out it was just a newb.

  5. timkindberg closed this discussion on 02 Nov, 2010 01:37 PM.

  6. timkindberg re-opened this discussion on 02 Nov, 2010 01:40 PM

  7. 5 Posted by timkindberg on 02 Nov, 2010 01:40 PM

    timkindberg's Avatar

    Just to clarify to followup readers, the issue was that I still had the old constructor in my concrete Context class.

    I had this:

    public class ServiceExampleContext extends Context 
    {
        /**
         * Constructor
         */
        public function ServiceExampleContext(contextView:DisplayObjectContainer) 
        {
            super(contextView);
        }   
    
        override public function startup():void
        {       
            mediatorMap.mapView(SearchResultsView, SearchResultsViewMediator);
    
            injector.mapSingletonOf(ISearchService, TwitterSearchService);
            injector.mapSingletonOf(ISearchResultsParser, TwitterSearchResultsParser);
        }       
    }

    Which needed to be this (removed constructor):

    public class ServiceExampleContext extends Context 
    {
        override public function startup():void
        {       
            mediatorMap.mapView(SearchResultsView, SearchResultsViewMediator);
    
            injector.mapSingletonOf(ISearchService, TwitterSearchService);
            injector.mapSingletonOf(ISearchResultsParser, TwitterSearchResultsParser);
        }
    
    }
  8. timkindberg closed this discussion on 02 Nov, 2010 01:40 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac