jeudi 23 février 2017

AC3 display data attextfiled from array of numbers

I'm new at actionScript and I've a problem with my code, will I'm trying to build a simple app which allow the users to enter a data number and these data will be stored in array , after that the data could be display on a bar chat but for now my problem is that I want to display these data on specific positions in textinput filed on stage I tried several methods but I failed. please here is the code and any advice will be appreciated.

    package
{
    import feathers.controls.Button;
    import feathers.controls.Header;
    import feathers.controls.Screen;
    import feathers.controls.TextInput;

    import starling.display.Image;
    import starling.events.Event;
    import starling.textures.Texture;
    import starling.utils.Color;


   public class MainScreen extends Screen
   {

       [Embed(source="assets/axis1.png")]
       private static var BG:Class;
       public static var BGTexture:Texture;

       [Embed(source="assets/Line.png")]
       private static var BG1:Class;
       public static var BG1Texture:Texture;


      private var EnterButton:Button;
      private var TextF:TextInput;

      private var DataArray:Array
      private var num:Number;
      private var ChartButton:Button;
      private var Ax:Image;

      private var l1:TextInput;
      private var l2:TextInput;
      private var l3:TextInput;
      private var l4:TextInput;
      private var l5:TextInput;

      private var Jheader:Header;
      private var Fheader:Header;
      private var Mheader:Header;
      private var Aheader:Header;
      private var Maheader:Header;

    private var max:Number;
    private var min:Number;
    private var len:Number;
    private var check:Number;

    public function MainScreen()
    {

    }

    override protected function draw():void
    {

        TextF.width =  100;
        TextF.height = 50;
        TextF.y = 500;
        TextF.x = 5;


        EnterButton.width = 60;
        EnterButton.height = 50;
        EnterButton.y = TextF.y ;
        EnterButton.x =120;


        ChartButton.width = 60;
        ChartButton.height = 50;
        ChartButton.y = EnterButton.y;
        ChartButton.x =200;

        l1.width = 30;
        l1.height = 20;
        l1.y=340;
        l1.x=15;

        l2.width = 30;
        l2.height = 20;
        l2.y=280;
        l2.x=15;

        l3.width = 30;
        l3.height = 20;
        l3.y=215;
        l3.x = 15;

        l4.width = 30;
        l4.height = 20;
        l4.y=155;
        l4.x = 15;


        l5.width = 30;
        l5.height = 20;
        l5.y=90;
        l5.x=15;


        Jheader.x = 90;
        Jheader.y=400;

        Fheader.x = 155;
        Fheader.y=400;

        Mheader.x = 215;
        Mheader.y=400;

        Aheader.x = 275;
        Aheader.y=400;

        Maheader.x = 335;
        Maheader.y=400;



    }

    override protected function initialize():void
    {
        DataArray = new Array();

        TextF = new TextInput();
        TextF.prompt = "Enter Data"


        EnterButton = new Button ();
        EnterButton.label = "Add";

        ChartButton = new Button();
        ChartButton.label = "Chart";


        l1 = new TextInput();

        l2 = new TextInput();
        l3 = new TextInput();
        l4 = new TextInput();
        l5 = new TextInput();



    //l1.isEditable = false;


        Jheader = new Header();
        Fheader = new Header();
        Mheader = new Header();
        Aheader = new Header();
        Maheader = new Header();


        Jheader.title = "Jan";
        Fheader.title = "Feb";
        Mheader.title = "Mar";
        Aheader.title = "Apr";
        Maheader.title = "May";


        addChild(TextF);
        addChild(EnterButton);
        addChild(ChartButton);





        EnterButton.addEventListener(Event.TRIGGERED,OnClick);
        ChartButton.addEventListener(Event.TRIGGERED,OnChart);

    }

    private function OnChart():void
    {
        BGTexture = Texture.fromBitmap(new BG());
        Ax = new Image(BGTexture);
        Ax.color = Color.TEAL;
        Ax.x=40;
        Ax.y = 40;
        addChild(Ax);

        addChild(l1);
        addChild(l2);
        addChild(l3);
        addChild(l4);
        addChild(l5);



        addChild(Jheader);
        addChild(Fheader);
        addChild(Mheader);
        addChild(Aheader);
        addChild(Maheader);



        trace("chart");

    }

    private function OnClick():void
    {
        num = new Number(TextF.text);
        DataArray.push(num);
        trace(DataArray);

        len = DataArray.length;
        min = Number.MAX_VALUE;
        max = Number.MIN_VALUE;

        for (var i:int = 0;i<len;i++)
        {
            check = DataArray[i];

            if (check < min)
            {
                min = check;
            }
            if(check > max)
            {
                max = check;
            }

        }

        trace("minimum value= ",  min);
        trace("maximum value=" , max);


      } 


  }

}

Aucun commentaire:

Enregistrer un commentaire