PDA

View Full Version : Flash Lite 2.1 - Strange problem just on device, not in DeviceCentral


darthbane
03-25-2008, 11:59 AM
Hi,

I wrote an application just in actionscript.
It first read XML from a server and then creates movie clips on the scene.

When I click on one of the movie clips, another XML is received from the server and a "popup" is displayed with the data (populated with new movie clips and textFields corresponding to the 2nd XML).

This works fine in DeviceCentral (I use a 240x320 Flash Lite 2.1 device).

But when I try to use it on the read device (HTC 3600 or VPA Compact GPS), it seems that flash lite skips some instructions. Sometimes, there are no titles, or the background is not drawn correctly. Sometimes it works. (I cant reproduce the behaviour)

I rewrote the code. Completly in actionscript, without any images in the Library (so, it is not about too little memory).


I have no idea what this is about.
(Maybee XML data is too large, an Garbage Collector runs just every 60 seconds. Or I have too much classes / actionscript code?)

I will post the neccessary code.

The missing classes LabeledScene.as Triggers.as QuickLinks.as work fine.

Tankwart.as

class Tankwart {

public static function startApp() {

var triggers:Array;

var xmlFile:XML = new XML();
xmlFile.ignoreWhite = true;
xmlFile.onLoad = function(success:Boolean):Void {
if (success) {
try {
triggers = ComUtils.createTriggers(this);
DrawUtils.createTriggerButtons(triggers);
} catch (e:Error) {
DrawUtils.showError("General Error", "Unknown error: " + e.message);
return;
}
} else {
DrawUtils.showError("Network Error","Unable to get data from server.");
return;
}
};
xmlFile.load(res/GetTriggers.xml);
} // startApp()
}


ComUtils.as

class ComUtils {

/* Creates and returns an Array containing the Trigger classes corresponding to the XML file. */
public static function createTriggers(node:XMLNode):Array {
var triggers:Array = new Array();
var i:Number;
for (i=0; i<node.firstChild.childNodes.length; i++) {
var triggerNode:XMLNode = node.firstChild.childNodes[i];
var t:Trigger = new Trigger();
t.setViaXml(triggerNode);
triggers.push(t);
}
return triggers;
}

/* Creates and returns an Array containing the QuickLink classes corresponding to the XML file. */
public static function createQuickLinks(node:XMLNode):Array {
var links:Array = new Array();
var i:Number;
for (i = 0; i < node.firstChild.childNodes.length; i++) {
var linkNode:XMLNode = node.firstChild.childNodes[i];
var l:QuickLink = new QuickLink();
l.setViaXml(linkNode);
links.push(l);
}
return links;
}

/* Is called when clicked on a MovieClip (=Trigger). */
public static function createPopup(tid:Number, triggerName:String) {
var links:Array = new Array();
var xmlFile:XML = new XML();
xmlFile.ignoreWhite = true;
xmlFile.onLoad = function(success:Boolean):Void {
if (success) {
try {
links = ComUtils.createQuickLinks(this);// can throw Error
ComUtils.createPopupPanel(tid, triggerName, links);
} catch (e:Error) {
DrawUtils.showError("General Error","Unknown error: " + e.message);
return;
}
} else {
DrawUtils.showError("Network Error","Unable to get data from server.");
return;
}
};
xmlFile.load("res/GetQuickLinks.xml");
}
/* Creates a popup MovieClip which contains serveral MovieClips for each QuickLink. */
public static function createPopupPanel(tid:Number, triggerName:String, links:Array):Void {

var popup:MovieClip = mc.createEmptyMovieClip("popup", _root.getNextHighestDepth());

// TITLE
var titleMc:MovieClip = popup.createEmptyMovieClip("title", popup.getNextHighestDepth());
titleMc.createTextField("title_txt", titleMc.getNextHighestDepth(), 0, 0, 10, 10);
var titleText:TextField = titleMc["title_txt"];
titleText.autoSize = true;
titleText.text = "-= " + triggerName + " =-";

// QUICKLINKS:
var h:Number = titleMc._y + titleMc._height;
for (var i:Number = 0; i < links.length; i++) {
var link:QuickLink = links[i];
var mc:MovieClip = popup.createEmptyMovieClip("mc_" + link.id , popup.getNextHighestDepth());
mc.createTextField("mc_txt", mc.getNextHighestDepth(), 0, 0, 10, 10);
var mc_txt:TextField = mc["mc_txt"];
mc_txt.autoSize = true;
mc_txt.text = link.name;
mc._y = h;
h = mc._y + mc._height;

var w:Number = 0;
for (var j:Number = 0; j < link.scenes.length; j++) {
var s:LabeledScene = link.scenes[j];
var mcS:MovieClip = popup.createEmptyMovieClip("mc_s_" + s.sid , popup.getNextHighestDepth());
mcS.createTextField("mcS_txt", mcS.getNextHighestDepth(), 0, 0, 10, 10);
var mcS_txt:TextField = mcS["mcS_txt"];
mcS_txt.autoSize = true;
mcS_txt.text = s.name;
mcS._y = h;
mcS._x = w;

w = mcS._x + mcS._width;
}
h = mcS._y + mcS._height;

}

// CLOSE:
var closeMc:MovieClip = popup.createEmptyMovieClip("close", popup.getNextHighestDepth());
closeMc.createTextField("close_txt", closeMc.getNextHighestDepth(), 0, 0, 10, 10);
var closeText:TextField = closeMc["close_txt"];
closeText.autoSize = true;
closeText.text = "CLOSE";
closeMc.onRelease = function () {
popup.removeMovieClip();
}
closeMc._y = h;

// BG: 5 = rounded corner radius, 100=alpha
DrawUtils.drawBg(popup, popup._width, popup._height, 5, 0x0000FF, 100);
}

}




