Archive for the ‘Flex’ category

[Modules] Check if class implements interface

October 2nd, 2011

Problem:

I have module that implements my interface:

class MyModule extends ModuleBase implmenets IMyInterface
{
...
}

After loading module from external file:

var moduleInfo:IModuleInfo = ModuleManager.getModule('module_path.swf');
moduleInfo.addEventListener(ModuleEvent.READY, this_READY );
moduleInfo.load(null,null,null ,FlexGlobals.topLevelApplication.moduleFactory);

And creating module object:

private function this_READY( moduleEvent:ModuleEvent ):void {
var moduleInfo:IModuleInfo = moduleEvent.module;
var m:Object = moduleInfo.factory.create();
}

The expression:

m is IMyInterface;

returns false instead of true.

 

Solution:

The solution for this problem is following:

After creating the module object using factory, we must use the expression presented above. I do not know why, but after the first use of this expression or casting (operator as) it behaves right.

Therefore we must add the following line:

private function this_READY( moduleEvent:ModuleEvent ):void {
var moduleInfo:IModuleInfo = moduleEvent.module;
var m:Object = moduleInfo.factory.create();

m is IMyInterface;
}

It looks like error in Flex for me, as I cannot find an explanation for it.

Two way data binding

September 23rd, 2011

If you bind a variable to some component’s property by just adding [Bindable] metatag above it you may notice that component’s property changes when variable changes but it doesn’t work in the opposite direction. So what to do in order to achieve to way data binding? » Read more: Two way data binding

png2swf: a way to keep transparency and small PNG file size

August 7th, 2011

png2swf utility is a part of SWFTools package. It is capable of converting PNG to SWF format and it can really save your life if you are in need of having small PNG files. » Read more: png2swf: a way to keep transparency and small PNG file size

Embeding assets

July 14th, 2011

Embeding assets allows you to complie some external data into your SWF file.

There are two ways of doing it. In first of them you create ActionScript Class object embeding your resource:

[Embed(source="image.png", mimeType="image/png")]
public var ImageClass:Class;

and use it MXML tag:

<s:Image source="{ImageClass}"/>

The other way is to embed your resource directly in MXML tag:

<s:Image source="@Embed(source='image.png')" />

How to disable databinding warnings?

July 14th, 2011

Sometimes when you put a variable into MXML tag you get a warning: “Data binding will not be able to detect assignments to …”. You can get rid of it by making your variable bindable but what if you are completly sure that the variable will not change and you don’t want to make it bindable?

In order to turn off all annoying warnings at once you can add the following code to your compiler options:

-show-binding-warnings="false"

The second solution is to add the following tag:

[Bindable("__NoChangeEvent__")]

before each variable you don’t want to be bindable and to be source of the warning.

How to capture image from web camera?

July 9th, 2011

If you have a web camera connected to your computer and you want to capture image from it then in the following text you will see how to do it.
» Read more: How to capture image from web camera?

Localizing Flex Applications (static)

July 2nd, 2011

Localization is a process of adapting an application to a particular language. Flex offers it’s own tools and techniques to make this feature available. Localization can be done statically or dynamically. This post describes how to localize an apllication statically, which means that nobody will be able to change localized strings after compilation.
» Read more: Localizing Flex Applications (static)

How to regenerate html-template in Flash Builder

July 2nd, 2011

Recently I have accidentally deleted “html-template” folder from one of my projects and I needed to restore it. Here is how I did it:

  1. Open project’s properties window.
  2. Go to “Flex Complier”.
  3. Under “HTML wrapper” uncheck “Generate HTML wrapper file” and click “Apply”.
  4. Check “Generate HTML wrapper file” and click “Apply”.

After that you should have “html-template” folder generated in you project.

FlexPrintJob makes printed component disappear

April 26th, 2011

When I was testing some piece of code which was responsible for printing a component I found out that if I cancel a printing dialog box the component disappers. I didn’t put much attention to this problem and I don’t know why exactly it happend but I found a solution. To prevent component from disappering you need to cancel printing procedure if start method form FlexPrintJob class returns false.

var printJob:FlexPrintJob = new FlexPrintJob();
if (printJob.start() != true)
    return;
printJob.addObject(someUIComponent, FlexPrintJobScaleType.SHOW_ALL);
printJob.send();

Własna czcionka i przycisk (button)

May 31st, 2010

Dzisiaj spotkałem się z problemem podczas wstawiania do aplikacji własnej embeed’owanej czcionki. Robi się to w CSSie w ten sposób:

@font-face {
src: url("../fonts/moja-czcionka.ttf");
fontFamily: MyFont;
}

Następnie w prosty sposób można ustawić czcionke dla np. Aplikacji:

Application {
fontFamily: MyFont;
}

Do tej pory wszystko działa bez zarzutu. Jednak, gdy ustawiałem czcionke dla przycisku:

Button {
fontFamily: MyFont;
}

no to coś nie grało, bo czcionka nie pojawiała się. Była to zwykła polska czcionka:

  • styl – normalny
  • grubość – normalna

Okazało się, że problemem był fakt, że Flex jako domyślną grubość czcionki dla przycisków ustawia bold, a moja czcionka była normalnej grubości. Stąd, po dodaniu jednej linijki do stylu przycisku:

Button {
fontFamily: MyFont;
fontWeight: normal;
}

wszystko działało. Trochę mnie zdenerwowała taka błahostka, bo spędziłem nad nią trochę czasu, dlatego mam nadzieje, że ten wpis go komuś zaoszczędzi.

Flexmaniaks on Facebook