Flash 从另一个SWF文件访问SWF文件中的变量
好的,我是一个动作脚本noob。我可以做“点击这里去那里”之类的事情,所有的时间线脚本 然后我把这个项目扔到了我的膝上(因为我是“Flash高手”),虽然我读过很多有意义的东西,但我需要有人告诉我到底在哪里编写代码。我保证这一切结束后我会回去学习真正的AS3,我有书和很好的教程 这是任务。我有一个SWF文件(我们称之为parent.SWF),它要求用户在文本字段(hospNameInput)中输入名称,并将其保存到变量(hName)中 我需要在另一个SWF(child.SWF,由parent.SWF加载)中使用字符串变量“hName”,以便将名称文本添加到文件许多帧的文本框中。这本质上是一个美化的幻灯片,在画面上有一些互动性,他们希望能够为他们展示给的人个性化 我在child.swf中有一些文本框,我想用parent.swf变量“hName”中的文本填充这些文本框,如:Flash 从另一个SWF文件访问SWF文件中的变量,flash,variables,Flash,Variables,好的,我是一个动作脚本noob。我可以做“点击这里去那里”之类的事情,所有的时间线脚本 然后我把这个项目扔到了我的膝上(因为我是“Flash高手”),虽然我读过很多有意义的东西,但我需要有人告诉我到底在哪里编写代码。我保证这一切结束后我会回去学习真正的AS3,我有书和很好的教程 这是任务。我有一个SWF文件(我们称之为parent.SWF),它要求用户在文本字段(hospNameInput)中输入名称,并将其保存到变量(hName)中 我需要在另一个SWF(child.SWF,由parent.S
var frameHeader:String = "01 " + hName + " Today";
frameHeader1.text = frameHeader;
chartLabel.text = hName + " Analysis";
就像我说的,我只是个懦弱的时间线编码员。有人能给我相当明确的指示,在每个SWF中放入什么来让它工作吗
我保证阅读这些书,并学会正确地做这件事,就像文件一样 尝试通过加载程序对象的content属性访问变量。内容属性应该直接引用加载的swf的时间线
对于仍有此问题的任何人,您可以尝试以下步骤
- 您必须使用代码创建文本框。首先将输入框添加到后台
- 加载外部SWF并将其视为MovieClip对象
- 将文本框(带有保存的输入)添加到MovieClip(加载的SWF)中
//-- For later referencing of Child.swf as though it's MovieClip on stage named "my_Child_Swf"
var my_Child_Swf:MovieClip;
//-- create User Input textbox
var input_txt:TextField = new TextField();
input_txt.type = "input";
input_txt.border = true;
input_txt.x = 50;
input_txt.y = 100;
//-- create string to hold User Input for passing onto a Child.swf textbox
var saved_text:String;
//-- create Name textbox for Child.swf (later will contain text of "saved_text")
var name_txt:TextField = new TextField();
name_txt.type = "dynamic";
//name_txt.border = true;
name_txt.x = 10;
name_txt.y = 10;
name_txt.width = 50;
//-- Now add User Input box to screen
stage.addChild(input_txt);
//-- load SWF
var swf_loader:Loader = new Loader();
//add loader object to stage BEFORE you do anything with external SWF..
stage.addChild(swf_loader);
btn_load_SWF.buttonMode = true;
btn_load_SWF.addEventListener(MouseEvent.CLICK, load_Child_SWF);
//Button control function
function load_Child_SWF (event:MouseEvent) : void
{
saved_text = input_txt.text; //capture text as we begin load of Child SWF
trace("input_txt is..." + saved_text); //trace is for testing/confirmation
swf_loader.load ( new URLRequest ("Child.swf") );
swf_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, Child_SWF_ready);
}
function Child_SWF_ready (evt:Event) : void
{
swf_loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, Child_SWF_ready);
swf_loader.x = stage.stageWidth / 2;
swf_loader.y = 200;
//Treat the Loader contents (Child.swf) as a MovieClip named "my_Child_Swf"
my_Child_Swf = swf_loader.content as MovieClip;
//Position of text when adding to Child SWF
//note: Its top-left corner is new X & Y point set to 0
name_txt.x = 10; //10 pixels from 0 point of Child SWF
name_txt.y = 10;
updateText(); //do instructions inside function "updateText"
my_Child_Swf.addChild(name_txt); //add (updated) name text to Child SWF
}
function updateText() : void
{
name_txt.text = saved_text; //apply the saved_input String here
}
这应该足以让你开始。其他需要研究的是如何通过代码设置和嵌入字体、设置文本大小和颜色等。对于记录来说,在时间轴中进行任何编码都不是最好的工作方式。我将所有代码放在一个地方.as文件中。我无法预测当您切换到另一个框架和代码集时会发生什么。这就是说,这是从时间表和工作测试。谢谢,VC:1
//-- For later referencing of Child.swf as though it's MovieClip on stage named "my_Child_Swf"
var my_Child_Swf:MovieClip;
//-- create User Input textbox
var input_txt:TextField = new TextField();
input_txt.type = "input";
input_txt.border = true;
input_txt.x = 50;
input_txt.y = 100;
//-- create string to hold User Input for passing onto a Child.swf textbox
var saved_text:String;
//-- create Name textbox for Child.swf (later will contain text of "saved_text")
var name_txt:TextField = new TextField();
name_txt.type = "dynamic";
//name_txt.border = true;
name_txt.x = 10;
name_txt.y = 10;
name_txt.width = 50;
//-- Now add User Input box to screen
stage.addChild(input_txt);
//-- load SWF
var swf_loader:Loader = new Loader();
//add loader object to stage BEFORE you do anything with external SWF..
stage.addChild(swf_loader);
btn_load_SWF.buttonMode = true;
btn_load_SWF.addEventListener(MouseEvent.CLICK, load_Child_SWF);
//Button control function
function load_Child_SWF (event:MouseEvent) : void
{
saved_text = input_txt.text; //capture text as we begin load of Child SWF
trace("input_txt is..." + saved_text); //trace is for testing/confirmation
swf_loader.load ( new URLRequest ("Child.swf") );
swf_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, Child_SWF_ready);
}
function Child_SWF_ready (evt:Event) : void
{
swf_loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, Child_SWF_ready);
swf_loader.x = stage.stageWidth / 2;
swf_loader.y = 200;
//Treat the Loader contents (Child.swf) as a MovieClip named "my_Child_Swf"
my_Child_Swf = swf_loader.content as MovieClip;
//Position of text when adding to Child SWF
//note: Its top-left corner is new X & Y point set to 0
name_txt.x = 10; //10 pixels from 0 point of Child SWF
name_txt.y = 10;
updateText(); //do instructions inside function "updateText"
my_Child_Swf.addChild(name_txt); //add (updated) name text to Child SWF
}
function updateText() : void
{
name_txt.text = saved_text; //apply the saved_input String here
}