haXe 2 Beginner's Guide


haXe 2 Beginner's Guide
eBook: $26.99
Formats: PDF, PacktLib, ePub and Mobi formats
$22.94
save 15%!
Print + free eBook + free PacktLib access to the book: $71.98    Print cover: $44.99
$44.99
save 37%!
Free Shipping!
UK, US, Europe and selected countries in Asia.
Also available on:
Overview
Table of Contents
Author
Reviews
Support
Sample Chapters
  • 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

Book Details

Language : English
Paperback : 288 pages [ 235mm x 191mm ]
Release Date : July 2011
ISBN : 1849512566
ISBN 13 : 9781849512565
Author(s) : Benjamin Dasnois
Topics and Technologies : All Books, Application Development, Beginner's Guides, Open Source, Web Development

Table of Contents

Preface
Chapter 1: Getting to know haXe
Chapter 2: Basic Syntax and Branching
Chapter 3: Being Cross-platform with haXe
Chapter 4: Understanding Types
Chapter 5: The Dynamic Type and Properties
Chapter 6: Using and Writing Interfaces, Typedefs, and Enums
Chapter 7: Communication Between haXe Programs
Chapter 8: Accessing Databases
Chapter 9: Templating
Chapter 10: Interfacing with the Target Platform
Chapter 11: A Dynamic Website Using JavaScript
Chapter 12: Creating a Game with haXe and Flash
Pop Quiz Answers
Index
  • Chapter 1: Getting to know haXe
    • Installing haXe
      • Two ways to install: The installer and sources compilation
      • Installing on Windows
      • Installing on MacOSX
      • Installing on Linux
      • Installing nightly builds
      • Verifying your installation
    • Choosing an editor
      • FlashDevelop 3
      • The TextMate bundle
      • VIM
    • Writing your first program
    • Time for action – Writing a Hello World
    • A program with some interaction
    • Time for action – Interacting with the user
    • Summary
    • Chapter 2: Basic Syntax and Branching
      • Modules, packages, and classes
        • Packages
        • Modules
        • Classes
          • Accessing a class
      • Constants and its types
        • Booleans
        • Integers
        • Floats
          • Base 10
          • Scientific notation
        • Strings
        • Regular expressions
        • The null value
          • Flash9 and above
      • Binary and unary operators
        • Binary operators
          • Assigning values
          • Comparison operators
          • Arithmetic operators
          • Boolean operators
          • Bitwise operators
        • Unary operators
      • Blocks
      • Variable declaration and scope
        • Declaring a variable
          • At class level
      • Time for action – Declaring some fields
        • In a block of instructions
    • Field access and function calls
    • Constructing class instance
    • Conditional branching
      • If
      • Switch
    • Loops
      • While
      • For
    • Break and continue
    • Time for action – Using the break keyword
    • Time for action – Using the continue keyword
    • Return
    • Exception handling
    • Anonymous objects
    • Local functions
    • Managing a fridge
    • Time for action – Managing a fridge
    • Summary
      • Chapter 3: Being Cross-platform with haXe
        • What is cross-platform in the library
          • Object storage
          • The Std class
          • The haxe package
            • The haxe.remoting package
            • The haxe.rtti package
            • The haxe.Http class
          • Regular expressions and XML handling
            • Regular expressions
            • XML handling
          • Input and output
            • The DOM interface
            • The Flash interface
            • The standard input/output interface
        • Platform-specific packages
          • JavaScript
          • Flash
          • Neko
          • PHP
          • C++
        • Conditional compilation
          • Conditional compilation depending on flags
          • Conditional compilation depending on the target
        • The remap switch
        • Coding cross-platform using imports
        • Time for action – Welcoming the user on Neko & PHP
        • Time for action – Reading from the XML file
        • Time for action – Writing to an XML file
        • Testing our sample
        • Making it cross-platform
        • Summary
        • Chapter 4: Understanding Types
          • Explicitly typed variables
          • Static typing
          • Values with several types
            • Defining a type
            • Inheritance
            • Multi-inheritance
            • Implementing an interface
          • Representing a blog article
          • Time for action – Representing different types of articles
          • Function's type
            • Expressing a function's type
            • Functions using functions
            • Dynamic functions
          • Anonymous objects
            • Duck typing
          • Creating a function to apply another one
          • Time for action – Applying a function on every item
          • Type inference
            • Assigning a value
            • Assigning the value of the variable to another one
            • Passing the variable as a parameter
          • Casting
            • Safe casting
            • Unsafe casting
            • Untyped
          • Type parameters
            • Usage of Type parameters
            • Creating a parameterized class
            • Constraint parameters
          • Extending the fridge
          • Time for action – A fridge with constraints
          • Summary
          • Chapter 5: The Dynamic Type and Properties
            • Freeing yourself from the typing system
            • Time for action – Assigning to Dynamic variables
            • Time for action – Assigning from Dynamic variables
              • Field access
              • Functions in Dynamic variables
            • Parameterized Dynamic class
            • Classes implementing Dynamic
            • Time for action – Implementing a non-parameterized Dynamic
            • Time for action – Implementing a parameterized Dynamic
            • Using a resolve function when implementing Dynamic
            • Time for action – Writing our Component class
            • Time for action – Parsing the configuration file
            • Time for action – Testing our parser
            • Time for action – Writing the configuration file
            • Time for action – Testing the writer
            • The dot-notation
            • Thoughts on writing our parser
            • The dynamic keyword
            • Warning
            • Properties in classes
              • Use
              • Implementation
                • Writing the getter
                • Writing the setter
                • Defining the property
              • Accessibility
              • The default getter
              • The default setter
              • The dynamic getter and setter
              • The never getter and setter
              • A compile-time feature
            • Summary
            • Chapter 6: Using and Writing Interfaces, Typedefs, and Enums
              • Interfaces
                • Purpose
                • Default visibility
                • Type inference
                • Implementing an interface
                  • Implementation and type inference
                  • Implementation and visibility
                  • Making use of interfaces
              • Typedefs
              • Time for action – Naming Anonymous Types
                • Aliases
                • Visibility
                  • Private typedefs
                • Duck typing
                • Typedefs to access private members
                • Creating iterable objects
              • Enums
                • Basic enums
                • Enums' constructors
                • Switching on basic enums
                • Enums with parameters
              • Time for action – Switching over enums with parameters
              • Time for action – Writing our Fridge class
              • Time for action – Making it possible to iterate over a fridge
              • Time for action – Creating the iterator
              • Our main function
              • Summary
              • Chapter 7: Communication Between haXe Programs
                • The haXe serializer
                  • Usefulness
                  • Possibilities
                    • Class instances
                    • Custom serialization
                    • Enum instances
                    • Unserializing exceptions
                    • Reducing size and preventing infinite loops
                • haXe remoting
                  • Supported protocols and layers
                    • Over HTTP
                    • Using the ExternalInterface
                    • Using AMF
                • Time for action – Writing a zoo management tool
                • The Animal class
                • Representing the zoo
                • Time for action – Saving the list
                • Time for action – Loading the list
                • The remoting service
                  • The getList function
                  • The createAnimal function
                  • Tying it together
                • The client
                • Time for action – Initializing the client connection
                  • The createAnimal function
                  • The listAnimals function
                  • The main menu
                • Compiling the client
              • Summary
                • Chapter 8: Accessing Databases
                  • Connecting to databases
                    • php.db.Connection and neko.db.Connection
                      • SQL usage
                      • The interface
                    • Connecting to the database
                      • MySQL
                      • SQLite
                    • Dealing with results
                      • Typing
                  • The SPOD
                    • Setting a SPOD object
                    • The table name
                    • Non-mapped fields
                    • The cache
                  • A concrete example of SPOD use
                    • Setting the object
                    • Setting the connection
                  • The Manager
                    • The all function
                    • The count function
                    • The delete function
                    • The get function
                    • The getWithKeys function
                    • The object function
                    • The objects function
                    • The search function
                  • Handling relations
                  • Creating a blogging system
                  • Time for action – Creating the Users table
                  • Time for action – Creating the User class
                  • Time for action – Creating the Posts table
                  • Time for action – Creating the Post class
                  • Time for action – Creating the connection to the database
                  • Time for action – Listing posts
                  • Time for action – Listing users
                  • Time for action – Adding a user
                  • Time for action – Adding a post
                  • Time for action – Branching it with the main function
                  • Summary
                  • Chapter 9: Templating
                    • Introduction to the haxe.Template class
                      • Printing a value
                      • Branching
                      • Using lists, arrays, and other iterables
                    • Time for action – Executing code from a template
                    • Integrating subtemplates
                    • Creating a blog's front page
                    • Time for action – Creating our SPOD class
                    • Time for action – Connecting to the database
                    • Time for action – Creating our template
                    • Time for action – Reading the template from resources
                    • Time for action – Executing the template
                    • Time for action – Testing the result
                    • Summary
                    • Chapter 10: Interfacing with the Target Platform
                      • Extern classes
                      • Time for action – Writing an extern
                        • Using an extern
                        • Class path
                        • Limitations
                        • The __init__ magic
                      • Native types and haXe types
                        • The Neko and PHP cases
                          • PHP functions
                          • Neko functions
                      • Magic functions
                        • The Flash magic
                          • __new__
                          • __arguments__
                          • __typeof__
                          • __delete__
                          • __eval__
                          • __gettimer__
                          • __geturl__
                          • __instanceof__
                          • __random__
                          • __trace__
                          • __keys__
                          • __global__
                          • __as__
                          • __is__
                          • __in__
                        • The Neko magic
                          • Arrays and strings
                        • The PHP magic
                          • __php__
                          • __call__
                          • __var__
                          • __physeq__
                      • Summary
                      • Chapter 11: A Dynamic Website Using JavaScript
                        • Manipulating the DOM
                          • The browser's DOM
                            • Nodes
                            • Events
                        • Time for action – Using events from the DOM level 0
                        • Time for action – Using DOM level 2 events
                        • Time for action – Working around by storing reference to functions
                        • Time for action – Setting up the model
                        • Time for action – Setting up our view
                        • Time for action – Setting up the controller
                        • Time for action – Creating a computer view
                        • The main class
                        • Summary
                        • Chapter 12: Creating a Game with haXe and Flash
                          • Embedding assets
                          • Time for action – Installing SWFMILL
                          • Time for action – Creating a library
                          • Time for action – Using assets
                          • Event handling
                            • The game design
                            • The assets
                            • The player's character
                          • Time for action – Drawing the character
                          • Time for action – Handling moves
                          • Time for action – Moving the character
                          • Time for action – Adding balls
                          • Time for action – Updating the position
                          • Time for action – Detecting collisions
                          • Summary
                          • Pop Quiz Answers
                            • Chapter 1: Getting to know haXe
                            • Chapter 3: Being Cross-platform with haXe
                            • Chapter 4: Understanding Types
                            • Chapter 5: The Dynamic Type and Properties
                            • Chapter 6: Using and Writing Interfaces, Typedefs, and Enums
                            • Chapter 7: Communication Between haXe Programs
                            • Chapter 8: Accessing Databases
                            • Chapter 9: Templating
                            • Chapter 10: Interfacing with the Target Platform

                            Benjamin Dasnois

                            Benjamin Dasnois has always been fascinated by open source software and as such, has been giving courses about Linux in an IT school in France. In the meantime, Benjamin has been following and working with haXe since its beginning and uses it in his professional life. He now works on an open source project, started the integration of haXe into it, and made it work with the technologies that were already in use.

                            Errata type: Others | Page number: 101-104 | Errata date: 26 Aug 11

                            nameMyComponent 1 textHelloWorld 0 // SHOULD BE name MyComponent 1 text HelloWorld 0

                             

                            Code Downloads

                            Download the code and support files for this book.


                            Submit Errata

                            Please let us know if you have found any errors not listed on this list by completing our errata submission form. Our editors will check them and add them to this list. Thank you.


                            Errata

                            - 2 submitted: last submission 01 Aug 2013

                            Errata type: Others | Page number: 231 | Errata date: 03 Sep 2011

                            there is a code that contain this line: osCell.appendChild(Lib.document.createTextNode) it should be: osCell.appendChild(Lib.document.createTextNode(

                             

                            Errata type: Code | Page number: 69-71 

                            The Page class declares a layers property of type List, but never instantiates that object.  This means the Main class cannot successfully use the lines p.layers.add(l1); or p.layers.add(l2); on page 71, because the layers property of that Page instance (p), doesn't exist.  This works by adding the following line to the Page class on page 69:

                            // ORIGINAL
                            public function new()
                            {
                            }

                            // MY VERSION
                            public function new()
                            {
                              layers = new List();
                            }

                             

                            Errata type: Code | Page number: 71 

                            The Main class attempts to write an XML file in the last line of code shown on page 71.  In the example as shown, the full path is /Users/benjamin/page1.xml, which is problematic.  For example, must the directories "Users" and "benjamin" pre-exist?  If so, from what point of view must these directories pre-exist?  From the system root, or from the root of wherever the compiled n file lives?  To make this example work, I changed the file path to the name of the file (page1.xml) and nothing else.  This created the XML file in the same directory as the compiled n file.

                             

                             


                            Errata type: Typo | Page number: 101-104

                            nameMyComponent 1
                            textHelloWorld 0

                            // SHOULD BE
                            name MyComponent 1
                            text HelloWorld 0

                            // if form eats spaces :
                            name SPACE MyComponent SPACE 1
                            text SPACE HelloWorld SPACE 0

                            expl :
                            the parser splits each line with a 'SPACE' delimiter ( " " )

                             

                            Sample chapters

                            You can view our sample chapters and prefaces of this title on PacktLib or download sample chapters in PDF format.

                            Frequently bought together

                            haXe 2 Beginner's Guide +    Apache Solr 3 Enterprise Search Server =
                            50% Off
                            the second eBook
                            Price for both: £24.65

                            Buy both these recommended eBooks together and get 50% off the cheapest eBook.

                            What you will learn from this book

                            • Install haXe, get to know the community, and write your first program
                            • Declare classes and variables in haXe
                            • Learn about branching so that your program can make decisions and choose different paths according to conditions
                            • Iterate lists and get things organized into modules, packages, classes – the lot
                            • Learn about haXe's typing system
                            • Learn features such as type inference and Dynamic objects
                            • Learn all there is to know about the famed Dynamic type
                            • Use and write interfaces, typedefs, and enums
                            • Learn to use templates in haXe to further enhance your web applications

                            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".

                            Approach

                            This book is part of the Packt Beginner's Guide series. Written in an engaging style, it offers step-by-step examples with screenshots at key steps and clear explanation of what is happening in each task.

                            Who this book is for

                            This book is written for both Beginners and Developers who want to learn this multi-platform programming language to build web applications from scratch.

                            Code Download and Errata
                            Packt Anytime, Anywhere
                            Register Books
                            Print Upgrades
                            eBook Downloads
                            Video Support
                            Contact Us
                            Awards Voting Nominations Previous Winners
                            Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
                            Resources
                            Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software