Monday, July 9, 2007

Frustrating Flex problems solved #1 - dropEnabled

I set up a drag-drop interaction between two components - from a custom 'dragMe' component i set up(extending Canvas) to a Tree component, but couldn't work out why my Tree wouldn't allow dragMe to drag over it. Until I started experimenting with removing properties from the Tree component. Eventually(this sort of trial and error can be soo slow going in flex) I found the source of the problem: i had dropEnabled set to true. huh? how unintuitive is that?!! as soon as i set dropEnabled to false(or left it out altogether because that's the default) the behaviour works fine.

After reading up on this property it does make sense - dropEnabled refers purely to the default drop behaviour. really defaultDropEnabled would be a more intuitively named property, but anyway i put this information out there for others not to waste the time i did yesterday!

Tuesday, July 3, 2007

line width

i was creating a dashed line function which basically drew a short line, then moved on a few pixels. i was trying to display this line with one pixel width. what i discovered was that if the dash was three pixels or less in length the width would increase to two pixels.?? have a look at this flex code(which assumes a Canvas component called 'canvas'), which displays several lines with the same linestyle, but with the length of each one increasing by one pixel:

import flash.geom.*
import flash.display.*
private function drawLine():void {,0x000000);
  for (var i:int;i<10;i++) {,(i*10));,(i*10));

what's that about? well i had a look at whether other lineStyle options had any effect and discovered pixelhinting. pixelhinting is a boolean that specifies whether to hint strokes to full pixels. you'd think that a straight horizontal line wouldn't require much in the way of hinting, but the player does seem to display it incorrectly. perhaps short lines confuses it?

anyway, to resolve this issue, add pixelhinting to the lineStyle:,0x000000,1.0,true);