使用动作脚本 3 在帧之间传递变量 [英] Passing a variable between frames with actionscript 3

查看:18
本文介绍了使用动作脚本 3 在帧之间传递变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 actionscript 3.0 的新手,我在尝试将在第 1 帧中创建和设置的变量传递到在第 4 帧中添加到舞台的动态文本框时遇到了困难.

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.

推荐答案

你必须想象 - 不同的场景很像单独的电影,而 Flash 在它们之间无法共享.

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

正确的做法是开始使用AS3的OOP(面向对象编程).您将需要创建一个称为文档类的东西.这是永远存在于幕后的有效代码(没有双关语).您可以将内容存储在该类中,以后可以随时阅读.

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.

它比听起来更容易,一旦设置好 - 它将允许您开始将代码移出您的时间线.

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"文件的名称 * 不带.as"扩展名 - 如果您不确定需要输入的位置,请单击该链接.

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.

http://curtismorley.com/wp-content/uploads/2007/07/documentclasspath_bad.JPG

请注意大写 - 这是很好的做法

在 Flash 中打开此文件并编写以下代码.就像我写的一样

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...
    }
  }

}

你可以看到我为你写的所有guff里面我有一个名为myName的变量 - 你可以创建你想要的东西 - myAge... textToBeInAllScenes...girlsWeightToday...然后调用任何东西.

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.

类是需要时在内存中创建的代码块.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.

一个 - 就像 3 所说的把这些东西放在一个盒子里" - 它可以变得更先进,但这就是 jist.

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

class DocumentClass extends MovieClip - 你告诉 flash 我的类叫做 DocumentClass" - 这扩展一个叫做 MovieClip 的东西.

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

MovieClip 是一个类,与您的类完全相同 - 但专为您而生,并且存在于 Flash 中.这包含许多使动画工作的代码.您的 Flash 场景本身只是此 MovieClip 内容的可见版本.

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.

你必须扩展这个类,因为你很想[以虚假的方式]复制粘贴所有完成的代码并在你的文档类中使用它.您现在正在扩展 MovieClip,这样一来,您的代码就会堆积在现有内容之上.

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.

public function DocumentClass() - 是的,这是一个函数.但它被称为构造".它是一种特殊类型的函数,存在于类中.首先它具有相同的名称.这使 Flash 可以很容易地找到它.它的特殊工作是当这个类被创建并在 flash 中看到时立即开始自动运行它的代码.全部自动查看...

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...

对您来说重要的部分是我添加的 public var.这是一个可以存储信息的存储桶.

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

public 部分告诉 flash,任何东西都可以看,只要他们想,场景,其他类...街上的人 - 任何东西!

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

变量(或存储桶)名称后面的 :string,它告诉 Flash 将在变量中存储什么类型的信息.这不是破坏应用程序的重要 - 但对于好的 OOP 代码 - 做到这一点.(谷歌 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)

var 类型有很多种,StringNumberintBoolean 等等...大约 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 -

注意大多数错误是你的拼写错误...Flash不喜欢拼写错误.

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

享受吧!

这篇关于使用动作脚本 3 在帧之间传递变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