I am kind of new to AS3 and programming itself.
I have this issue. I want to be able to use the Pl_array and En_array outside of AfterLoad function, but I always get undefined value. I am writing the code inside the timeline not .as file. Does it matter?
I was trying to return them from function but since it's related to listener i just dont know how to do it also i was trying to make them public.
Here is code on first frame:
import flash.events.MouseEvent;
stop();
Btn_start.addEventListener(MouseEvent.CLICK, onStartClick);
function onStartClick(me:MouseEvent):void{
gotoAndStop("Dictionary");
}
and here is on the second called Dictionary:
import flash.events.Event;
import flash.utils.Timer;
import flash.events.MouseEvent;
stop();
var myTextLoader:URLLoader = new URLLoader();
var Txt_array:Array=new Array(); //tablica wczytanych zwrotów
var Pl_array:Array=new Array();
var En_array:Array=new Array();
var myTimer:Timer = new Timer(1000);
myTextLoader.addEventListener(Event.COMPLETE, onLoaded); //listener na koniec wczytywania pliku tekstowego
function onLoaded(e:Event):void { //funkcja wywoływana przez listener na koniec wczytywania pliku
Txt_array = e.target.data.split(/\n/); //
dispatchEvent(new Event("Load_END"));
}
myTextLoader.load(new URLRequest("Zwroty.txt"));
this.addEventListener("Load_END", AfterLoad); //kod wykonywano po wczytaniu pliku tekstowego
function AfterLoad(e:Event):void{
for each (var s:String in Txt_array){// pętla która rozdziela tekst na polski i angielski
var i:int=0;
En_array[i]=s.substr(0, s.indexOf("-")-1);
Pl_array[i]=s.substr(s.indexOf("-")+2, s.length);
i++;
} //koniec fora
}//koniec funkcji
Begin.addEventListener(MouseEvent.CLICK, test);
function test(e:Event):void{
trace(En_array[1]);
}
//funkcja wyświetlająca string w txt_load
function ShowString (txt_show:String):void{
load_txt.text = txt_show;
}
function ShowOpinion(txt_opinion:String):void{
opinion_txt.text=txt_opinion;
}
function HideOpinion():void{
opinion_txt.text=" ";
}
//funkcja porównująca łańcuchy
function Compare(txt_a:String,txt_b:String):Boolean{
if (txt_a==txt_b){
return true;
}
return false;
}
//up_btn.useHandCursor=true;
//up_btn.addEventListener(MouseEvent.MOUSE_OVER, switch_bg);
//function switch_bg(me:MouseEvent):void{
//var newColor:ColorTransform = me.target.transform.colorTransform;
//newColor.color = 0x1000C6;
//me.target.transform.colorTransform = newColor;
//}
on test function i always get undefined while tracing. I was trying to find solution in Google but couldn't.