Friday, October 2, 2009

Flex 3.4 Illegal override of FlexModuleFactory

An important note for those switching from Flex 3.2 to Flex 3.4


If you have css styles which were compiled (likely in FlexBuilder), you must re-compile them with the Flex 3.4 SDK to get rid of this error.

Line Causing Error

StyleManager.loadStyleDeclarations("yourexternalstyles.swf");

Exact Error Message

VerifyError: Error #1053: Illegal override of FlexModuleFactory in mx.core.FlexModuleFactory.

at global$init()

Tuesday, July 7, 2009

Help with "ref" and "out" in C# .NET 3.5 2008

In this article, I will discuss the out keyword and the ref keyword in C Sharp. These should be used sparingly but are handy in certain situations (especially when dealing with structs and sorting).

If you do not understand pointers yet, I would advise steering clear of these.


Similarities to other languages

Both "out" and "ref" mean pass the variable into the function "by reference".

If you are a VB6 guru, this is similar to the "ByRef" keyword.

If you're a C++ writer, you would use the address of operator "&" (if you did not already have a pointer to the object) and the function would have "*" following the data type.

There is no such modifier in Java.


What do they mean?

Out and ref extend the meaning of "by reference" by additionally stating that the variable must be initialized and will be modified (ref) or that it will be initialized inside of the function (out).

The default (no prefix to the parameter) is a "by value" copy of a structure/simple data type or a "read-only reference" of an object meaning you cannot change where it points to but you can change the variables inside of the class. This is how Java works.


The "ref" Parameter Modifier
  • "ref" is by reference
  • It does not give a compiler error if it was not passed in the argument list for the function
  • It gives you the ability to modify the pointer of the original object
  • It is a great way to pass structures around in code because it does not make a "by value" copy of them
  • Parameter must be initialized before calling the function
  • "ref" prefix exists when defining the function and when calling it (making it obvious that this is a by reference call)

Example of By-Reference Parameters in C#
public void SimpleSwap(ref String string1, ref String string2)
{
// store the pointer of string1
String temp = string1;
// set string1's pointer to point to string2
string1 = string2;
// set string2's pointer to point to string1 (HINT: this is not pointing to string2)
string2 = temp;
}

// ... code using this ...
String string1 = "ABC";
String string2 = "DEF";
SimpleSwap(ref string1, ref string2);

// string1 now points to "DEF"
// string2 now points to "ABC"


The "out" Parameter Modifier
  • "out" is by reference
  • The parameter must be assigned or you get a compile error
  • A new object is created and returned (the variable you passed in points to the one created inside of the function)
  • "out" parameters do not need to be initialized
  • This is a great way to fill structures
  • It allows the language to safely handle multiple return values without the need for new objects/structs
  • "out" prefix exists when defining the function and when calling it (making it obvious that this variable will be initialized by the function call)

Example of a Function Returning Multiple Values in C#
public void GetCoordinates(out int x, out int y)
{
x = 5;
y = 9;
}


// ... code using this ...
int x;
int y;

GetCoordinates(x,y);
// x is now 5
// y is now 9

Conclusion

Out and ref are great tools when you need them. I hope this article helps you understand more about how they work.

Note: I use the terms "keyword", "modifier", and "prefix" when discussing ref and out. The actual term (AFAIK) for these is "modifier".

Note: Code examples in this article are incomplete and will not compile. If you require complete examples, please leave a comment and I will post them for everyone.

Monday, June 8, 2009

Why can't I import javafx.ui.*?

The Answer for the Impatient (like me!)

Short answer for those who are impatient... see javafx.scene.layout.* and use something like HBox. Reason you ask? JavaFX 1.1 vs 1.2 had many non-backwards compatible changes.

Background

So I was trying out JavaFX with NetBeans 6.5.1 while I was waiting for a software build to complete. I created a simple project then wanted to do a more advanced component layout. I Googled "javafx positioning elements side by side" and noticed that many of the tutorials were importing javafx.ui.* to get BorderLayout. Looks great!

