0

Below is the code i'm looking at the moment.

<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
    xmlns:s="library://ns.adobe.com/flex/spark" title="data"
    xmlns:model="model.*"
    creationComplete="data=sqlSearch(data)"
    >

In this View, it has just been pushView 'ed with data object. I need to use this data as part of a sql search. I've used creationComplete one other time in the initial view. My understanding is, on creationComplete, whatever the function, (I'll just name sqlSearch here as the example), is run, and its return value becomes the data to be used in a List.

The error for the creationComplete line is

Multiple markers at this line: -1137: Incorrect number of arguments. Expected no more than 0.

How should I go about this?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Pete
  • 683
  • 1
  • 8
  • 17

1 Answers1

0

The creationComplete defined by you expects an event handler function.

To make some logic directly to the event use { } like in the following

creationComplete  = "{data=sqlSearch(data)}"

I strongly suggest to use a handler function so you can add more logic on creationComplete. For this take the following sample

<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
    xmlns:s="library://ns.adobe.com/flex/spark" title="data"
    xmlns:model="model.*"
    creationComplete="handleCreationComplete()"
    >

<mx:Script>
    <![CDATA[

    private function handleCreationComplete():void
    {
         //Here is my code
         data=sqlSearch(data);
    }


]]></mx:Script>
Adrian Pirvulescu
  • 4,308
  • 3
  • 30
  • 47
  • 1./ I don't see how the curly braces (`{}`) are relevant here: AFAIK they're ignored in an event handler since there is no data binding going on. 2./ Although I agree with you on the principle, this code will probably still throw the same error, only on a different line. – RIAstar May 07 '12 at 12:41
  • Thanks for the suggestions. I've implemented the curly braces for quick implementation and the error as cleared itself. Hooray. Unfortunately, I now have a entirely different error. Not wanting to diverge entirely, would you have any ideas on changing the data object from pushview, into a String? Anyways, Thanks. – Pete May 07 '12 at 12:55
  • @RIAstar the braces will let the "flex" know there is an expression to be evaluated in there. So it makes a whole difference. Ex text="1+1" is not the same as text="{1+1}" in the case of a mx:Label. Please give it a try. Pat Happy I could help. What;s the next error now ? – Adrian Pirvulescu May 07 '12 at 13:04
  • http://stackoverflow.com/questions/10483027/flex-pushview-data-object-being-converted-into-a-string i've posted a new question relating to my new problems. Thanks again. – Pete May 07 '12 at 13:35
  • @AdrianPirvulescu `text` is a _property_ of the `Label` class and its value can be bound through `{}`. `creationComplete` is an _event handler_ and it doesn't need curly braces to execute the code. – RIAstar May 07 '12 at 13:40
  • {} it's not used just for binding. As a result is solves current problem. Anyway.. you are right, text is a property not an event! – Adrian Pirvulescu May 07 '12 at 13:56
  • @AdrianPirvulescu I do not understand this 'feature' and I cannot find any documentation on it (I'm talking about curly braces in an event handler, not data binding). Could you point me to some docs? Also, I tried setting up a [simple test](http://pastebin.com/JckcJCXh) that recreates the error in this question: with or without curly braces, the error is there (as I expected). So why did it work in Pat's case? – RIAstar May 07 '12 at 15:26