Notes on Java, Solaris, PHP, LDAP…

July 20, 2009

Error blackhole in Adobe Flex or SWF player

Filed under: Uncategorized — negev @ 1:34 pm
Tags:

So you have an Adobe Flex application that uses GUI states. You get back to it after a longer period, and you need to fine-tune details. You need to set initial properties of some GUI controls for some situations. You already had an initialization function, so you just do it there. Then you run it, and the code just stops where you changed it. No error and no execution. You try the debug SWF player, same thing.

That’s when you access a GUI control, which wasn’t created yet. It happens if your control is added in a GUI state, but the component didn’t enter that state yet. Like if in the following you want to set contactMe.selected before you switch your component to “extendedForm“.

<mx:states>
<mx:State name=”extendedForm”>
<mx:AddChild position=”lastChild”>
<mx:CheckBox id=”contactMe” x=”10″ y=”216″ label=”Would you like us to contact you about our new products? Maximum 4 times a year.” />
</mx:AddChild>
</mx:State>
</mx:states>

Adobe Flex or SWF player should really report this as a null exception or some other meaningful error.

I reported it at Flex bugs site.

August 21, 2008

Weird Flex states

Filed under: Java — negev @ 6:06 pm
Tags:

I had a weird experience with Flex states in Flex 2.0.1. My component had an initialization function. That set currentState to one of two values depending on something. Later on in the same function it checked for a few rare situations, and if any of those occurred then it set currentState to some special values.

Somehow Flex or Flash player didn’t like that and it rendered the 2nd (special/rare) state on top of the 1st state. Solution: instead of setting currentState directly, set some temp variable e.g. state:String. Then once state doesn’t change assign it to currentState. Note that you can’t use any GUI objects specific to that state before you switch to it.

December 11, 2007

Conflicts between Flex properties and component ids

Filed under: Uncategorized — negev @ 12:45 pm
Tags:

Today I’ve been extending mx:TitleWindow component. And I wanted to have a TextInput called ‘name’. However, when I added

  <mx:TextInput id="name" ... />

then I was getting funny errors like

Attempting to initialize inherited property 'name' of type 'String'
with value of incompatible type 'mx.controls.TextInput'

You can define and access visual subcomponents in Flex MXML very easily. They are almost equivalent to properties and subcomponents defined via Action Script. Adobe standard components and classes have plenty of properties and methods. However, that is a double-sided sward – because you may want to use the same property name or subcomponent id for something else, and you just can’t.

Solution: You can put your properties into a separate object, or separate them in some other way. Or call your properties/subcomponents by some other name.

December 4, 2007

Surprises of Flex operators

Filed under: Uncategorized — negev @ 7:17 pm
Tags:

Flex operator == is a funny one. You won’t get much info on its behaviour in Flex docs. But it turns out that

  • it compares Strings by value
  • but it compares arrays by reference
    • the same for ‘non-primitive objects’ (never mind the non-sense) – compared by reference

November 23, 2007

Filed under: Uncategorized — negev @ 3:57 pm
Tags: ,

I’ve learned how to configure SSL for Apache 1.3 on Mac OS X: http://www.macosxhints.com/article.php?story=20041129143420344
I’ve found two errors in Flex/Flash:

November 21, 2007

File uploads with Apache/PHP and Flex; TCP dump

Filed under: Uncategorized — negev @ 6:44 pm
Tags: , ,

File upload with Apache/PHP
– if your HTML form has a hidden input MAX_FILE_SIZE and you submit a file bigger than that, you won’t get any warning by the browser, and the file won’t be submitted to the server!

File upload in Flex using FileReference
– the file size must be above 0!

TCP dump filtering
sudo tcpdump -i en0 -s 0 -w csv_processing_tcpdump.dmp
-s 0 => print whole packets

tcpdump -s 0 -n -e -A -vvv -r DumpFile.dmp host ip-of-the-target-host
-A => prints packet in ASCII

November 17, 2007

Adobe Flex and MXML

Filed under: Uncategorized — negev @ 8:46 pm
Tags:

Flex public variables in Action Script act as ‘global’ variables – potential for spaghetti code

