PacktLib: haXe 2 Beginner's Guide

haxe 2

Credits

Foreword

About the Author

About the Reviewers

www.PacktPub.com

Preface

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

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

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

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

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

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

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

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

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

Interfacing with the Target Platform

Extern classes

Time for action – Writing an extern

Native types and haXe types

Magic functions

Summary

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

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

Pop Quiz Answers

Pop Quiz Answers

Pop Quiz Answers

Pop Quiz Answers

Pop Quiz Answers

Pop Quiz Answers

Pop Quiz Answers

Pop Quiz Answers

Pop Quiz Answers

Pop Quiz Answers

Pop Quiz Answers

Index