9 Replies Latest reply on Mar 27, 2012 2:07 PM by EvyatarBH

    Help with code!!

    fsoender Level 1

      Hi,

       

      Im trying to make a real time temp chart. Finally this chart will display real time temperature from a sensor thru WI-FI.

      But I need some help, I got this code shown under, I have trouble with the "TempValue" and "Temp" variable.

      I want to be able to change the "Temp" with any value, and the chart will display the plot in the chart accordingly.

       

       

       

      <?xml version="1.0"?>

      <!-- charts/RealTimeArrayCollection.mxml -->

      <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"

             initialize="initTimer()"

             height="600">

            

             <fx:Script><![CDATA[

                    import flash.utils.Timer;

                    import flash.events.TimerEvent;

                    import mx.collections.ArrayCollection;

                   

                    [Bindable]

                    public var TempValue:ArrayCollection = new ArrayCollection();

                   

                    public function initTimer():void {

                          

                          

                           var myTimer:Timer = new Timer(10, 0);

                          

                          

                           myTimer.addEventListener("timer", timerHandler);

                           myTimer.start();

                    }

                   

                    public function timerHandler(event:TimerEvent):void {

                           var o:Object = new Object();

                          

                           Temp = 100

                          

                           o.time = getTimer();             

                          

                           TempValue = Temp;

                          

                           trace(o.time + ":" + TempValue);

                          

                          

                           TempValue.addItem(o);

                    }

             ]]></fx:Script>

            

             <s:layout>

                    <s:VerticalLayout/>

             </s:layout>

            

             <s:Panel title="Temperature">

                    <s:layout>

                           <s:VerticalLayout/>

                    </s:layout>

                    <mx:LineChart id="chart"

                                          dataProvider="{TempValue}"

                                          showDataTips="true">

                           <mx:horizontalAxis>

                                 <mx:LinearAxis/>

                           </mx:horizontalAxis>

                           <mx:verticalAxis>

                                 <mx:LinearAxis minimum="5000000"/>

                           </mx:verticalAxis>

                           <mx:series>

                                 <mx:LineSeries yField="Temp"/>

                           </mx:series>

                    </mx:LineChart>

             </s:Panel>

      </s:Application>

        • 1. Re: Help with code!!
          nikos101 Level 2

          try refreshing the arraycollection

          • 2. Re: Help with code!!
            fsoender Level 1

            I got it fixed by myself, but now I get an error when running under iOS. Anyone know why?

             

            Get this ERROR:

             

            TypeError: Error #1034: Type Coercion failed: cannot convert views::TrackingView@837f0a1 to spark.components.View.

                            at spark.components::ViewNavigator/createViewInstance()[E:\dev\4.y\frameworks\projects\mobil ecomponents\src\spark\components\ViewNavigator.as:1999]

                            at spark.components::ViewNavigator/http://www.adobe.com/2006/flex/mx/internal::createTopView()[E:\dev\4.y\frameworks\projects\mobilecomponents\src\spark\components\ViewNavigator.as:1 981]

                            at spark.components::ViewNavigator/http://www.adobe.com/2006/flex/mx/internal::setActive()[E:\dev\4.y\frameworks\projects\mobilecomponents\src\spark\components\ViewNavigator.as:4 24]

                            at spark.components::TabbedViewNavigator/commitProperties()[E:\dev\4.y\frameworks\projects\m obilecomponents\src\spark\components\TabbedViewNavigator.as:741]

                            at mx.core::UIComponent/validateProperties()[E:\dev\4.y\frameworks\projects\framework\src\mx \core\UIComponent.as:8219]

                            at mx.managers::LayoutManager/validateProperties()[E:\dev\4.y\frameworks\projects\framework\ src\mx\managers\LayoutManager.as:597]

                            at mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\4.y\frameworks\projects\framewo rk\src\mx\managers\LayoutManager.as:813]

                            at mx.managers::LayoutManager/doPhasedInstantiationCallback()[E:\dev\4.y\frameworks\projects \framework\src\mx\managers\LayoutManager.as:1180]

             

             

            Code:

             

            <?xml version="1.0"?>     

            <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"

                   initialize="initTimer()">

             

                                 <fx:Script>

                                             

                                       import flash.utils.Timer;

                                       import flash.events.TimerEvent;

                                       import mx.collections.ArrayCollection;

                                      

                                       [Bindable]

                                       public var myArray:ArrayCollection = new ArrayCollection();

                                       public function initTimer():void {

                                       var myTimer:Timer = new Timer(1000, 0);

                                       myTimer.addEventListener("timer", timerHandler);

                                       myTimer.start();

                                       }

                                      

                                       public function timerHandler(event:TimerEvent):void {

                                       var obj:Object = new Object();

                                       obj.time = getTimer();

                                       obj.Value = 60;

                                       myArray.addItem(obj);

                                      

                                       }

                                 </fx:Script>

                                

                                

                                 <mx:LineChart id="chart" dataProvider="{myArray}" showDataTips="true">

                                       <mx:horizontalAxis>

                                              <mx:LinearAxis/>

                                       </mx:horizontalAxis>

                                       <mx:verticalAxis>

                                              <mx:LinearAxis minimum="35"/>

                                       </mx:verticalAxis>

                                       <mx:series>

                                              <mx:LineSeries yField="Value"/>

                                       </mx:series>

                                 </mx:LineChart>                  

                          </s:Application>

             

             

             

             

             

            • 3. Re: Help with code!!
              EvyatarBH Level 3

              My guess is that you have a class named TrackingView that should have extended View somehow, but it doesn't.

              You get a pretty clear casting error there and the code you included seems irrelevant to the error.

              • 4. Re: Help with code!!
                fsoender Level 1

                I'm making a two tablet iOS app.

                The error accure on one of the tablet windows.

                I'm wondering if that is the fault?

                • 5. Re: Help with code!!
                  EvyatarBH Level 3

                  It seems like you are using a framework component called ViewNavigator, which is used to display components that extends a framework component called View, but YOUR TrackingView component DOES NOT extend the View component.

                   

                  At least that's my guess...

                  • 6. Re: Help with code!!
                    fsoender Level 1

                    Hi EvyatarBH,

                     

                    It works if I run the code under "Project" but not when I want to use the code under a different view like "View1" or "View2", any suggestions why?

                    Flex.jpg

                    • 7. Re: Help with code!!
                      EvyatarBH Level 3

                      The error is specifically about TrackingView, so I don't understand how View1 & View2 are relevant and what code are you referring to.

                      In addition, note that you have in the stack trace the line numbers leading to the error and all the framework's source code.

                       

                      You just need to better understand what you are doing and debug properly...

                       

                      Good luck!

                      • 8. Re: Help with code!!
                        fsoender Level 1

                        The program works in a one slide app, but not if I want to have a two slide app, why is that?

                        • 9. Re: Help with code!!
                          EvyatarBH Level 3

                          I'm not familiar with the specific components you are using, so I can't really help you, but I'm generalizing the issue to the properly debugging your own code, which is what you should do.

                          (Alternatively, you should post additional relevant code and error messages)