Popup windows in Flex
http://livedocs.adobe.com/flex/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000701.html

Flex 2 Metadata Tags[Bindable] etc
http://mxdj.sys-con.com/read/361239.htm

Non-visual components in Flex – in Action Script or MXML:

http://www.nabble.com/Simple-design-question-t3416123.html
“If all they need is a container for nonvisual components that is
itself a nonvisual component, then just create one that extends
IMXMLObject that accepts any other IMXLObjects as children.

But really, I would recomend doing as much as possible in AS anyway.
AS is going to compile faster so your build times will be shorter. AS
code is easier to debug. And expanding ActionScript skills will only
help you be a better flex developer.”

Polarion – SVN plugin for IDE

26 Apr 07
diff
–ignore-blank-lines –side-by-side –left-column –minimal –width=180

Flex custom centered/positioned renderer
– we want a custom ‘dynamic’ renderer, which shows a picture that depends on data row
– we want it to be horizontally centered
— we cannot center it by padding because it’s used in a DataGrid where width of columns can be resized
— we cannot set alignment in CSS – see http://livedocs.adobe.com/flex/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000761.html#164917
– following uses embedded images; or uncomment the image names and remove the embedded variables
– don’t use override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void in mx:Image because it’s invoked too frequently – every time you move a mouse over the Data Grid.

<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Box xmlns:mx=”http://www.adobe.com/2006/mxml&#8221; direction=”horizontal” horizontalAlign=”center” verticalAlign=”middle” >
<!– By some good magic of Flex he ‘source’ handler in the following mx:Image gets ‘data’ parameter.
However, the actual renderer object is the outer mx:Box and this mx:Image is only a component of it.
–>
<mx:Image id=”image” source=”{getSourceName(data)}” >
<mx:Script>
<![CDATA[
[Embed(source=”deploy/resources/admin.gif”)]
private var admin_star :Class;
[Embed(source=”deploy/resources/not-admin.gif”)]
private var admin_blank :Class;

private function getSourceName(data: Object): Object {
if( data.is_admin ) {
return admin_star; //”resources/admin.gif”;
}
else
return admin_blank; //”resources/not-admin.gif”;
}
]]>
</mx:Script>
</mx:Image>
</mx:Box>

Double-click handling in Flex:
<!– If we handle double clicks for data grid, which would display detailed info on user
– same as selecting a user and pressing an info button –
then we can’t handle both single clicks and double clicks. If we have handlers for both
then double click handler is ignored.
doubleClick=”Alert.show(‘double click’)” doubleClickEnabled=”true”
==> set doubleClickEnabled

CSS properties supported by Flex:
The actual set depends on current Theme – http://livedocs.adobe.com/flex/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000761.html#190648
List of supported properties – from http://livedocs.adobe.com/flex/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000761.html#164917

  • color
  • fontFamily
  • fontSize
  • fontStyle
  • fontWeight
  • paddingBottom
  • paddingLeft
  • paddingRight
  • paddingTop
  • textAlign
  • textDecoration
  • textIndent

Flickering Adobe Flex custom renderer for DataGrid

Filed under: Uncategorized — negev @ 8:22 pm
Tags:

Data grid render which knows what column it’s rendering:
It is supposed to do the same job as the previous renderer – it renders columns lines differently if the data row has ‘is_admin’ field set. However, the following renderer is flickering!

package {
import mx.controls.DataGrid;
import mx.controls.dataGridClasses.DataGridItemRenderer;
import mx.controls.dataGridClasses.DataGridListData;
import mx.controls.Text;
import mx.controls.dataGridClasses.DataGridColumn;

public class MemberRenderer extends DataGridItemRenderer {
public function MemberRenderer() { super(); }
private var lastUID:String; // the last thing we rendered

override public function set data(value:Object):void {
super.data = value;

if (listData && listData.uid != lastUID) {
//styleChanged(“color”);
var dgListData:DataGridListData = listData as DataGridListData;
var dataGrid:DataGrid = dgListData.owner as DataGrid;
var column:DataGridColumn = dataGrid.columns[dgListData.columnIndex];

if (value.is_admin == true) {
styleName = “adminStyle”;
}
text = data[column.dataField];
lastUID = listData.uid;
}
}
}
}

