haXe 2

Book description

Develop exciting applications with this multi-platform programming language

  • Build web applications from scratch using haXe
  • Target multiple platforms using the same code and interface the code with the target platform
  • Create a whole dynamic website with haXe targeting JavaScript as a case study, even if you haven't touched haXe before
  • Learn about haXe remoting and how haXe applications communicate with each other
  • Learn to manage your data and map haXe objects into your databases

In Detail

haXe is the universal programming language that is completely cross-platform and provides a standard library that remains the same - regardless of platform.

haXe 2 Beginner's Guide will get you up and running with this exciting language and will guide you through its features in the easiest way possible.

haXe has filled the gap in creating multi-platform applications, and haXe 2 Beginner's Guide will fill the gap in learning all you need to know about haXe - even if it's the first time you have heard of it.

This book will enable you to fully realize haXe's potential for translating code from a haXe program into different languages.

Start with learning how to install haXe, work your way up to templating, and finally learn exactly how to make the same code work for multiple platforms. In between, find heaps of tricks and techniques and work with haXe's typing system. Learn about inheritance, go from learning what a parameter is to creating your own parameterized classes, and find out what the fuss is all about regarding the dynamic type.

By the time you are done with this book, you'll find yourself writing efficient haXe code for multiple platforms in less time than you can say "compatible".

