English 中文(简体)
如何让闪电专业的特异性 传递到AS3脚本?
原标题:How can I give flash stage instances unique properties in Flash Professional to pass to AS3 script?

我开始在Flash Professional中建立一个粗略的游戏引擎框架, 我很好奇我如何能够在 Flash 库中创建对象, 从而可以拖到舞台上, 并指定从 AS3 上可以访问的属性 。

Example:
I want to create a switch object (e.g. a light switch), so that when the player interactes with it, it triggers something specific in code such as a light in the room turns on.

我理解闪电报在 UI 中构建了组件, 您可以在 Flash 专业环境中定义属性( 参见下面的图像), 我想知道是否有方法可以创建我自己的自定义样式组件, 这样我就可以基本上用闪光打开我的级别文件(. fla), 然后从我的图书馆拖动一个开关组件, 并输入一些信息, 比如它所控制的灯光, 以及我想要的任何其他信息 。

"https://i.sstatic.net/pZaLu.jpg" alt="闪光元件参数"/>

(以上是我要寻找的参数控制类型的例子)

我读过一些关于延长闪光UI Concommonent 类的内容,但我认为,这样做不正确,因为它对我想要的东西来说是超乎寻常的。我所想要的只是将一些基本参数从一个图书馆级实例传送到AS3。我不想通过例名传递数据,因为如果我想进行更复杂的互动,这看起来非常混乱。

谢谢!

问题回答

我会制作一个“开关”电影剪辑,然后将它导出到“开关”电影剪辑中,就像“灯光”电影剪辑一样。在主类中,我用添加“Child”(剪辑),然后在“开关”电影剪辑中添加点击听众来控制“灯光”。

这很容易做到。

在我看来,组成部分是错误的做法。

Firstly you would want to setup Actionscript linkage / label your Library item. In Library Panel. - Right Click on "yourMC" >> click "Properties". - In Properties dialog Tick "Export for Action Script" - Then Name your Class eg "yourMC_Class"

监控监已经准备好在你的代码中被引用了

next you would want to Dynamically add your "yourMC" from library to stage. which can be done like such.

/第一个参考图书馆项目

var yourMC_ref:yourMC_Class = new yourMC_Class();

/ 然后将动态 mc 项装入 var 。

var your_MC_OBJ = yourMC_ref;

/然后把你的MC添加到舞台上。

this.addChild(your_MC_OBJ);
your_MC_OBJ.x = 200;
your_MC_OBJ.y = 100;

简而言之,这就是我如何把图书馆项目添加到舞台上。

显然,这是基本功能/代码。

在一个项目中,我会拥有所有代码 在一个外部阶级, 在这样的情况下,你会 仅仅设置vars作为公共vars

public var yourMC_ref:yourMC_Class = new yourMC_Class();
public var your_MC_OBJ = yourMC_ref;

最后三行代码变成公共职能

public function ADD_First_MC()
{
       this.addChild(your_MC_OBJ);
       your_MC_OBJ.x = 200;
       your_MC_OBJ.y = 100;
}

现在您可以用更复杂的 MC_ OBJ 方式使用 。

eg. to create a light switch there are many options depending on how you need to approch functionality. eg. Apply a different MC library item to "your_MC_OBJ" play specific frame within MCs.

However If it was me I would just use mouse function to switch light on or off using addChild removeChild. eg.

public var LightON = 0;
public var yourMC_ref:yourMC_Class = new yourMC_Class();
public var your_MC_OBJ = yourMC_ref;

然后创建一个公共函数, 处理/ 关闭事件

public function LightON_OFF()
     {
         if(LightON == 1)
            {
               this.addChild(your_MC_OBJ);
               your_MC_OBJ.x = 200;
               your_MC_OBJ.y = 100;
            }
         if(LightON == 0)
            {
               this.removeChild(your_MC_OBJ);
            }
     }

希望这能帮上忙

所以,对于你想要的,虽然它可能不是 做你想做的事的最佳方式, 我明白这是你的经验 你正在构建。

以下列方式(最简单的一种)使用组件:

  • Create a Movie Clip
  • Right-click it in library
  • Click on "Component Definitions"
  • Add a property, set a name, a variable name (var test, for this matter) and a default value
  • 点击确定

  • 打开你的电影短片

  • Open code for the first frame and declare the variable without an initial value (var test:String;)
  • 追踪其 s 值( 跟踪( 测试) ); )

  • 返回到舞台根

  • Drag and drop the item from library to stage
  • 测试它 (Cmd/Ctrl + Enter) (也许它会打印 null, 不知道为什么, 它有时忽略默认值)

  • 在舞台上选择您的组件

  • Open the properties panel (Windows > Properties)
  • 转到此面板上的组件参数并更改属性值

  • 您应该看到控制台上追踪的值 。

我认为,像这样, 你可以使用组件的属性 来达到你想要的目的, 比如使用字符串, 并按其名称获得受控 mc 。

祝你好运

我想人们想说的是 你可以让数据驱动整个过程 这样你就可以把 IDE 和数据结合起来 来完成你最后的游戏

但考虑到这一点... 这可能是你想要的。

例如,如果您有 BaseSwitch 类 :

public Class BaseSwitch extends MovieClip {
   private var _lightName:String;
   private var _light:Light;
   public function get lightName():String {
      return lightName;
   }
   public function set lightName(value:String):void {
      if (value != _lightName) {
        _lightnName = value;
        //Note I don t advocate having children reach into their parents like this,
        //but you sound like you don t want the parent involved in the process, so
        //this is one way you could do it.
        if (parent.hasOwnProperty(lightName) && parent[lightName] is Light) {
           _light = parent[lightName];
        } else {
           trace( Could not find light , _lightName);
        }

      }
   }
   //other code to listen for gestures and operate the light
}

当您想要一个开关来操作特定光名称时, 请创建一个库例, 并将其 < 坚固 > 基础类 设置为 BaseSwitch 。 当您关闭用于设置基本类的对话框时, 您就会注意到它给了您一个对话框, 它无法在类路径中找到该类, 一个将会生成。 您将用一个设置光的类来替换它。 在根目录中创建一个新的 AS3 类, 名称与您的库例相同 。 它应该看起来类似 :

public class SpecificSwitch {
   public function SpecificSwitch() {
      super();
      lightName =  theSwitch ;
   }
}

其他可能的选择包括让母类将开关与以名称为基础的灯光相匹配,因此,如果它发现光1和光1开关,它要么引用开关的灯光,要么在它自己的事件监听系统中建立绘图系统。





相关问题
Disable button tooltip in AS3

I want to disable the tooltip on certain buttons. The tooltip manager seems to be an all or nothing solution. Is it possible to disable the tooltip for just one or two buttons?

Sorting twodimensional Array in AS3

So, i have a two-dimensional Array of ID s and vote count - voteArray[i][0] = ID, voteArray[i][1] = vote count I want the top 3 voted items to be displayed in different colors, so i have a 2nd Array -...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

AS3 try/catch out of memory

I m loading a few huge images on my flex/as3 app, but I can t manage to catch the error when the flash player runs out of memory. Here is the what I was thinking might work (I use ???? because i dont ...

Red5 Security Tutorial

I am looking for a step by step tutorial on securing Red5 from intrusion. This seems to be a question that comes up alot in a google search, but is never really answered in a way that makes sense to ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

visible property of DisplayObject

For example I have a hierarchy of movie clips. mc1 is a child of mc, and mc2 is a child of mc1. Turns out that when I set mc1.visible = false; mc2.visible stays true. Is that supposed to happen?...

热门标签