本文介绍了在外部。作为脚本如何调用一个按钮实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的舞台创造了一个按钮。我给自己定的实例名称的init 并具有 MainTimeline 从外部脚本被称为:

I've created a button in my stage. I've set the instance name to init and have the MainTimeline being called from an an external script:

./项目/ MyFlash.fla

./Project/MyFlash.fla

./项目/ MyFlash_fla / MainTimeline.as

./Project/MyFlash_fla/MainTimeline.as

我在Flash初学者尝试创建一个按钮,并把它放在 MainTimeline.as ;返回的错误:的ReferenceError:错误#1065:初始化的变量没有定义。    在TFM :: MainTimeline()

I'm a beginner in Flash attempting to create a button and call it inside MainTimeline.as; the error returned:ReferenceError: Error #1065: Variable init is not defined. at tfm::MainTimeline()

我也试过 VAR初始化:按钮=新按钮(); ,没有运气

更具体地说,我试图做到这一点:

More specifically, I am trying to do this:

function MainTimeline(){
    //var init:Button = new Button();
    init.addEventListener(MouseEvent.CLICK, begin);
}
function begin(){
    addFrameScript(0, frame1);
}

这些是我的进口(和我增加甚至没用的人在无奈):

These are my imports (and I've added even useless ones in frustration):

import flash.display.*;
import flash.events.*;
import flash.net.*;
import flash.system.*;
import flash.utils.*;
import flash.text.*;
import flash.xml.*;
import flash.media.*;
import fl.controls.Button;
import flash.*;
import fl.*;
import fl.controls.*;

任何可能的解决方案?

Any possible solution?

更新:我链接stage属性下的外部脚本, MyFlash_fla.MainTimeline

Update:I'm linking the external script under the stage property, Class as MyFlash_fla.MainTimeline

我已经得到了没有定义变种错误,只需添加这消除了。 preceding init.add [... ] 。我现在的错误:类型错误:错误#2007:参数监听器必须为非空 在flash.events::EventDispatcher/addEventListener() 在TFM :: MainTimeline()。对不起,不是一开始完全清楚,但我有一个按钮,在我的舞台,我试图把它执行的功能,开始()只要点击。目前,返回的错误和开始()无任何交互执行。

I've gotten the 'var not defined' error eliminated by simply adding this. preceding init.add[...]. My current error: TypeError: Error #2007: Parameter listener must be non-null at flash.events::EventDispatcher/addEventListener() at tfm::MainTimeline(). Sorry for not being completely clear at first, but I have a button in my stage, and I'm trying to have it execute the function, begin() whenever clicked. Currently, that error is returned and begin() is executed without any interaction.

更新II。 事件在开始(事件:事件),我已经加入事件消灭了最后一个错误{... 。一切似乎都在平稳运行。我留下了,虽然错误;它不影响什么,但我仍想摆脱它:的ReferenceError:错误#1065: 在TFM变量初始化没有定义:: MainTimeline / __ setProp_init_Scene1_Layer1_0() 在TFM :: MainTimeline() - ?这是什么

Update II. I've eliminated the last error by adding event:Event in begin(event:Event){.... Everything seems to be running smoothly. I'm left with an error though; it's not affecting anything, but I would still like to rid of it: ReferenceError: Error #1065: Variable init is not defined. at tfm::MainTimeline/__setProp_init_Scene1_Layer1_0() at tfm::MainTimeline() - What is this?

推荐答案

您将需要通过主的DisplayObjectContainer (大概此访问按钮在你的范围内,但很难知道没有更多的信息)

You will need to access the button through the main DisplayObjectContainer (probably this in your context, but difficult to know without more info)

使用方法 getChildByName(参数name:String):的DisplayObject 引用的init 按钮

var init:Button = this.getChildByName("init") as Button;
init.addEventListener(MouseEvent.CLICK, begin);

如果你想要做什么。

Should do what you want.

顺便说一句,不要怕麻烦将所有那些未使用的进口,你的主要问题是定位的init 按钮的显示列表的范围。

By the way, don't bother adding all those unused imports, your main problem is locating the init Button's display list scope.

如果你表现出你是怎样连接在外部脚本过这将是有益的。

It would be helpful if you showed how you were linking in your external script too.

这篇关于在外部。作为脚本如何调用一个按钮实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 03:40