使用ActionScript 3帧之间传递变量变量、ActionScript

2023-09-08 12:13:51 作者:亡心少女

我是新来的ActionScript 3.0和我遇到困难,试图通过创建的,并已添加到舞台中的帧4一个动态文本框的第1帧设置一个变量。

I am new to actionscript 3.0 and I'm experiencing difficulty trying to pass a variable that is created and set in frame 1 to a dynamic text box that is added to the stage in frame 4.

第1帧上的变量是从用户输入的信息设置: VAR input_dia =; input_dia = pdia_input.text;

on frame 1 the variable is set from information entered by the user: var input_dia = ""; input_dia = pdia_input.text;

和应显示在框架4一个动态文本框: dia_alert.text = input_dia;

and should be displayed in a dynamic text box on frame 4: dia_alert.text=input_dia;

我收到以下错误: 1120:未定义的属性input_dia的访问

I'm receiving the following error: 1120: Access of undefined property input_dia.

推荐答案

您必须想象 - 在不同的场景有很多像独立电影和闪光灯麻烦它们之间共享

You have to imagine - the different scenes are a lot like separate movies and flash has trouble sharing between them.

做的正确的方法 - 就是开始使用AS3的OOP(面向对象编程)。 您将需要创建一些所谓的文档类。这实际上是code,生活永远在幕后(没有双关语意)。你可以存储东西,在这个类,并在以后读的,只要你请。

The correct way to do it - is begin to use the OOP (object orientated programming) of AS3. You will need to create something called a document class. This is effectively code that lives forever behind the scenes (no pun intended). You can store stuff in this class and read them later on whenever you please.

它很容易,它的声音,设置一次 - 这将让你开始移动code关你的时间表。

Its easier than it sounds and once set up - it'll allow you to start moving the code off your timeline.

首先创建一个名为DocumentClass.as这可真称得上是什么文件,但调用它,这是非常好的做法。

First create a file called "DocumentClass.as" This can really be called anything, but calling it this is very good practice.

这个文件保存在与FLA你正在使用的同一个地方 - 同样的文件夹

Save this file in the same place as the FLA you're working with - the same folder.

在CS3 - 在属性面板在屏幕的底部 - 当你有选择的阶段都会有一个小盒子让您键入文档类的名称进去。输入您刚才提出'的DocumentClass*文件的名称没有。至于延期 - 点击链接,如果您不确定,它在哪里,你需要键入

In CS3 - In the properties panel at the bottom of your screen - when you have the stage selected there will be a little box allowing you to type the name of the document class into it. Type the name of the file you just made 'DocumentClass' *without the '.as' extension - click on the link if you're unsure where it is you need to type.

https://m.xsw88.com/allimgs/daicuo/20230908/651.png.JPG

请注意capitlization - 这是很好的做法

在Flash中打开该文件,并写入以下code。正是因为我把它写

Open this file in Flash and write the following code. Exactly as I write it

DocumentClass.as 的

package {

  //Call this class the SAME NAME as the file - VERY IMPORTANT
  class DocumentClass extends MovieClip
  {

    //This is an example of a variable - a container
    //of information of which is public - and can be 
    //seen by all the scenes in your flash movie.
    public var myName:String = "Jay Jagpal";

    //This is called a construct - this function automatically
    //runs when this class is seen by flash.
    public function DocumentClass()
    {
      //nothing needs to go here for you today...
    }
  }

}

您可以看到里面的一切我为你写的废话我有一个名为MYNAME变量 - 您可以创建你想要的 - 。myAge ... textToBeInAllScenes ...... girlfriendsWeightToday ......然后叫什么

You can see inside all the guff I write for you I have a variable called myName - You can create what you want - myAge... textToBeInAllScenes... girlfriendsWeightToday... Call then anything.

一个类是一个在内存中需要时创建code块。一个的DocumentClass是这样的 - 而是通过应用程序的人生活一路

A class is a block of code that is created in memory when needed. A DocumentClass is this - but lives all the way through the life of your application.

一个的包的 - 只是看中了的AS3代言'把这个东西在一个盒子 - 它可以得到更先进的,但多数民众赞成在JIST

A package - is just fancy as3 speak for 'put this stuff in a box' - it can get more advanced but thats the jist.

类的DocumentClass扩展MovieClip的的 - 你告诉闪光我的类被称为的DocumentClass - 这的扩展的一些所谓的影片剪辑。

class DocumentClass extends MovieClip - You're telling flash "my class is called DocumentClass" - this extends something called a MovieClip.

该影片剪辑是一个类,完全像你 - 但你都做了住在里面闪光灯。这包含了大量的code键使动画作品。您的Flash场景本身是这个影片剪辑的事情只是一个可见的版本。

The MovieClip is a class, exactly like yours - but made for you and lives inside flash. This contains lots of code to make animations work. Your Flash scene itself is just a visible version of this MovieClip thing.

您需要的扩展的这一类,因为你pretty的太多希望的 [在一个假的方式] 的复制粘贴所有已完成code和使用它在你的DocumentClass。您现在继承MovieClip,并通过这样做,你的code都堆在已经存在的东西上面。

you have to extend this class, because you pretty much want to [in a fake way] copy paste all the finished code and use it in your DocumentClass. You're now extending MovieClip and by doing so, your code is piled on top of already existing stuff.

公共职能的DocumentClass()的 - 是的,这是一个函数。但其称为结构。它是一种特殊类型的函数,生活类中。首先,它具有相同的名称。这使得Flash来发现它真的很容易。其特殊的任务是立即开始运行其code自动当这班由,看到闪光灯。所有的自动看看...

public function DocumentClass() - yes this is a function. But its called a 'construct'. Its a special type of function that lives inside a class. Firstly it has the same name. This allows Flash to find it really easily. Its special job is to instantly start running its code automatically when this class is made and seen in flash. All automatic see...

为您的重要组成部分,是公共变种我补充道。这是一桶水,你可以存放你的信息。

The important part for you is the public var I added. This is a bucket you can store your information in.

在公开的部分告诉闪光灯,什么都可以看出来,如果​​他们想,场景,其他类......人们在大街上 - !任何

The public part tells flash, anything can see it if they want to, scenes, other classes... people in the street - Anything!

在:字符串的后您的变量(或桶)的名字,它告诉闪光什么类型的信息将被存储在变种内。这不是APP突破重要 - 但求好OOP code - 做到这一点。 (谷歌AS3变量铸造)

The :string after your variable (or bucket) name, it telling flash what type of information will be stored inside the var. This isn't app breaking important - but for good OOP code - do it. (google AS3 variable casting)

有许多变种类型的字符串的号的 INT 的布尔的以及这么一...大约7基础。

There are many var types, String, Number, int, Boolean and so one... roughly about 7 basic.

我认为是不够的StackOverflow的答案 - 它会 -

I think thats enough of an answer for StackOverflow - it will work -

警告的大多数错误是拼写错误...闪光不喜欢拼写错误。

be warned Most errors are your spelling errors... Flash don't like spelling errors.

享受!