I have a home.fla file

``import flash.events.MouseEvent;
    import flash.display.StageDisplayState;
    import flash.display.MovieClip;

stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;

SearchBut.addEventListener(MouseEvent.CLICK, clickSearch);
TestBut.addEventListener(MouseEvent.CLICK, clickTest);
//DemoBut.addEventListener(MouseEvent.CLICK, clickDemo);
var MC:MovieClip;
MC=new MovieClip();
var myGlobal:Number = 100;
this.addChild(MC);
var flag:Boolean;
flag=false;
//this.addEventListener(Event.ADDED,onFileAdded);
//
//function onFileAdded() {
//
//}

MC.addEventListener(Event.ADDED,MCAdded);
this.addEventListener(Event.ADDED,onFileAdded1);

function MCAdded(e:Event):void {

    var f:Boolean;
    f=true;

}

function onFileAdded1(e:Event):void {

    flag=true;
    trace("flag ");
    trace(flag);

    trace("This");
    trace(this);

    trace("This currentFrame");
    trace(this.currentFrame);

}
function clickSearch(e:MouseEvent):void {
    //var request:URLRequest = new URLRequest("Untitled21.swf");
 var request:URLRequest = new URLRequest("Search.swf");
 var loader:Loader = new Loader()
 loader.load(request);
 addChild(loader);

}
function clickTest(e:MouseEvent):void {

    trace("In Test");
    var request1:URLRequest = new URLRequest("test11.swf");
 var loader1:Loader = new Loader()
 loader1.load(request1);
 addChild(loader1);

}

var acArray:Array; 
var myXML:XML;
var leng:Number;
var myLoader:URLLoader = new URLLoader();
var len:Number;
var n:Number;
var tempArray:Array;
var wordBank:Array = [];
var display;

and another test11.fla

import flash.net.LocalConnection;
//import flash.filesystem.File;
//import flash.filesystem.FileStream;
//import flash.filesystem.FileMode;
import flash.events.MouseEvent;
import flash.events.KeyboardEvent;
import flash.events.*;
var global:MovieClip = MovieClip(root);
var fileName:String;
var myTextLoader:URLLoader = new URLLoader();
var conn:LocalConnection;
 var searchFlag:Boolean;
 searchFlag=false;

var homeFlag:Boolean;   
homeFlag=false;

//trace(File.applicationStorageDirectory.nativePath);

this.addEventListener(Event.ADDED,onFileAdded);

this.addEventListener(Event.COMPLETE,onFileAdded1);

function onFileAdded(e:Event):void {

    trace("Movie clip root");

    trace(MovieClip(root).flag);

    trace("Movie clip MC");
     trace(global.myGlobal);
    //trace(MovieClip(MC).flag);

}
function onFileAdded1(e:Event):void {

    trace("Movie clip root");

    trace(MovieClip(root).flag);
}

//conn = new LocalConnection();
//conn.client = this;
//conn.allowDomain("*");
//Security.allowDomain("*");
BackBut.addEventListener(MouseEvent.CLICK, backButListener );
//conn.connect('SearchConnection');

//public var value:String = "This is the Test";
myTextLoader.addEventListener(Event.COMPLETE, onLoaded);
//fileName = File.applicationStorageDirectory.nativePath+"\\"+"myText.txt";

//myTextLoader.load(new URLRequest("File.applicationStorageDirectory.nativePathmyText.txt"));
//myTextLoader.load(new URLRequest(fileName));

function onLoaded(e:Event):void {
    var myArrayOfLines:Array = e.target.data.split(" ");

    for (var i = 0; i<myArrayOfLines.length; i++) {

            var tempWord:String = myArrayOfLines[i];

            if (Boolean(tempWord == "Search")) {

                searchFlag=true;
            } else
            if (Boolean(tempWord == "home")) {
                homeFlag =true;
            }
        }

}

function searchMethod():void
{
SearchBut.visible= true;
Label1.text="Search";

}

function backButListener(e:MouseEvent):void { 

if(searchFlag==true) 
{
    var request:URLRequest = new URLRequest("Search.swf");
    var loader:Loader = new Loader()
    loader.x=0;
    loader.y=0;
    loader.load(request);
    addChild(loader);
}
else

if(homeFlag==true) 
{
    var request1:URLRequest = new URLRequest("home.swf");
    var loader1:Loader = new Loader()
    loader1.x=0;
    loader1.y=0;
    loader1.load(request1);
    addChild(loader1);
}

}

function searchListener(e:MouseEvent):void {
//var request:URLRequest = new URLRequest("Untitled21.swf");
// var loader:Loader = new Loader()
// loader.x=0;
// loader.y=0;
// loader.load(request);
// addChild(loader);
}

I want to access "myGlobal" from test11.fla

Dani AI

Generated

— the issue is not a compiler bug but scope and timing. The myGlobal you set on the home timeline lives on the loader's document, while root inside the loaded SWF is the loaded SWF's own root. Declaring var global:MovieClip = MovieClip(root); at the top of the child will run before the loader/parent reference is available, so it will not reliably point at the home movie clip. is right to question the undefined reference — the child never gets a safe reference to the host.

Three practical, reliable options:

  1. Have the parent push the data into the child after the SWF finishes loading (recommended). In the parent, wait for the loader to complete, then set a property or call an init method on the child:

    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaded);
    function onLoaded(e:Event):void {
    var child:MovieClip = loader.content as MovieClip;
    if (child) {
     child.parentGlobal = this.myGlobal; // or child.init(this.myGlobal)
    }
    }
  2. If the child must pull the value, resolve the loader and then the loader's parent only after it is on stage. Use loaderInfo.loader and safe checks:

    this.addEventListener(Event.ADDED_TO_STAGE, onInit);
    function onInit(e:Event):void {
    var loaderRef:Loader = this.loaderInfo.loader as Loader;
    var host:Object = loaderRef ? loaderRef.parent : null;
    if (host && host.hasOwnProperty("myGlobal")) {
     trace(host["myGlobal"]);
    }
    }
  3. Use events: the child dispatches a bubbling event (or a custom event) asking for data; the parent listens and responds by calling the child's method or setting a property.

Notes and cautions: prefer ADDED_TO_STAGE for initialization, avoid relying on timeline timing, and expose a small API (public method/property) on the child for clear communication. If SWFs come from different domains, cross-domain security or ApplicationDomain settings will block direct property access — then use LocalConnection or an explicit messaging API.

I only see test11.fla in your variable list, not as a function. Why do you think you should be able to access "myGlobal" from a variable that has no definition?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.