[haXe] Using HaXe/ASWing

Tane Piper digitalspaghetti at googlemail.com
Tue Aug 5 21:52:18 CEST 2008


Hi there,

I'm in the process of porting my Actionscript 3 code to HaXe 2.0 and 
I've hit some issues.

My code was developed using FlashDevelop + Flash CS3, so I was using 
components like fl.components.ComboBox to display select boxes.

I've tried to use the example here: 
http://www.haxe.org/doc/flash/aswingas3 to set up ASWing with Haxe. Now, 
I'm trying to create a custom components that extends the JPanel and 
adds 3 combo boxes with day/month/year, with a validation function that 
will eventually fire on an event listener for a main submit button.

The problem is that when I include the library in the build file, my 
application turns into a empty flex application with nothing showing. 
I'm mixing HaXe standard components and ASWing, which I'm not sure if 
thats legal.

Any help on this is appreciated.

My build file:

-swf H2Base.swf
-swf-version 9
-main org.ifies.helium.H2Base
-swf-lib library.swf

Here is my main class:

/**
* ...
* @author Tane Piper <tane at digitalspaghetti.me.uk>
*/

package org.ifies.helium;

import org.ifies.helium.services.ConfigLoader;
import org.ifies.helium.components.H2Image;
import org.ifies.helium.components.H2Headline;
//import org.ifies.helium.components.H2AgeVerify;
import flash.events.Event;
import flash.display.MovieClip;
import flash.xml.XML;

class H2Base extends MovieClip
{
public static function main()
{
flash.Lib.current.addChild(new H2Base());
}

public var configXML:ConfigLoader;
public var appName:String;
public var appVersion:String;

public function new(){
// Constructor
configXML = new ConfigLoader();
configXML.addEventListener(ConfigLoader.CONFIG_LOADED, onConfigLoaded);
configXML.load("config.xml");
super();
}

private function onConfigLoaded(event:Event) {
appName = Std.string(configXML.config.appname);
appVersion = Std.string(configXML.config.appversion);
var components:XML = new XML(configXML.config.components);
var totalComponents:Int = components.component.length();
for (i in 0...totalComponents) {
var component:XML = new XML(components.component[i]);
var parameters:XML = new XML(component.parameters);
switch (Std.string(component.type)) {
case "headline":
var headline:H2Headline = new H2Headline(parameters);
headline.generateHeadline(Std.string(parameters.headlinetext));
addChild(headline);
case "image":
var image:H2Image = new H2Image(parameters);
image.load(Std.string(parameters.url));
addChild(image);
default:
trace('Unknown Component');
}
}
//var ageVer:H2AgeVerify = new H2AgeVerify();
//addChild(ageVer);
}
}

This is my component code:
package org.ifies.helium.components;

import org.aswing.JPanel;
import org.aswing.JFrame;
import org.aswing.geom.IntDimension;
import org.aswing.geom.IntPoint;
import org.aswing.JComboBox;
import org.aswing.JList;

class H2AgeVerify extends JPanel {

private var cmb_days:JComboBox;
private var cmb_months:JComboBox;
private var cmb_years:JComboBox;

private var allDays:Array<Int>;
private var allYears:Array<Int>;
static var allMonths:Array<String> = ["January", "Feburary", "March", 
"April", "May", "June", "July", "August", "September", "October", 
"November", "December"];

public function new(){
super();
//component creation
setSize(new IntDimension(300, 60));
var year:Int = Date.now().getFullYear();

for (i in 1...31) {
allDays.push(i);
}

for (j in 1900...year) {
allYears.push(j);
}

cmb_days = new JComboBox(allDays);
cmb_days.setLocation(new IntPoint(5, 5));
cmb_days.setSize(new IntDimension(40, 22));
cmb_days.setMaximumRowCount(7);

cmb_months = new JComboBox(allMonths);
cmb_months.setLocation(new IntPoint(50, 5));
cmb_months.setSize(new IntDimension(40, 22));
cmb_months.setMaximumRowCount(7);

cmb_years = new JComboBox(allYears);
cmb_years.setLocation(new IntPoint(95, 5));
cmb_years.setSize(new IntDimension(40, 22));
cmb_years.setMaximumRowCount(7);

//component layoution
append(cmb_days);
append(cmb_months);
append(cmb_years);
}

public static function main(){
}

private function calculateAge(birthdate:Date):Int {
var dtNow:Date = Date.now();
var currentMonth:Int = dtNow.getMonth();
var currentDay:Int = dtNow.getDay();
var currentYear:Int = dtNow.getFullYear();

var bdMonth:Int = birthdate.getMonth();
var bdDay:Int = birthdate.getDay();
var bdYear:Int = birthdate.getFullYear();

// get the difference in years
var years:Int = dtNow.getFullYear() - birthdate.getFullYear();
// subtract another year if we're before the
// birth day in the current year
if (currentMonth < bdMonth || (currentMonth == bdMonth && currentDay < 
bdDay)) {
years--;
}
return years;
}
}

While this is a component that just uses HaXe and standard flash:

package org.ifies.helium.components;

import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.TextFieldAutoSize;
import flash.text.AntiAliasType;
import flash.xml.XML;

class H2Headline extends TextField {

private var configTextFormat:TextFormat;

public function new(config:XML){
x = Std.parseFloat(Std.string(config.x));
y = Std.parseFloat(Std.string(config.y));
configTextFormat = new TextFormat(Std.string(config.font), config.size, 
config.color);
defaultTextFormat = configTextFormat;
autoSize = TextFieldAutoSize.LEFT;
antiAliasType = AntiAliasType.ADVANCED;
super();
}

public static function main(){
}

public function generateHeadline(outputText:String) {
htmlText=outputText;
}
}



More information about the Haxe mailing list