class DrawUtils {

/* Draws background of a given MovieClip with color, alpha and coner-radius. */
public static function drawBg(mc_button:MovieClip, w:Number, h:Number, radius:Number, bg_color:Number, param_alpha:Number):Void {
mc_button.beginFill(bg_color,param_alpha);
mc_button.lineStyle(2,0x000000);

mc_button.moveTo(0, 0);
mc_button.lineTo(w,0);
mc_button.lineTo(w,h);
mc_button.lineTo(0,h);
mc_button.lineTo(0,0);

mc_button.endFill();
}

public static function showError(param_title:String, msg:String):Void {
_root.clear();
for (var mcName in _root) {
_root[mcName].removeMoiveClip();
}
_root.createTextField("title",_root.getNextHighestDepth(),0,0,10,10);
var txt:TextField = _root["title"];
txt.autoSize = true;
txt.text = param_title;
_root.createTextField("msg",_root.getNextHighestDepth(),0,txt._height,10,10);
var txt2:TextField = _root["msg"];
txt2.autoSize = true;
txt2.text = msg;
}

/* Creates for each Trigger a MovieClip which can open a Popup when clicked. */
public static function createTriggerButtons(triggers:Array):Void {
for (var i = 0; i<triggers.length; i++) {
var t:Trigger = triggers[i];

var mc_trigger:MovieClip = bg.createEmptyMovieClip("trigger_button_"+t.tid, bg.getNextHighestDepth());
mc_trigger.createTextField("txt_trigger_button_"+t.tid,mc_trigger.getNextHighestDepth(),2,3,10,10) ;
var txt:TextField = mc_trigger["txt_trigger_button_"+t.tid];
txt.text = t.triggerName;
txt.autoSize = true;

var hClose:Number = txt._height+4;
var w:Number = txt._width+4;

DrawUtils.drawBg(mc_trigger,w,hClose,5,0x00FF00,10 );

mc_trigger._x = t.xPos;
mc_trigger._y = t.yPos;

mc_trigger.onRelease = function() {
var tid:Number = new Number(this._name.substring(this._name.lastIndexOf ("_")+1, this._name.length));
var t:Trigger;
var k:Number;
for (k=0; k<triggers.length; k++) {
if (triggers[k].tid.valueOf() == tid.valueOf()) {
t = triggers[k];
break;
}
}
ComUtils.createPopup(t.tid,t.triggerName);
};

}
}
}


Thanks

darthbane
03-26-2008, 12:30 PM
Hi,

I managed to bugfix the problem:

After instruction which take long time to execute, I inserted a pause function:

function pause() {
for (var i:Number = 0; i < 10; i++) {
Math.pow(Math.E, i);
}
}

// somewhere in the code:
txt.text = "Test";
pause();
txt.autoSize = true;
pause();
txt._x = 10;
txt._y = 20;


I think some of the instructions are beeing skiped if they take too long or the following instruction is skipped.

Often, when I create a TextField or something similar (autoText, setTextFormat, ...) the following instruction was skipped. Often, I draw the background of the TextField or I moved it around. So when positioning or drawing instructions are skipped, thats what I saw on the windows Mobile 5 device.

Hmm. I found nothing about skipping instruction or code on adobe.com.
I can remember that the instructions have to finish after 750ms??? Not sure about that. But I just have simple instructions like <i>autoSize = true</i> or <i>setTextFormat</i>.


I hope, no one of you has to develp for windows mobile or flash lite player on Windows Mobile!