Adobe Flex – ActionScript language features, sorting by columns in mx:DataGrid

Filed under: Uncategorized — negev @ 8:15 pm
Tags:

20 Apr 07
Notes on Action Script
1. It’s both statically & dynamically typed
If you access an object/component stored in a variable, and that variable is typed to that appropriate class, then Flex IDE gives you field/method hints as you type. So if you have var array:Array; and you type array. then it shows you a list of methods – Flex retrieves them from static type. However, even if you have a variable statically typed, Flex allows you to type and compile fields/methods which are not supported by that static type – because Flex allows dynamical typing, PHP-like.

So I can use a method/property which is not declared by the variable’s static type. However, if the actual runtime type of the variable won’t be right and there’s no such a method/property in runtime, then debug SWF fails and opens Flex in debug mode. However, live SWF quietly stops the current event without any message.

So maybe we could use a global error handler, which would catch such quiet errors in live, would send them to server and log or report them. Obviously, we don’t want to use such a handler for connectivity errors otherwise it would go recursive.

2. Objects are assigned by reference. However, Flex API getters/setters of API properties most likely use protective copies. If you store a result of a property, e.g. mx.controls.Tree’s openItems and you modify it (e.g. by calling push(..) on it) that won’t be reflected in the view, and you can see that myTree.openItems will be different to openItems copy you just modified. So after you apply any modifications, you need to save it by invoking the setter – myTree.openItems= theModifiedCopy. E.g.

var openItemsCopy:Object= groupList.adminGroupsTree.openItems; // openItems is probably of type Array, but Flex doesn’t document that.
if( openItemsCopy.indexOf(groupsNode) <0 ) {
openItemsCopy.push( groupsNode ); // This doesn’t refresh the tree; we need to set it to kick it in:
groupList.adminGroupsTree.openItems= openItemsCopy;
}

3. ‘for in ‘ and ‘for each in’ are quite different loops. Use ‘for in’ to iterate over Object’s field names and Array keys (indices). Use ‘for each in’ to iterate over entries (values) of Array and collections e.g. ArrayCollection.

for( var fieldName:String in myObject ) {

var fieldValue:Object= myObject[fieldName]
Alert.show( fieldName+ “: ” +fieldValue );
}

for each( var entry:Object in myCollection) {
Alert.show( entry );
}

19 Apr 07
Although Flex performs static type check whenever static types are known, it’s not 100%. It compiles the following, although there’s no Array.contains(*) method
var memberListEmails: Array= baseApp.memberList.memberListEmails;
if( memberListEmails.contains(myObject) ) {…}

18 April 07
Flex sorting by columns in mx:DataGrid
When using a renderer, either parameterized via an implementation of mx.core.IFactory, or non-parameterized, then it accesses data fields via Action Script. That is case-insensitive to the field name. E.g. field can be ‘fullName’ or ‘fullname’ and you get the entries rendered fine by <mx:Text xmlns:mx=”http://www.adobe.com/2006/mxml&#8221; text=”{data[field]}”

However, when trying to sort entries by such a column, you must pass it exact case-sensitive to <mx:DataGridColumn dataField=”fullname”… Otherwise sorting by that column won’t work, but entries will be still rendered.

Using Flex with Subversion on Mac OS X or Linux

Filed under: Uncategorized — negev @ 8:06 pm
Tags: , ,

4 April 07
Flex and Subversion
Flex performs SVN housekeeping even without Subclipse being installed. If you delete a directory which is SVN-controlled and it has entry in its parent directory’s .svn, then Flex recreates that deleted directory.

Also, if new MXML files were added to a project while Flex was turned off and if those files have any compile-time error, then next time Flex will be building the project it doesn’t generate any SWF and it *doesn’t* display any error.
Solution: create new empty MXML files using Flex menu; turn off Flex, copy the actual files over, turn on Flex.

Separate Flex and web folders
Because of the above issues, I’ve separated Flex folder:
1. I’ve checked out on commandline to ~/TLGM2_svn
2. In Flex I’ve created a plain Flex project under ~/TLGM2
— the project itself is local only and it isn’t SVN-controlled

