1
votes

I am developing a mobile project in Flash builder using flex 4.5. I am very new to flex, with some background in Obj-C.

Current Setup:

I am passing the text property of a text input component to a second view via navigator.pushview{view.Someview, data}

public function doSomething():void{
            navigator.pushView(Session_View, timeInput.text);
        }

This successfully passes the text I put into the textinput to the Session_View instance and I can display that text in a label in the mxml; however, I would like to take the text passed and convert it to an integer to use in my logic.

Within Action Script I have tried parseInt() function with no luck. I have also tried to assign data to a variable in actionscript with no luck.

Does any flex ninja out there know what I am doing wrong or a best practices way to pass a simple string between views in flex mobile and then convert that string to an int?

Thanks

1

1 Answers

1
votes

Both parseInt and casting to Number should work.

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

            [Bindable]
            public var intA:int;
            [Bindable]
            public var intB:int;

            protected function application1_creationCompleteHandler(event:FlexEvent):void
            {
                var s:String = "55";
                intA = parseInt(s);
                intB = Number(s);

            }

        ]]>
    </fx:Script>
    <s:VGroup>
        <s:Label text="{intA}" />
        <s:Label text="{intB}" />
        <s:Label text="{intA+intB}" />
    </s:VGroup>
</s:Application>

Edit: Override set data.

In the view that you are pushing you should be able to get at the variable from the data object.

var someInteger:int = data.integerProperty;

If you need to do something with that property every time data is pushed into the view, and not just the first time you should override the set data method.

public override function set data(value:Object):void{
    super.data = value;
    var someInteger:int = data.integerProperty;
}