Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
swf to swf communication:
http://kb2.adobe.com/community/publishing/918/cpsid_91887.html
Copy link to clipboard
Copied
If you are loading test11 using a Loader, into the home.fla stage, then I think the problem is that MovieClip(root) is pointing to the main timeline of test11, and not the main timeline of home.fla.
There is an event for when something is added to the stage. At that point the object certainly has a parent, and you could get the parent of test11. It would be like this (in test11):
var global:MovieClip;
addEventListener(Event.ADDED_TO_STAGE,added);
function added(e:Event){
global = MovieClip(MovieClip(root).parent);
}
Then global should be pointing at the main timeline of home.fla.
Copy link to clipboard
Copied
I added the following to test11.fla,
var global:MovieClip;
addEventListener(Event.ADDED_TO_STAGE,added);
function added(e:Event){
global = MovieClip(MovieClip(root).parent);
trace("global");
trace(global);
}
It never prints "global".
Copy link to clipboard
Copied
did you read the help at that link?
Copy link to clipboard
Copied
Look at Q3 in the page kglad linked to. It has a better syntax than in my example.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now