Absolute Positioning

Before I continue, here is my code which has a simple Text and an ImageView component:

/*
* Main.fx
*
* Created on Jun 8, 2009, 9:50:23 AM
*/

package javafxapplication1;

import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.text.Font;
import javafx.scene.image.Image;

import javafx.scene.image.ImageView;
import javafx.scene.text.Text;


/**
* @author graeme
*/

Stage {
title: "Flask"
width: 800
height: 600
scene: Scene {
content: [
Text {
font : Font {
size : 16
}
x: 10
y: 30
content: "Flask 0.01"
}
ImageView {
x: 10
y: 50
image: Image {
url: "{__DIR__}flask-2.jpg"
}
}
]
}

Adding the Infamous BorderLayout

I simply added BorderLayout inside of my scene content and did the old CTRL+SHIFT+I to fix imports and... nothing. Confused++

So I typed the import in manually and noticed it was not there. Confused++

I figured I had an old version of NetBeans. So I went to get NetBeans 6.7 RC2 and JavaFX is not available for it... Confused++

Maybe my Plugin was old...? I checked - nope! Brand new. Confused++

Here is the code that will not work in JavaFX 1.2 - I have bolded the reasons why:

/*
* Main.fx
*
* Created on Jun 8, 2009, 9:50:23 AM
*/

package javafxapplication1;

import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.text.Font;
import javafx.scene.image.Image;


import javafx.ui.*;

import javafx.scene.image.ImageView;
import javafx.scene.text.Text;


/**
* @author graeme
*/

Stage {
title: "Flask"
width: 800
height: 600
scene: Scene {
content: [
BorderLayout {
content: [
Text {
font : Font {
size : 16
}
content: "Flask 0.01"
}
ImageView {
image: Image {
url: "{__DIR__}flask-2.jpg"
}
}
]
}
]
}
}

Breaking Through the Confusion

So now that Confused = 4, I Googled once more. (Rhyming not intentional)

I read that many classes moved from javafx.ui.* to javafx.application.* then distributed somewhere inside to javafx.scene. This makes more sense!

So I found HBox and VBox (which are quite familiar to me in the Flex world) and gave those a shot. Worked like a charm!

Here is the code that will work in JavaFX 1.2:

/*
* Main.fx
*
* Created on Jun 8, 2009, 9:50:23 AM
*/

package javafxapplication1;

import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.text.Font;
import javafx.scene.image.Image;


import javafx.scene.layout.HBox;

import javafx.scene.image.ImageView;
import javafx.scene.text.Text;


/**
* @author graeme
*/

Stage {
title: "Flask"
width: 800
height: 600
scene: Scene {
content: [
HBox {
content: [
Text {
font : Font {
size : 16
}
content: "Flask 0.01"
}
ImageView {
image: Image {
url: "{__DIR__}flask-2.jpg"
}
}
]
}
]
}
}
Screenshot of NetBeans 6.5.1 Flask Example















References

Good ones:

http://java.sun.com/javafx/1/tutorials/ui/layout/index.html#hbox
http://java.sun.com/javafx/1/tutorials/ui/

Old ones:

http://www.ibm.com/developerworks/java/library/j-javafx/
http://www.informit.com/guides/content.aspx?g=java&seqNum=418

Friday, May 15, 2009

Websites in Midland

It's important to have great looking web pages. Many sites in Midland, Ontario (my home town) need a revitalization to bring out the quality, atmosphere, and appeal that the town and businesses of Midland offer in-person.

If you look around the internet, there are great looking websites and some older style ones. The difference? People tend to be more comfortable buying from amazing looking sites. See this article posted at A List Apart which visually demonstrates the importance for "eye candy" when presenting information and products to customers.

Do you want a great looking website in Midland? Head over to StyleMarks (a local web design and development company) for more information. StyleMarks offers polished looking websites without the hassle and at a reasonable price.