-1

i have this code on my main swf :

var btnLingua : Array = new Array(ITA,DE,LAT,EL);
var lingua:String = "ITA";

for(var i:int=0;i<btnLingua.length;i++){
    btnLingua[i].addEventListener(MouseEvent.CLICK,settaLingua);
}

function settaLingua(event:MouseEvent){
    trace("la lingua selezionata è : " + event.target.name);
    lingua=event.target.name;
    caricamento("scenaProva.swf");
}


var fl_Loader:Loader;

function caricamento(myURL:String):void {
    if(fl_Loader != null){
        contenitore.removeChild(fl_Loader);
        fl_Loader.unloadAndStop();
        fl_Loader = null;
    }
    fl_Loader = new Loader();
    fl_Loader.load(new URLRequest(myURL));
    fl_Loader.contentLoaderInfo.addEventListener(Event.COMPLETE, caricamentoCompleto);
}

function caricamentoCompleto(e:Event):void {
    contenitore.addChild(fl_Loader);
    fl_Loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, caricamentoCompleto);
}

and this on the movieClip :

trace("numero di elementi nella pagina : "+numChildren);
trace(MovieClip(root).lingua);
var lingua : String = MovieClip(root).lingua;

for(var i:int = 0; i<numChildren; i++)
{
    var e:Object = getChildAt(i);

    if(e.name.indexOf("$"+lingua) >= 0){
        e.visible = true;
        trace(e.name + " contiene il carattere di linguaggio");
    }
    else if(e.name.indexOf("$")  >= 0){
        e.visible = false;
    }

}

when i try to get the variable lingua from my root movieclip i recive "UNDEFINED" please can someone help me? i'm trying by 2 days... sorry for bad english, i'm italian

Alessandro Zago
  • 793
  • 3
  • 12
  • 33
  • When you say "on the movieclip" where exactly is that code? Which movie clip? Presumably the one you're loading in. Most likely you're running into a security context issue. – BadFeelingAboutThis Dec 04 '15 at 22:05
  • i need to get the variable lingua in the second movieclip. the second movieclip is instanced by the first – Alessandro Zago Dec 04 '15 at 22:23
  • @AlessandroZago You question is unclear. Try to give all details that can help other to understand the problem to get an answer. Explain what you are trying to do ... – akmozo Dec 04 '15 at 23:00

2 Answers2

0

You don't have a variable lingua in your main timeline, you have btnLingua and ling.

0

I dont think in your Child SWF you can use the line:
var lingua : String = MovieClip(root).lingua;
because that code will run before even the Child SWF has been added to the stage (Flash must do the first code to know what to show you).

So try something like...

var lingua : String = "";

addEventListener(Event.ADDED_TO_STAGE, onReady);

function onReady (evt : Event) : void
{
    trace("numero di elementi nella pagina : " + numChildren);
    //trace(MovieClip(root).lingua);

    lingua = this.parent.parent.lingua; //update string

    for(var i:int = 0; i<numChildren; i++)
    {
        var e:Object = getChildAt(i);

        if(e.name.indexOf("$"+lingua) >= 0)
        {
            e.visible = true;
            trace(e.name + " contiene il carattere di linguaggio");
        }
        else if(e.name.indexOf("$")  >= 0)
        { e.visible = false; }

    }
}
VC.One
  • 14,790
  • 4
  • 25
  • 57
  • PS: The above code is untested since I'm not on Flash right now but you can try it. Comment if you still need help with it. – VC.One Dec 06 '15 at 15:15
  • the string lingua is undefined – Alessandro Zago Dec 07 '15 at 01:05
  • I see you have another **[Question](http://stackoverflow.com/q/34125195/2057709)** here. So is this problem fixed now or you still need solution for string lingua? – VC.One Dec 07 '15 at 06:15