Friday, January 30, 2009

Logging

xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
initialize="init()">

import mx.logging.LogEventLevel;
import mx.logging.targets.TraceTarget;
import mx.logging.ILogger;
import mx.logging.Log;
import mx.logging.LogLogger;

/*
* This is a sample application that uses a simple logger. There are 4 simple
* steps to using it:
* 1. Get an Instance of ILogger, with the appropriate category
* (Done in each class)
*
* 2. Define a Target and set it's properties
* (Done only once when initializing the logging API)
*
* 3. Add the target to Logging runtime
* (Done only once when initializing the logging API)
*
* 4. Use the instance of ILogger to log messages
*/

// 1. Get an Instance of ILogger, with the appropriate category
private var _log:ILogger = Log.getLogger("mx.com.yahoo.com");

// Initialize the remote logger
// import to do this on the application's initialize callback if you want to log
// the construction of your application's child component's
private function init():void {
// 2. Define a Target and set it's properties
var target:TraceTarget = new TraceTarget();
target.includeCategory=true;
target.includeDate=true;
target.includeLevel=true;
target.includeTime=true;
target.level=LogEventLevel.INFO;

// 3. Add the target to Logging runtime
Log.addTarget(target);
trace("Hello World");

}
//4. Use the instance of ILogger to log messages
private function sendDebugMessage():void {
_log.debug("This is a test debug level log message");
}

private function sendInfoMessage():void {
_log.info("This is a test info level log message");
}

private function sendWarnMessage():void {
_log.warn("This is a test warn level log message");
}

private function sendErrorMessage():void {
_log.error("This is a test error level log message");
}
]]>


]]>

CorssDomain in Flash Player 10 and 9

The cross domain works differently in flash player 10 and 9.

Sceanrio:
A swf file at location http://url2/Sow.swf make a request to the http://url1:9085/SOW_DSVServices/. As both the files are in different domain, crossdomain.xml file is required.

Flash Player 10.
In flash player 10, crossdomain is required at two location.
1.
http://url1:9085/SOW_DSVServices/crossdomain.xml
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy
SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-access-from domain="*" />
</cross-domain-policy>
2.
http://url1:9085/crossdomain.xml
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy
SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<site-control permitted-cross-domain-policies="all"/>
</cross-domain-policy>

3.
In swf file code you have to loadPolicyFile
Security.loadPolicyFile("http://url1:9085/SOW_DSVServices/crossdomain.xml");

While in the case of Flash Player 9, crossdomain.xml file is required at only one location
1.
http://url1:9085/SOW_DSVServices/crossdomain.xml
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy
SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-access-from domain="*" />
</cross-domain-policy>

2.
In swf file code you have to loadPolicyFile
Security.loadPolicyFile("http://url1:9085/SOW_DSVServices/crossdomain.xml");
3.
CrossDomain.xml file is not required at location
http://url1:9085/crossdomain.xml

This is due to the more security enchancement in flash player 10.

Monday, January 26, 2009

Force Browser to get new version of cached swf file

How to make the request to server only if new version of swf file?

It is very common opportunity, that whenever any new changes are made to the swf file it does not load into the browser as swf is already in browser
cache. At the sametime, you do not want to make the request every time to the server when swf file is accessed. You want to make the request to server only if new version of file is on server. To get rid of the issue, follow the steps.

In the file AC_OETags.js, inside function AC_GetArgs

1.
modify the statement : args[i+1] = AC_AddExtension(args[i+1], ext);
to : args[i+1] = AC_AddExtension(args[i+1], ext+"?v="+appVersion);


2.
add case statement

case "appversion":
appVersion = args[i+1];
break;

3.add global variable in the AC_OETags.js
//Application Version
var appVersion = '1';

Now changes in the .html file where flex swf is embedded
4. Modify the function in the

AC_FL_RunContent(
"appversion", applicationVersion,
"src", "Sow",
"width", "100%",
"height", "100%",
"align", "middle",
"id", "Sow",
"quality", "high",
"bgcolor", "#869ca7",
"name", "Sow",
"allowScriptAccess","sameDomain",
"type", "application/x-shockwave-flash",
"pluginspage", "http://www.adobe.com/go/getflashplayer"
);


5. Declare the
//Application Version
var applicationVersion =

Conclusion:
Every time a new version of swf comes , change the "applicationVersion". In the below request there will always be new version value which will force browser to make request to the webserver
If you see the request it will be
http:///SOW/Sow.swf?v=2.0.0

Saturday, January 24, 2009

Links

Flex Coders yahoo group

Icons

Charts Sample

Flex Styles Explorer

Flex Regular Expression Explorer

Easing Function Calculator

Flex Developer General

Styles Website

Tips for Style Manager

In the style sheet(.css file) declare
.icons
{
add: Embed('images/add.png')
mul: Embed('images/mul.png')
}

icon="{StyleManager.getStyleDeclarations('.icons').getStyle('add')}"
label="Customize" />