What is the deal with application.parameters?

I send a userId to my application to display a linechart with the application.parameter object. I get the userId parameter inside my application and can trace or alert it and I see the userId on my screen. Ok everything is working fine for now. Then I want to use the userId to call php function. And there is where it breaks. Somehow the userId parameter is empty.

example:

?View Code ACTIONSCRIPT
                       private var userId:int = 1234;
 
			private function init():void{
				this.userId = Application.application.parameters.userId;
			}

for this example I set a default value of 1234 and on creationComplete the userId is set with the real userId value, lets say that the userId in parameters is 1. If I trace the userId inside the application after the init() it returns 1. That is normal. But if I now call the remoteObject:

	<mx:RemoteObject endpoint="test/test.php" 
	    id="phpCall"
	    source="myFunction"
	    destination="amfphp"
	    showBusyCursor="true">
	   	<mx:method name="getUser" fault="onFaultResult(event)" result="onResult(event)">
	    	<mx:arguments><userId>{this.userId}</userId>
	    </mx:method>
	</mx:RemoteObject>

With this call the php function receives a userId with 1234. Very strange because we already set that with an other number.

solution for me
I tried a lot of different ways to fix this problem and now I finally found a solution. I set the value of the userId parameter inside a invisible label. And use that label to send the userId back to php.

?View Code ACTIONSCRIPT3
this.userIdLabel.text =(this.userId).toString();

and in the remoteObject:

	<mx:RemoteObject endpoint="test/test.php" 
	    id="phpCall"
	    source="myFunction"
	    destination="amfphp"
	    showBusyCursor="true">
	   	<mx:method name="getUser" fault="onFaultResult(event)" result="onResult(event)">
	    	<mx:arguments><userId>{int(this.userIdLabel.text)}</userId>
	    </mx:method>
	</mx:RemoteObject>

Author Bio

8 Comments

  1. Tom Chiverton - August 11, 2009

    What happens if you make the private variable a string, not an int ?

  2. Arno Manders - August 11, 2009

    I keep the same problem. Inside the application everything is going well but when I send it to php he sends nothing.

  3. Pete - August 11, 2009

    I’m not familiar with amfphp, but as you’re setting userId from parameters try casting it as an int there and then, as all flashvars are stored in the parameters obejct as String.

  4. mloncaric - August 11, 2009

    Did you declare userId variable as Bindable?

    • Arno Manders - August 11, 2009

      @mloncaric: wow amazing that this is really working. I have to admit that I thought your solution was ridiculous. But then I realized it could work but that also means that the userId argument is set on application start and is not a reference to the variable.

      what is very strange because in the same method I have the selectedItem of a comboBox as argument and that is working correct. Why is that working correct?

  5. Arno Manders - August 11, 2009

    @Pete: well in my example i’m not doing that because it doesn’t care but in my code I’m doing it: this.userId = int(Application.application.parameters.userId);.

  6. Zjéraar - August 24, 2009

    Sheesh, Arno, didn’t you know that? It’s, like, beginners stuff. 😉

  7. mloncaric - September 16, 2009

    ComboBox#selectedItem is also Bindable so thats why 🙂
    Sorry for being so late..

Leave a reply