[英]Flash Programming ActionScript3, double import swf to the main Stage from another class
Let me explain my situation: We have a file named Main.fla which links to the class MAIN( it's included in the MAIN.as file). 让我解释一下我的情况:我们有一个名为Main.fla的文件,该文件链接到MAIN类(包含在MAIN.as文件中)。 I also have a secondary User.as file with a User class. 我也有一个带有User类的辅助User.as文件。
I managed to import a classic swf button to my stage from the User.as class but i'm finding trouble on adding the pop up window, when the button is clicked. 我设法从User.as类中将经典的swf按钮导入舞台,但是单击按钮时添加弹出窗口时遇到麻烦。 Here are the codes: 以下是代码:
MAIN.as 主要
import flash.display.*;
import flash.net.*;
import flash.events.*;
import User; //Importing our User class
public class MAIN extends MovieClip
{
public function MAIN()
{
var k = new User();
k.logocons(this); //This function is made on User class and
//it takes a stage:Object as definition
}
}
User.as 用户
import flash.display.*;
import flash.net.*;
import flash.events.*;
public class User extends MovieClip
{
var myLoader:Loader = new Loader();
public function User()
{
var url:URLRequest = new URLRequest("C:/Project/Button.swf");
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, swfLoaded);
myLoader.load(url);
}
function swfLoaded(event:Event):void
{
myLoader.x = 50;
myLoader.y = 50;
}
public function logocons(stage:Object)
{
stage.stop();
stage.addChild(myLoader);
}
}
This works normally so far When i test the file the Button works perfectly 到目前为止,这正常工作当我测试文件时,Button可以正常工作
What i want now is when the button is clicked to show at my MAIN.Stage a pop up window which is also in the same folder named PopUp.swf. 我现在想要的是单击按钮以在我的MAIN.Stage上显示一个弹出窗口,该窗口也位于名为PopUp.swf的同一文件夹中。
I tried really many things but i couldn't find how i can access the MAIN.stage from another class. 我尝试了很多事情,但找不到其他类可以访问MAIN.stage的方法。
Thanks in advance 提前致谢
User.as 用户
import flash.display.*;
import flash.net.*;
import flash.events.*;
import fl.motion.MotionEvent;
public class User extends MovieClip
{
var myLoader:Loader = new Loader();
private var _mainStage:Stage;//MAIN.stage
public function User()
{
var url:URLRequest = new URLRequest("C:/Project/Button.swf");
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, swfLoaded);
myLoader.load(url);
}
function swfLoaded(event:Event):void
{
myLoader.x = 50;
myLoader.y = 50;
}
public function logocons(stage:Object)
{
_mainSage = (stage as MovieClip).stage;// now you can use _mainStage anywhere on User class.
stage.stop();
stage.addChild(myLoader);
}
private function onButtonClick(e:MouseEvent){
//ex. _mainSage.addChild(popWindows);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.