Table of contents

  1. haXe 2
    1. Table of Contents
    2. haxe 2
    3. Credits
    4. Foreword
    5. About the Author
    6. About the Reviewers
    7. www.PacktPub.com
      1. Support files, eBooks, discount offers and more
        1. Why subscribe?
        2. Free access for Packt account holders
    8. Preface
      1. Here is haXe
      2. Where and for what is haXe used?
        1. Where is haXe used?
        2. What is haXe used for?
        3. One language to rule them all
        4. Object-oriented programming
        5. haXe versions
        6. haXe and the new models of web applications
        7. haXe as an universal language
      3. Getting help
        1. Reading some documentation
        2. Asking questions
          1. The haXe forum
          2. The haXe mailing list
            1. Some advice
        3. Reading some blogs
          1. Nicolas Cannasse
          2. Weblob
          3. GameHaXe
          4. A Bug's Life
          5. Blog.haxe.org
      4. Helping the community
        1. The mailing list and the forum
        2. The wiki
        3. Write on your blog or website
        4. Writing libraries or tools
        5. Talking about haXe
      5. What this book covers
      6. What you need for this book
      7. Who this book is for
      8. Conventions
      9. Time for action – heading
        1. What just happened?
        2. Pop quiz – heading
        3. Have a go hero – heading
      10. Reader feedback
      11. Customer support
        1. Downloading the example code for this book
        2. Errata
        3. Piracy
        4. Questions
    9. 1. Getting to know haXe
      1. Installing haXe
        1. Two ways to install: The installer and sources compilation
        2. Installing on Windows
        3. Installing on MacOSX
        4. Installing on Linux
        5. Installing nightly builds
        6. Verifying your installation
      2. Choosing an editor
        1. FlashDevelop 3
        2. The TextMate bundle
        3. VIM
      3. Writing your first program
      4. Time for action – Writing a Hello World
        1. What just happened?
      5. A program with some interaction
      6. Time for action – Interacting with the user
        1. What just happened?
        2. Pop quiz – basic knowledge
      7. Summary
    10. 2. Basic Syntax and Branching
      1. Modules, packages, and classes
        1. Packages
        2. Modules
        3. Classes
          1. Accessing a class
      2. Constants and its types
        1. Booleans
        2. Integers
        3. Floats
          1. Base 10
          2. Scientific notation
        4. Strings
        5. Regular expressions
        6. The null value
          1. Flash9 and above
      3. Binary and unary operators
        1. Binary operators
          1. Assigning values
          2. Comparison operators
          3. Arithmetic operators
          4. Boolean operators
          5. Bitwise operators
        2. Unary operators
      4. Blocks
      5. Variable declaration and scope
        1. Declaring a variable
          1. At class level
      6. Time for action – Declaring some fields
        1. What just happened?
          1. In a block of instructions
      7. Field access and function calls
      8. Constructing class instance
      9. Conditional branching
        1. If
        2. Switch
      10. Loops
        1. While
        2. For
      11. Break and continue
      12. Time for action – Using the break keyword
        1. What just happened?
      13. Time for action – Using the continue keyword
        1. What just happened?
      14. Return
      15. Exception handling
      16. Anonymous objects
      17. Local functions
      18. Managing a fridge
      19. Time for action – Managing a fridge
        1. What just happened?
        2. Have a go hero – Throw Exceptions to prevent crashes
      20. Summary
    11. 3. Being Cross-platform with haXe
      1. What is cross-platform in the library
        1. Object storage
        2. The Std class
        3. The haxe package
          1. The haxe.remoting package
          2. The haxe.rtti package
          3. The haxe.Http class
        4. Regular expressions and XML handling
          1. Regular expressions
          2. XML handling
        5. Input and output
          1. The DOM interface
          2. The Flash interface
          3. The standard input/output interface
      2. Platform-specific packages
        1. JavaScript
        2. Flash
        3. Neko
        4. PHP
        5. C++
      3. Conditional compilation
        1. Conditional compilation depending on flags
        2. Conditional compilation depending on the target
      4. The remap switch
      5. Coding cross-platform using imports
      6. Time for action – Welcoming the user on Neko & PHP
        1. What just happened?
        2. Pop quiz – Writing cross-platform code
        3. Have a go hero – Handle XML
      7. Time for action – Reading from the XML file
        1. What just happened?
      8. Time for action – Writing to an XML file
        1. What just happened?
      9. Testing our sample
      10. Making it cross-platform
      11. Summary
    12. 4. Understanding Types
      1. Explicitly typed variables
      2. Static typing
      3. Values with several types
        1. Defining a type
        2. Inheritance
        3. Multi-inheritance
        4. Implementing an interface
      4. Representing a blog article
      5. Time for action – Representing different types of articles
      6. Function's type
        1. Expressing a function's type
        2. Functions using functions
        3. Dynamic functions
      7. Anonymous objects
        1. Duck typing
      8. Creating a function to apply another one
      9. Time for action – Applying a function on every item
        1. What just happened?
      10. Type inference
        1. Assigning a value
        2. Assigning the value of the variable to another one
        3. Passing the variable as a parameter
      11. Casting
        1. Safe casting
        2. Unsafe casting
        3. Untyped
      12. Type parameters
        1. Usage of Type parameters
        2. Creating a parameterized class
        3. Constraint parameters
      13. Extending the fridge
      14. Time for action – A fridge with constraints
        1. What just happened?
        2. Have a go hero – Creating a typed container
        3. Pop quiz – Verify your knowledge
      15. Summary
    13. 5. The Dynamic Type and Properties
      1. Freeing yourself from the typing system
      2. Time for action – Assigning to Dynamic variables
      3. Time for action – Assigning from Dynamic variables
        1. Field access
        2. Functions in Dynamic variables
      4. Parameterized Dynamic class
      5. Classes implementing Dynamic
      6. Time for action – Implementing a non-parameterized Dynamic
        1. What just happened?
      7. Time for action – Implementing a parameterized Dynamic
        1. What just happened?
      8. Using a resolve function when implementing Dynamic
      9. Time for action – Writing our Component class
      10. Time for action – Parsing the configuration file
      11. Time for action – Testing our parser
      12. Time for action – Writing the configuration file
      13. Time for action – Testing the writer
      14. The dot-notation
      15. Thoughts on writing our parser
      16. The dynamic keyword
      17. Warning
      18. Properties in classes
        1. Use
        2. Implementation
          1. Writing the getter
          2. Writing the setter
          3. Defining the property
        3. Accessibility
        4. The default getter
        5. The default setter
        6. The dynamic getter and setter
        7. The never getter and setter
        8. A compile-time feature
        9. Have a go hero – Writing a person class
        10. Pop Quiz – Doing the things
      19. Summary
    14. 6. Using and Writing Interfaces, Typedefs, and Enums
      1. Interfaces
        1. Purpose
        2. Default visibility
        3. Type inference
        4. Implementing an interface
          1. Implementation and type inference
          2. Implementation and visibility
          3. Making use of interfaces
      2. Typedefs
      3. Time for action – Naming Anonymous Types
        1. What just happened?
        2. Aliases
        3. Visibility
          1. Private typedefs
        4. Duck typing
        5. Typedefs to access private members
        6. Creating iterable objects
      4. Enums
        1. Basic enums
        2. Enums' constructors
        3. Switching on basic enums
        4. Enums with parameters
      5. Time for action – Switching over enums with parameters
        1. What just happened?
        2. Have a go hero – Write a fridge with an iterator
      6. Time for action – Writing our Fridge class
        1. What just happened?
      7. Time for action – Making it possible to iterate over a fridge
        1. What just happened?
      8. Time for action – Creating the iterator
        1. What just happened?
      9. Our main function
        1. Pop quiz – Typedef, interfaces, and Enums
      10. Summary
    15. 7. Communication Between haXe Programs
      1. The haXe serializer
        1. Usefulness
        2. Possibilities
          1. Class instances
          2. Custom serialization
          3. Enum instances
          4. Unserializing exceptions
          5. Reducing size and preventing infinite loops
      2. haXe remoting
        1. Supported protocols and layers
          1. Over HTTP
            1. Implementation
          2. Using the ExternalInterface
            1. The JavaScript side
            2. The Flash side
          3. Using AMF
      3. Time for action – Writing a zoo management tool
      4. The Animal class
      5. Representing the zoo
      6. Time for action – Saving the list
      7. Time for action – Loading the list
      8. The remoting service
        1. The getList function
        2. The createAnimal function
        3. Tying it together
      9. The client
      10. Time for action – Initializing the client connection
        1. What just happened?
          1. The createAnimal function
          2. The listAnimals function
          3. The main menu
        2. Compiling the client
        3. Have a go hero – Represent data from JS in Flash
        4. Pop quiz – Doing the things
      11. Summary
    16. 8. Accessing Databases
      1. Connecting to databases
        1. php.db.Connection and neko.db.Connection
          1. SQL usage
          2. The interface
            1. The close function
            2. The commit function
            3. The rollback function
            4. The escape function
            5. The quote function
            6. The request function
            7. The addValue function
            8. The dbName function
            9. The lastInsertId function
        2. Connecting to the database
          1. MySQL
          2. SQLite
        3. Dealing with results
          1. Typing
      2. The SPOD
        1. Setting a SPOD object
        2. The table name
        3. Non-mapped fields
        4. The cache
      3. A concrete example of SPOD use
        1. Setting the object
        2. Setting the connection
      4. The Manager
        1. The all function
        2. The count function
        3. The delete function
        4. The get function
        5. The getWithKeys function
        6. The object function
        7. The objects function
        8. The search function
      5. Handling relations
      6. Creating a blogging system
      7. Time for action – Creating the Users table
        1. What just happened?
      8. Time for action – Creating the User class
        1. What just happened?
      9. Time for action – Creating the Posts table
      10. Time for action – Creating the Post class
        1. What just happened?
      11. Time for action – Creating the connection to the database
        1. What just happened?
      12. Time for action – Listing posts
      13. Time for action – Listing users
      14. Time for action – Adding a user
      15. Time for action – Adding a post
      16. Time for action – Branching it with the main function
        1. Have a go hero – Listing posts from a specific user
        2. Pop quiz – Doing the things
      17. Summary
    17. 9. Templating
      1. Introduction to the haxe.Template class
        1. Printing a value
        2. Branching
        3. Using lists, arrays, and other iterables
      2. Time for action – Executing code from a template
        1. What just happened?
      3. Integrating subtemplates
      4. Creating a blog's front page
      5. Time for action – Creating our SPOD class
      6. Time for action – Connecting to the database
      7. Time for action – Creating our template
      8. Time for action – Reading the template from resources
      9. Time for action – Executing the template
      10. Time for action – Testing the result
        1. Pop quiz – Doing the thing
        2. Have a go hero – Doing more with the thing
      11. Summary
    18. 10. Interfacing with the Target Platform
      1. Extern classes
      2. Time for action – Writing an extern
        1. What just happened?
        2. Using an extern
        3. Class path
        4. Limitations
        5. The __init__ magic
      3. Native types and haXe types
        1. The Neko and PHP cases
          1. PHP functions
          2. Neko functions
      4. Magic functions
        1. The Flash magic
          1. __new__
          2. __arguments__
          3. __typeof__
          4. __delete__
          5. __eval__
          6. __gettimer__
          7. __geturl__
          8. __instanceof__
          9. __random__
          10. __trace__
          11. __keys__
          12. __global__
          13. __as__
          14. __is__
          15. __in__
        2. The Neko magic
          1. Arrays and strings
        3. The PHP magic
          1. __php__
          2. __call__
          3. __var__
          4. __physeq__
        4. Have a go hero – Wrapping parameters in an array
        5. Pop quiz – Doing the things
      5. Summary
    19. 11. A Dynamic Website Using JavaScript
      1. Manipulating the DOM
        1. The browser's DOM
          1. Nodes
          2. Events
            1. Level 1
            2. Level 2
      2. Time for action – Using events from the DOM level 0
        1. What just happened?
      3. Time for action – Using DOM level 2 events
        1. What just happened?
      4. Time for action – Working around by storing reference to functions
        1. What just happened?
        2. Have a go hero – A dynamic website with JavaScript
      5. Time for action – Setting up the model
      6. Time for action – Setting up our view
        1. What just happened?
      7. Time for action – Setting up the controller
      8. Time for action – Creating a computer view
        1. What just happened?
      9. The main class
      10. Summary
    20. 12. Creating a Game with haXe and Flash
      1. Embedding assets
      2. Time for action – Installing SWFMILL
      3. Time for action – Creating a library
      4. Time for action – Using assets
      5. Event handling
        1. Have a go hero – A game with Flash
        2. The game design
        3. The assets
        4. The player's character
      6. Time for action – Drawing the character
      7. Time for action – Handling moves
        1. What just happened?
      8. Time for action – Moving the character
        1. What just happened?
      9. Time for action – Adding balls
        1. What just happened?
      10. Time for action – Updating the position
        1. What just happened?
      11. Time for action – Detecting collisions
        1. What just happened?
        2. Have a go hero – Adding a proper score display
        3. Have a go hero – Adding an online score table
        4. Pop quiz – Software used
      12. Summary
    21. A. Pop Quiz Answers
      1. Chapter 1: Getting to know haXe
      2. Chapter 3: Being Cross-platform with haXe
      3. Chapter 4: Understanding Types
      4. Chapter 5: The Dynamic Type and Properties
      5. Chapter 6: Using and Writing Interfaces, Typedefs, and Enums
      6. Chapter 7: Communication Between haXe Programs
      7. Chapter 8: Accessing Databases
      8. Chapter 9: Templating
      9. Chapter 10: Interfacing with the Target Platform
      10. Chapter 12: Creating a Game with haXe and Flash
    22. Index

Product information

  • Title: haXe 2
  • Author(s): Benjamin Dasnois
  • Release date: July 2011
  • Publisher(s): Packt Publishing
  • ISBN: 9781849512565