我有两个swf文件。我已经遵循了这个global variables in AS3但没有用。
我有一个home.fla文件
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;
和另一个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);
}
我想访问&#34; myGlobal&#34;来自test11.fla
答案 0 :(得分:0)
这可能不会起作用,因为在订阅时, test11 的根目录已经是显示列表的一部分:
this.addEventListener(Event.ADDED,onFileAdded);
这肯定不起作用,因为 DisplayObject , Sprite , MovieClip 类不会发送完整事件:< / p>
this.addEventListener(Event.COMPLETE,onFileAdded1);
UPD:舞台检测。
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.
}