Book Image

haXe 2 Beginner's Guide

5 (1)
Book Image

haXe 2 Beginner's Guide

5 (1)

Overview of this book

Table of Contents (21 chapters)
haxe 2
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

The dot-notation


If you remember, one constraint was to be able to read values of metadata and properties using the dot-notation.

In fact, everything we've done until now has been done only for the sake of this exercise and for you to write some haXe code.

Although this is important, let's move on to implementing access via the dot-notation.

To do that, we will make our class implement Dynamic<String> and implement a resolve method.

Before doing that, there's just one question that arises: how are we going to handle the situation if a key exists in the metadata Hash and in the properties Hash? In our example, we will handle this situation quite easily by simply returning the value that is in the metadata.

So, here is our Component class modified:

class Component implements Dynamic<String>
{
   public var properties : Hash<String>;
   public var metadata : Hash<String>;
   
   public function new()
   {
      properties = new Hash<String>();
      metadata = new Hash...