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 remoting service


We will now add our remoting service. This remoting service will provide clients with the following two methods:

  1. getList: This method will return the list of animals.

  2. addAnimal: This method will take a name and a number to create an animal and add it to the list of animals in the zoo.

In order to provide this service, we will simply create a class named Service and implement the preceding two functions in it.

The getList function

The getList function will simply return the list from the Zoo class:

   public static function getList() : List<Animal>
   {
      returnZoo.animals;
   }

Ok, this one was pretty simple in our case.

The createAnimal function

The addAnimal method will create an instance of animal setting its name and number fields with the parameters it takes and adding it to the list of animals.

Here it is:

   public static function createAnimal(name : String, quantity : Int)
   {
      //Create a new Animal instance
      var a = new Animal();
      a.name = name...