3. build the project – otherwise it may not build once you add new files
4. close Flex

5.
cd TLGM2
# Following are hard-links, not symbolic links
ln ../TLGM2_svn/TLGM2.mxml

cd deploy
ln ../../TLGM2_svn/bin/TLGM2.swf

6. Start Flex, use it
7. svn on commandline under TLGM2_svn

If we go this way, then we need to adjust locations of any embedded resources. Right now I’m using the following adjustment to TLGM2.mxml:
– <mx:Button id=”showGroupButton” fontSize=”8″ width=”25″ click=”show_hide_Groups()” height=”78″ labelPlacement=”left” textAlign=”left” icon=”@Embed(‘deploy/resources/groups.gif’)”/>
+ <mx:Button id=”showGroupButton” fontSize=”8″ width=”25″ click=”show_hide_Groups()” height=”78″ labelPlacement=”left” textAlign=”left” icon=”@Embed(‘../TLGM2_svn/deploy/resources/groups.gif’)”/>

Probably rather than using ‘TLGM2’ and ‘TLGM2_svn’ it would be easier to have trunk/TLGM2 which would be checked out from SVN and trunk/Flex which wouldn’t be under SVN. Then resources would point at e.g. ../TLGM2/deploy/resources/groups.gif

This way if Flex gets better and we’ll use it direct on SVN-controlled trunk/TLGM2 rather than on non-SVN local trunk/Flex, then the resource locations would work unmodified.

I have had one issue when I modified same TLGM2.mxml in both Flex and via commandline svn. But I believe that was because I didn’t do a hard link, but I copied the file while experimenting – this way the file was duplicated rather than hard linked.

Formatting whole row in DataGrid

There are about 3 different types of specifying a renderer for a DataGridColumn:
1. Fully customized, but you need to copy and paste it for every column and to change {data.mail} appropriately:
<mx:DataGridColumn dataField=”mail” headerText=”Email Address”>
<mx:itemRenderer>
<mx:Component>
<mx:Text text=”{data.mail}” styleName=”{data.hasOwnProperty(‘is_admin’) ? ‘adminStyle’ : ” }” />
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>

2. Using a component – in this case defined in MemberRenderer.mxml – which gets instantiated behind the scenes; however it can’t be parameterized and therefore you need one component per column
<mx:DataGridColumn dataField=”mail” headerText=”Email Address” itemRenderer=”MemberRenderer” />

3. Parameterized renderer, which gets created behind the scenes via implementation (subclass) of mx.core.IFactory:
<mx:DataGridColumn dataField=”fullName” headerText=”Full Name” itemRenderer=”{new utils.MemberRendererFactory(‘fullName’)}” />

I’ve tried to somehow retrieve DataGridColumn’s dataField in the renderer object, so that we could use option (2) without using IFactory. However, the rendered components can’t access DataGridColumn.

How I’ve tried it: In renderer’s text=”{expression}” I invoked a local function, in which I called Alert.show( “parent: ” +parent.toString()+ “, owner: ” +owner.toString() ) Those showed that the parent element is ListBaseContentHolder and owner element is DataGrid.

2 April 07
Flex mx:Model – they can’t be used in initial values for variables. Use them only once the app/component was initialized – in creationComplete handler.
public var memberListData:ArrayCollection; // = new ArrayCollection( memberListModel.item ); // – this assignment fails
Flex <mx:DataGrid dataProvider=”{myDataSourceVariable}” ..> — myDataSourceVariable doesn’t need to have any initial value, then an empty DataGrid is shown
with any columns defined in its body in mx:columns
mx.Text (and its parent mx.Label) has htmlText attribute, but in order to get it used in DataGrid we need a renderer anyway

You can use any custom component for mx:DataGridColumn itemRenderer property.
If you’d like to add extra bindable variables, you define them in mx:Script within body of the component tag.

If you’re not using a custom component as a renderer, then you need to have <mx:itemRenderer><mx:Component> and the actual visible items within them, e.g. <mx:itemRenderer><mx:Component><mx:Text text=”{data.cn}” /></mx:Component></mx:itemRenderer>

Next Page »

Blog at WordPress.com.