-1

I have two swf files.I have followed this global variables in AS3 yet no use.

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

1 Answers1

0

This will probably won't work because at the moment of subscription the root of test11 is already a part of display list:

this.addEventListener(Event.ADDED,onFileAdded);

This will definitely not work because DisplayObject, Sprite, MovieClip classes do not dispatch complete event:

this.addEventListener(Event.COMPLETE,onFileAdded1);

UPD: Stage detection.

if (stage) onStage();
else addEventListener(Event.ADDED_TO_STAGE, onStage);

function onStage(e:Event = null):void
{
    removeEventListener(Event.ADDED_TO_STAGE, onStage);

    // Stage is available from this point on.
    // Your code here.
}
Organis
  • 7,243
  • 2
  • 12
  • 14
  • However, when test11.swf loads, the following two lines printout, Movie clip root undefined Movie clip MC undefined – Ramasamy Viswanathan Jul 11 '17 at 12:50
  • If I want to trace something when test11.swf loads, which event should I track. – Ramasamy Viswanathan Jul 11 '17 at 12:52
  • @RamasamyViswanathan You don't need events for it. If your **test11** is 1-frame then its frame script will execute after it is done loading. If it is a multiple frame SWF, then you need to watch **loaderInfo.bytesLoaded** vs **loaderInfo.bytesTotal** values to track the end of loading. – Organis Jul 11 '17 at 13:07
  • However, when test11.swf loads, the following two lines printout, Movie clip root undefined Movie clip MC undefined – Ramasamy Viswanathan Jul 11 '17 at 13:11
  • @RamasamyViswanathan The **added** event can originate from any inner content of the listener object. Check if **stage** is present, use **Event.ADDED_TO_STAGE** if not, and only when your content is a part of **stage** you can (probably) access **root**. – Organis Jul 11 '17 at 13:17
  • If I ain't asking too much,Is it possible to point me to an example. – Ramasamy Viswanathan Jul 11 '17 at 13:46
  • I am sorry, I get Movie clip root undefined Movie clip MC undefined – Ramasamy Viswanathan Jul 11 '17 at 14:16
  • I added if (stage) onStage(); else addEventListener(Event.ADDED_TO_STAGE, onStage); function onStage(e:Event = null):void { removeEventListener(Event.ADDED_TO_STAGE, onStage); trace("Movie clip root"); trace(MovieClip(root).flag); trace("Movie clip MC"); trace(global.myGlobal); } to test11.fla – Ramasamy Viswanathan Jul 11 '17 at 14:17
  • Can u plesae comment – Ramasamy Viswanathan Jul 12 '17 at 05:37
  • @RamasamyViswanathan There was no question. You informed me that you added the provided code, you didn't inform me of any result. – Organis Jul 12 '17 at 05:58
  • I am sorry, I get Movie clip root undefined Movie clip MC undefined – Ramasamy Viswanathan Jul 12 '17 at 06:48
  • @RamasamyViswanathan Trace **stage** and **root** instead of trying to access those variables of yours. Also **trace(root == this);** – Organis Jul 12 '17 at 06:53
  • While tracing trace("stage"); trace(stage); trace("root"); trace(root); trace("root == this"); trace(root == this); I get stage [object Stage] root [object MainTimeline] root == this true. – Ramasamy Viswanathan Jul 12 '17 at 07:10
  • If **root == this** is **true** that means **test11.fla** is in its own sandbox and have no access to the **home.fla** sandbox. Or maybe you are testing it without **home.fla**. – Organis Jul 12 '17 at 07:27
  • Is there a way to share the files with you, I am loading test11.fla from home.fla. – Ramasamy Viswanathan Jul 12 '17 at 07:31
  • @RamasamyViswanathan The root of **home.fla** is **parent.parent** from **test11.fla**. From the way you are doing it I'd advise you to prepare for continuous endeavors. – Organis Jul 12 '17 at 08:19
  • Basically I know I ain't doing it the correct way. I am ready to start all over again. How should I go about getting the correct thing to work. – Ramasamy Viswanathan Jul 12 '17 at 12:43
  • @RamasamyViswanathan Learn, how to build SWC, learn the difference between internal and external linkage, write a "global" data sharing class, build SWC of it, build main SWF with it and make all other SWFs refer it as "external" class. – Organis Jul 12 '17 at 14:54