haXe 2 Beginner's Guide

Develop exciting applications with this multi-platform programming language

haXe 2 Beginner's Guide

Beginner's Guide
Benjamin Dasnois

Develop exciting applications with this multi-platform programming language
$10.00
$44.99
RRP $26.99
RRP $44.99
eBook
Print + eBook
$12.99 p/month

Get Access

Get Unlimited Access to every Packt eBook and Video course

Enjoy full and instant access to over 3000 books and videos – you’ll find everything you need to stay ahead of the curve and make sure you can always get the job done.

+ Collection
Free Sample

Book Details

ISBN 139781849512565
Paperback288 pages

About This Book

  • 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

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.

Table of Contents

Chapter 1: Getting to know haXe
Installing haXe
Choosing an editor
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
Constants and its types
Binary and unary operators
Blocks
Variable declaration and scope
Time for action – Declaring some fields
Field access and function calls
Constructing class instance
Conditional branching
Loops
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
Platform-specific packages
Conditional compilation
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
Representing a blog article
Time for action – Representing different types of articles
Function's type
Anonymous objects
Creating a function to apply another one
Time for action – Applying a function on every item
Type inference
Casting
Type 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
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
Summary
Chapter 6: Using and Writing Interfaces, Typedefs, and Enums
Interfaces
Typedefs
Time for action – Naming Anonymous Types
Enums
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
haXe remoting
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 client
Time for action – Initializing the client connection
Summary
Chapter 8: Accessing Databases
Connecting to databases
The SPOD
A concrete example of SPOD use
The Manager
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
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
Native types and haXe types
Magic functions
Summary
Chapter 11: A Dynamic Website Using JavaScript
Manipulating the DOM
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
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

What You Will Learn

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

Authors

Table of Contents

Chapter 1: Getting to know haXe
Installing haXe
Choosing an editor
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
Constants and its types
Binary and unary operators
Blocks
Variable declaration and scope
Time for action – Declaring some fields
Field access and function calls
Constructing class instance
Conditional branching
Loops
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
Platform-specific packages
Conditional compilation
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
Representing a blog article
Time for action – Representing different types of articles
Function's type
Anonymous objects
Creating a function to apply another one
Time for action – Applying a function on every item
Type inference
Casting
Type 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
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
Summary
Chapter 6: Using and Writing Interfaces, Typedefs, and Enums
Interfaces
Typedefs
Time for action – Naming Anonymous Types
Enums
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
haXe remoting
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 client
Time for action – Initializing the client connection
Summary
Chapter 8: Accessing Databases
Connecting to databases
The SPOD
A concrete example of SPOD use
The Manager
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
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
Native types and haXe types
Magic functions
Summary
Chapter 11: A Dynamic Website Using JavaScript
Manipulating the DOM
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
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

Book Details

ISBN 139781849512565
Paperback288 pages
Read More