5 Replies Latest reply on Jun 3, 2009 10:59 AM by aprildavid

    how to create a Image object from action script

    aprildavid Level 1

      I need to set the back ground of charting dynamically, thus I need to create Image from a png/gif files. I have wrritten following code, but doesn't work.

      public function addBackground():void
      {
          var cbg:ChartBackground=new ChartBackground();
          var bgs:Array=new Array();
          bgs.push(cbg);
          lineChart.backgroundElements=bgs;     
      }

       

      package arubaUI
      {
          import mx.controls.Image;
         
          [Embed(source="../assets/chart_16.png")]   
          public class ChartBackground extends Image
          {   
          }
      }

       

       

      Does any one knows how to do that?

      Thanks!

        • 1. Re: how to create a Image object from action script
          Michael Borbor Level 4

          You don't need all that you just could've done something like this

           

                      [Embed(source="assets/logo.png")]

                     

                      public var Logo:Class;

          • 2. Re: how to create a Image object from action script
            aprildavid Level 1

            Could you give me an example in action script how can I add that?

             

            Thanks!

            • 3. Re: how to create a Image object from action script
              Michael Borbor Level 4

              The example I posted was an AS3 example. What else do you need?

              • 4. Re: how to create a Image object from action script
                aprildavid Level 1

                I put the code like and got compile error:

                public class ArubaLinePanel extends Panel
                {
                  private var lineChart:LineChart;
                  private var lineData:ArrayCollection=new ArrayCollection( [
                            { Month: "Jan", Profit: 2000, Expenses: 1500, Amount: 450 },
                            { Month: "Feb", Profit: 1000, Expenses: 200, Amount: 600 },
                            { Month: "Mar", Profit: 1500, Expenses: 500, Amount: 300 },
                            { Month: "Apr", Profit: 1800, Expenses: 1200, Amount: 900 },
                            { Month: "May", Profit: 2400, Expenses: 575, Amount: 500 } ]);

                 


                  public function ArubaLinePanel()
                {
                        super();           
                        lineChart=new LineChart();
                        lineChart.dataProvider=lineData;
                        lineChart.showDataTips=true;
                        var axisX:CategoryAxis=new CategoryAxis()
                        axisX.categoryField="Month";
                        lineChart.horizontalAxis=axisX;
                       
                        var seriesArray:Array = new Array();
                        var ls:LineSeries=new LineSeries();
                        ls.yField="Profit";
                        ls.displayName="Profit";
                        seriesArray.push(ls);
                       
                        lineChart.series=seriesArray;
                        this.addChild(lineChart);
                        var legend:Legend=new Legend();
                        legend.dataProvider=lineChart;
                        this.addChild(legend);       
                        addBackground();


                public function addBackground():void
                {
                    var cbg:ChartBackground=new ChartBackground();
                    var bgs:Array=new Array();
                    bgs.push(cbg);
                    lineChart.backgroundElements=bgs;     
                }

                 
                 
                }
                }

                 

                 

                 

                 

                Another method I tried:

                package arubaUI
                {
                    import mx.controls.Image;
                   
                    [Embed(source="../assets/chart_16.png")]   
                    public class ChartBackground extends Image
                    {   
                    }
                }

                There is no compile error, but image is not show on screen,

                 

                Thanks!

                 

                April

                • 5. Re: how to create a Image object from action script
                  aprildavid Level 1

                  Sorry missed some in the post. I put the code in front of declearation of class.

                  package arubaUI
                  {
                      import mx.charts.CategoryAxis;
                      import mx.charts.Legend;
                      import mx.charts.LineChart;
                      import mx.charts.series.LineSeries;
                      import mx.collections.ArrayCollection;
                      import mx.containers.Panel;
                  [Embed(source="assets/logo.png")]
                  Bindable
                  public var Logo:Class;

                   


                         
                  public class ArubaLinePanel extends Panel
                  {
                    private var lineChart:LineChart;
                    private var lineData:ArrayCollection=new ArrayCollection( [
                              { Month: "Jan", Profit: 2000, Expenses: 1500, Amount: 450 },
                              { Month: "Feb", Profit: 1000, Expenses: 200, Amount: 600 },
                              { Month: "Mar", Profit: 1500, Expenses: 500, Amount: 300 },
                              { Month: "Apr", Profit: 1800, Expenses: 1200, Amount: 900 },
                              { Month: "May", Profit: 2400, Expenses: 575, Amount: 500 } ]);

                   


                    public function ArubaLinePanel()
                  {
                          super();           
                          lineChart=new LineChart();
                          lineChart.dataProvider=lineData;
                          lineChart.showDataTips=true;
                          var axisX:CategoryAxis=new CategoryAxis()
                          axisX.categoryField="Month";
                          lineChart.horizontalAxis=axisX;
                         
                          var seriesArray:Array = new Array();
                          var ls:LineSeries=new LineSeries();
                          ls.yField="Profit";
                          ls.displayName="Profit";
                          seriesArray.push(ls);
                         
                          lineChart.series=seriesArray;
                          this.addChild(lineChart);
                          var legend:Legend=new Legend();
                          legend.dataProvider=lineChart;
                          this.addChild(legend);       
                          addBackground();


                  public function addBackground():void
                  {
                      var cbg:ChartBackground=new ChartBackground();
                      var bgs:Array=new Array();
                      bgs.push(cbg);
                      lineChart.backgroundElements=bgs;     
                  }

                   
                   
                  }
                  }