We are going to write a simple program that asks the user their name and prints a little welcome message along with the date. This program should work with the same codebase on Neko and PHP.
The following are the steps you should follow to write this program:
The following is the final code you should have produced:
#if neko import neko.Lib; import neko.io.File; #elseif php import php.Lib; import php.io.File; #end class Main { static function main() { //Print a prompt Lib.print("Please enter your name: "); //Read the answer var name = File.stdin().readLine(); //Print the welcome message Lib.println("Welcome " + name); //Store the date var date = Date.now(); //Concatenate a message with the two elements from the date object Lib.println("Time is: " + Std.string(date.getHours()) + ":" + Std.string(date.getMinutes())); } }
I'm pretty sure that with the commented code, you do understand what's going on, but let's clarify each step we have asked you to think about:
neko.Lib
and neko.io.File
classes obviously are platform-specific; their corresponding classes for php respectively are php.Lib
and php.io.File
Date
class is platform-independent and therefore, we won't need to do anything special with itWe just have a section to do the good important according to the target platform:
#if neko import neko.Lib; import neko.io.File; #elseif php import php.Lib; import php.io.File; #end
This one is pretty short, but sometimes you may have many of those classes.
a. It is more difficult to read
b. It takes more time to compile
c. It is less efficient at runtime
d. It simply doesn't work
flash9
package when targeting Flash9+?a. Use the—remap flash9:flash
switch
b. Simply access it by writing flash9
c. Access it by writing flash; the compiler knows what to do
d. Use an import
at the beginning of the file
Now, let's sum-up all we've done and more particularly the XML part.
Imagine you want to create a tool, which allows you to create pages. Each page will be composed of one or several layers and each layer will have an ID.
You want to save and load a page in an XML file that will look like the following:
<page name="My First Page"> <layer id="layer1"> [content] </layer> <layer id="layer2"> [content] </layer> </page>
For the sake of this example, we will not generate the content parts.
18.119.122.82