`
deepfuture
  • 浏览: 4332588 次
  • 性别: Icon_minigender_1
  • 来自: 湛江
博客专栏
073ec2a9-85b7-3ebf-a3bb-c6361e6c6f64
SQLite源码剖析
浏览量:79404
1591c4b8-62f1-3d3e-9551-25c77465da96
WIN32汇编语言学习应用...
浏览量:68361
F5390db6-59dd-338f-ba18-4e93943ff06a
神奇的perl
浏览量:101484
Dac44363-8a80-3836-99aa-f7b7780fa6e2
lucene等搜索引擎解析...
浏览量:281140
Ec49a563-4109-3c69-9c83-8f6d068ba113
深入lucene3.5源码...
浏览量:14597
9b99bfc2-19c2-3346-9100-7f8879c731ce
VB.NET并行与分布式编...
浏览量:65552
B1db2af3-06b3-35bb-ac08-59ff2d1324b4
silverlight 5...
浏览量:31311
4a56b548-ab3d-35af-a984-e0781d142c23
算法下午茶系列
浏览量:45199
社区版块
存档分类
最新评论

flex游戏引擎(PushButton)-查找实体,查找组件

阅读更多

Looking Up Entities

Looking up an entity by name is simple. You can do it from code, or via the level file.

1.<!-- An empty, named entity. -->
2.<entity name="NamedEntity">
3.   <!-- Components would go here, although an empty entity is valid. -->
4.</entity>      
1.// How to look it up from code: 
2.var namedEntity:IEntity = PBE.lookupEntity("NamedEntity");
1.<!-- How to reference an entity from XML. -->
2.<entity name="ExampleEntity">
3.   <component name="NameExampleComponent">
4.      <!-- EntityReference is a field of type IEntity. The entityName attribute indicates that we want to set it to a reference to the named entity.-->
5.      <EntityReference entityName="NamedEntity"/>
6.   </component>
7.</entity>

Looking Up Components

You can look up components by name in several ways. You can look them up in code or XML. You can also look them up via the NameManager, or via methods on IEntity.

1.<!-- A named entity, with some named components. -->
2.<entity name="NamedEntity">
3.   <!-- The type of these components are irrelevant for the examples in this section. -->
4.   <component type="ExampleComponent" name="A"/>
5.   <component type="AnotherComponent" name="B"/>
6.   <component type="AnotherComponent" name="C"/>
7.</entity>      
01.// Looking up a component by type and entity name. This returns component "A".
02.var componentA:ExampleComponent = PBE.lookupComponentByType("NamedEntity", ExampleComponent) as ExampleComponent;
03.  
04.// Look up a component by entity name and component name. This returns component "B".
05.var componentB:AnotherComponent = PBE.lookupComponentByName("NamedEntity", "B") as AnotherComponent;
06.  
07.// You can also look up components on an entity (either your owner as shown
08.// here, or a reference gotten via the NameManager or another means). This
09.// code snippet would have to be run from a component in NamedEntity, as
10.// otherwise owner would not reference the right thing.
11.var componentA:ExampleComponent = owner.lookupComponentByName("A");

You can also look up another component by type, as mentioned in the component chapter.

01.<!-- How to reference a component from XML. -->
02.<entity name="ExampleEntity">
03.  
04.   <!-- This is a component that we will reference by name in the other component. -->
05.   <component type="AnotherComponent" name="D"/>
06.   <component name="ComponentNameExampleComponent">
07.       <!-- ComponentReference is a field that has a component type (ExampleComponent in this case). The entityName attribute indicates that we want to look up the first component with matching type on the named entity.-->
08.      <ComponentReference entityName="NamedEntity"/>
09.      <!-- AnotherComponentReference is a field that has a component type (AnotherComponent in this case). entityName is as above, but componentName lets you indicate the specific component you want, based on name. -->
10.      <AnotherComponentReference entityName="NamedEntity" componentName="C"/>
11.        
12.      <!-- Finally, you can reference components on the same entity as you by only using the componentName attribute. -->
13.      <YetAnotherComponentReference componentName="D"/>
14.   </component>
15.</entity>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics