Air

From MegaZine3
Jump to: navigation, search


Important: there have been some major compatibility improvements for Air in version 2.1.0 - which, at the time of writing (2011/8/6) is still under development. This tutorial is meant to be followed using MegaZine3 version 2.1.0 or later. There will likely be issues with earlier versions.

This page will give very rudimentary step-by-step guide of how to get MegaZine3 running in an Air application.

Contents

[edit] Step 1: create project

If you already have your Air project you can skip directly to step 2.

In Flash Builder, select "New->Flex Project". You will see a screen like this (sorry for the German):

Air1.PNG

Fill in the desired project name, mark it as an Air app ("Desktop" type) and click "Finish", unless you need to set more nuanced settings.

[edit] Step 2: reference library

To work with MegaZine3 you'll need to reference the library in your project. The easiest way to do this is to simply place the megazine3-fat.swc file into you libs folder:

Air2.png

[edit] Step 3: the code

In the versions after the release of version 2.1 there is now a wrapper component available. So when using the nightlies or 2.1.1+ you can do the following when using the fat SWC:

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
			   xmlns:s="library://ns.adobe.com/flex/spark" 
			   xmlns:mx="library://ns.adobe.com/flex/mx"
			   xmlns:mp="de.mightypirates.megazine.flex.*">
	<fx:Script>
		<![CDATA[
			import de.mightypirates.megazine.Assets;
		]]>
	</fx:Script>
 
	<mp:MegaZine left="0" right="0" top="0" bottom="0"
			 addedToStage="Assets.init(loaderInfo)">
		<fx:XML>
			<book>
				<chapter>
					<page/>
					<page/>
				</chapter>
			</book>
		</fx:XML>
	</mp:MegaZine>
</s:WindowedApplication>

And you're done! If you're not using the fat SWC you can even skip the script block and the addedToStage event.

The old way to add an instance to your App is to create an mx:UIComponent in which you add an instance of MegaZine3. Assuming you have a blank application (new project), you'll modify it to something like this:

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
			   xmlns:s="library://ns.adobe.com/flex/spark" 
			   xmlns:mx="library://ns.adobe.com/flex/mx"
			   addedToStage="onInit()">
	<fx:Script>
		<![CDATA[
			import de.mightypirates.megazine.Assets;
			import de.mightypirates.megazine.MegaZine;
			private var mz:MegaZine;
			private function onInit():void {
				Assets.init(loaderInfo);
				mz = new MegaZine();
				container.addChild(mz);
				onResize();
				mz.loadXML(
					<book plugins="navigationbar">
						<chapter>
							<page/>
							<page/>
							<page/>
							<page/>
							<page/>
							<page/>
							<page/>
							<page/>
						</chapter>
					</book>);
			}
			private function onResize():void {
				if (mz) {
					mz.width = container.width;
					mz.height = container.height;
				}
			}
		]]>
	</fx:Script>
	<mx:UIComponent id="container" left="0" right="0" top="0" bottom="0" resize="onResize()"/>
</s:WindowedApplication>

The important points are:

This will create a book with eight empty pages and the navigationbar plugin loaded.

[edit] Step 4: using .mz3 files

You can still use .mz3 files. To do that, change the mz.loadXML(...) to mz.load("name_of.mz3") and place the file plus your data files in the "src" folder of the project.

When using the wrapper component, you can simply supply it as a property:

<mp:MegaZine xmlFile="path/to/book.mz3"/>

[edit] Known issues

See this and this entry in the swftools mailing list.
Personal tools
Namespaces
Variants
Actions
Navigation
documentation
miscellaneous
Toolbox