7 Replies Latest reply on Nov 6, 2009 5:11 AM by erthy

    Problem with text field .text atribute.

    erthy Level 1

      Hey,

       

      I had a mx:Text element and I put it onto a canvas for a tabbing system and now, my notation element.text="bla bla bla"; doesn't work. What am I doing wrong?

      Code below.

       

      <?xml version="1.0" encoding="utf-8"?>

      <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="otevritSlovnik()" width="1000" backgroundGradientAlphas="[1.0, 0.0]" backgroundGradientColors="[#FFFFFF, #6F8DFF]" height="360">

      <mx:Script>

           <![CDATA[

                import mx.controls.Text;

                import flash.filesystem.*;

                import mx.controls.Alert;

                import mx.controls.List;

                     

                     // public var slovnikFile:File;

                     public var slovnikFile:File = File.applicationDirectory.resolvePath("slovnik.xml"); // The preferences prefsFile

                     [Bindable] public var slovnikXML:XML; // The XML data

                     [Bindable] public var addXML:XML;               

                     

                     private var pocet_slovicek:int;

                     private var maximum:int;

                     private var cislo_slovicka:int;

                     private var slovicko_1:String;

                     private var slovicko_2:String;

                     private var zkousim_z:int;

                     private var pocet_vyzkousenych:int;

                     private var vyzkousene:Array = new Array;

                     private var vysledky_do_streamu:String = "pes";

                     private var zkousi_se:Boolean;

                     public var stream:FileStream; // The FileStream object used to read and write prefsFile data.

                

                private function otevritSlovnik():void

                {

                     stream = new FileStream();

                     if (slovnikFile.exists) {

                         stream.open(slovnikFile, FileMode.READ);

                         slovnikXML = XML(stream.readUTFBytes(stream.bytesAvailable));

                          stream.close();

                          vytahnout_udaje();

                     }

                     else

                     {

                         Alert.show("Nenalezeny žádné slovníky!");

                     }

                }

                

                private function vytahnout_udaje():void{

                     var jmeno_slovniku:String = slovnikXML.info.jmeno;

                     var verze_slovniku:String = slovnikXML.info.verze;

                     var autor_slovniku:String = slovnikXML.info.autor;

                     var jazyk1_slovniku:String = slovnikXML.info.jazyky.@lang1;

                     var jazyk2_slovniku:String = slovnikXML.info.jazyky.@lang2;

                     var web_slovniku:String = slovnikXML.info.web;

                     var poznamka_slovniku:String = slovnikXML.info.poznamka;

                     var udaje_o_slovniku:String = "Jméno slovníku: " +jmeno_slovniku+

                                                          "\nVerze: "+verze_slovniku+

                                                          "\nAutor: "+autor_slovniku+

                                                          "\nWeb: "+web_slovniku+

                                                          "\nJazyk1: "+jazyk1_slovniku+

                                                          "\nJazyk2: "+jazyk2_slovniku+

                                                          "\nPoznámka autora: "+poznamka_slovniku

                                                          ;

                     info_o_slovniku.text=udaje_o_slovniku;

                }

                public function ask (slid:int, lang:String):String {

                     if (slovnikXML) {

                          var slovicko:String = slovnikXML.slovicka.slovicko[slid].@[lang];

                          return slovicko;

                     }

                     else {

                          var chyba:String = "ff";

                          return chyba;

                     }

                }

                

                public function dalsi_slovicko():void {

                     if (pocet_vyzkousenych == 0 || pocet_vyzkousenych < zkousim_z){

                          cislo_slovicka = randomNumber(0, maximum);

                          

                          if (vyzkousene.indexOf(cislo_slovicka)==-1) {

                               

                               slovicko_1 = ask(cislo_slovicka, "en");

                               slovicko_2 = ask(cislo_slovicka, "cs");

                               slovicko1.text = slovicko_1;

                               nazor.text ="";

                               pocet_vyzkousenych++;

                          

                          }

                          else {

                               dalsi_slovicko();

                          }

                     }

                     else {

                          Alert.show("Vyzkoušení proběhlo úspěšně! \n"+"Počet vyzkoušených slovíček: "+pocet_vyzkousenych+"\nZkoušelo se z: "+zkousim_z);

                          last();

                     }

                }

                public function last():void {

                     slovicko1.text = "Great!";

                     nazor.text = "Výborně!";

                     odeslat.label="Zkoušej!";

                     zrusit.enabled=false;

                     slovicko1.enabled=true;

                     nazor.enabled=true;

                     nazor.editable=false;

                     zkousi_se=false;

                }

                public function zkousej():void {

                     zkousi_se=true;

                     odeslat.label="Odeslat!";

                     zrusit.enabled=true;

                     slovicko1.enabled=true;

                     nazor.enabled=true;

                     nazor.editable=true;

                     pocet_vyzkousenych = 0;

                     vyzkousene = new Array;

                     pocet_slovicek = slovnikXML.slovicka.elements("*").length();

                     maximum = pocet_slovicek-1;

                     zkousim_z = maximum+1;

                     

                     if (zkousim_z > maximum+1) {

                          Alert.show("Chcete se nechat vyzkoušet z více slovíček, než vybraný slovník obsahuje. E-e!");

                     }

                     else {

                          dalsi_slovicko();

                     }

                }

                

                public function kontrola() : void {

                          if (nazor.text == slovicko_2) {

                               vyzkousene.push(cislo_slovicka);

                                dalsi_slovicko()

                          }     

                          else {

                               Alert.show("Špatně!! \n\nSprávně jste měli napsat: " + slovicko_2);

                          }

                       }

                

                private function randomNumber(low:Number=NaN, high:Number=NaN):Number

                {

                     var low:Number = low;

                     var high:Number = high;

       

                     if(isNaN(low))

                      {

                         throw new Error("low must be defined");

                      }

                       if(isNaN(high))

                        {

                             throw new Error("high must be defined");

                       }

       

                       return Math.floor(Math.random() * (1+high-low)) + low;

                }

                

                private function odeslat_click(evt:MouseEvent):void {

                       if (zkousi_se==true) {

                               kontrola();

                          }

                          else {

                               zkousej();

                          }

                  }

       

                  private function zrusit_click(evt:MouseEvent):void {

       

                  }

                

           ]]>

      </mx:Script>

           <mx:ViewStack x="10" y="44" id="viewstack1" width="960" height="310">

                <mx:Canvas label="Zkoušení" width="100%" height="100%" id="zalozka_zkouseni" backgroundColor="#FFFFFF" color="#000000" borderColor="#919191">

                     <mx:Panel x="10" y="10" width="250" height="284" layout="absolute" title="Údaje o slovníku:" id="slovniky">

                          <mx:Text x="10" y="10" width="210" height="224" id="info_o_slovniku"/>

                     </mx:Panel>

                     

                     

                     <mx:Panel x="585" y="10" width="362" height="284" layout="absolute" id="panel_vysledky" title="Výsledky:">

                          <mx:List y="10" width="322" height="224" id="vysledky_stream" dataProvider="vysledky_do_streamu" enabled="true" x="10"></mx:List>

                     </mx:Panel>

                     <mx:Panel x="268" y="10" width="309" height="284" layout="absolute" id="main_alternate" title="Zkoušení:">

           <mx:Form id="main_form" x="10" y="10" width="269" height="224" defaultButton="{odeslat}">

              <mx:FormItem width="100%">

                  <mx:TextInput id="slovicko1"  width="100%"/>

              </mx:FormItem>

              <mx:FormItem width="100%">

                  <mx:TextInput id="nazor"  width="100%"/>

              </mx:FormItem>

              <mx:FormItem direction="horizontal"

                      horizontalAlign="center"

                      width="100%" height="47">

                  <mx:Button id="odeslat"

                          label="Zkoušet!"

                          click="odeslat_click(event);"  fontSize="25" textAlign="center" labelPlacement="top"/>

              </mx:FormItem>

              <mx:FormItem>

                   <mx:Spacer/>

              </mx:FormItem>

              <mx:FormItem direction="horizontal"

                      horizontalAlign="right"

                      width="226" height="26">

                  <mx:Button id="zrusit"

                          label="Reset"

                          click="zrusit_click(event);"  textAlign="center" labelPlacement="right"/>

              </mx:FormItem>

          </mx:Form>

                     </mx:Panel>

                </mx:Canvas>

                <mx:Canvas width="100%" height="100%" id="zalozka_about" label="O programu">

                     <mx:TextArea x="228" y="10" width="722" height="290" id="changelog" text="Slovíčka - Changelog&#xa;&#xa;0.0.3 - zvětšena tlačítka, přidán panel s údaji o slovníku a panel s logem (nefunkční)&#xa;0.0.2 - paměť na vyzkoušená slovíčka, vylepšení vzhledu&#xa;0.0.1 - základní funkce programu" textAlign="left" fontSize="15"/>

                </mx:Canvas>

           </mx:ViewStack>

           <mx:TabBar x="10" y="21" dataProvider="viewstack1" width="502" height="26">

           </mx:TabBar>

      </mx:WindowedApplication>