Archive

Archive for the ‘FLEX’ Category

FLEX : Creating RemoteObject Channel Set for WEBORB or LCDS in ActionScript

March 2nd, 2009

I have been having some issues when running multiple WebOrb instances (usually because of a different authentication scheme) where if I start using one destination and then switch to another, my SWF gets confused, and dose no know which remote instance to get execute the remote object at.

To combat the issue, i started hard coding my channel information for each instance, and I honestly like it more. I no longer need to clean my projects every time I make a change, and I always know where my .swf is pointing.

Like it or leave it, here is how its done.

import mx.rpc.remoting.RemoteObject;
import mx.messaging.Channel;
import mx.messaging.ChannelSet;
import mx.messaging.channels.AMFChannel;

    private function init() : void {
        remoteObject  = new RemoteObject("GenericDestination");
        var cs:ChannelSet = new ChannelSet();
        var customChannel:Channel = new AMFChannel("my-channel", "http://myurl:80/WebOrbK/weborb.aspx");
        cs.addChannel(customChannel);
        remoteObject.channelSet = cs;
        remoteObject.destination = "my-destination";
        remoteObject.source = "MyNameSpace.MyClass";

        //Probably would add remote object listeners here.
        }

Greg Actionscript, FLEX, WEBORB

Merge Flex Data Visualization Components with Open Source SDK

February 17th, 2009

If your application uses Flex Builder Professional features such as data visualization components or automated testing, you will need to copy those elements from the latest milestone SDK that came with Flex Builder into your newly downloaded SDK. The relevant files that you need to copy are:

{FlexSDKDir}/frameworks/libs/automation*.swc

{FlexSDKDir}/frameworks/libs/datavisualization.swc

{FlexSDKDir}/frameworks/locale/en_US/automation*.swc

{FlexSDKDir}/frameworks/locale/en_US/datavisualization_rb.swc

{FlexSDKDir}/frameworks/locale/ja_JP/automation*.swc

{FlexSDKDir}/frameworks/locale/ja_JP/datavisualization_rb.swc

{FlexSDKDir}/frameworks/rsls/datavisualization_3.0.0.* (or updated build numbers for later builds)

 {FlexSDKDir}/fbpro (source)

In order to get the source code you will need to run the following command java -jar DMV-source.jar {license-file-location} {output-location}

Greg FLEX

1119: Access of possibly undefined property grid through a reference with static type mx.core:Container

February 17th, 2009

The Actual error for me was 1119: Access of possibly undefined property grid through a reference with static type mx.core:Container. And was actually a pretty simple one to solve. Like always, I hacked at it for an hour and then when I finally got it, I smacked my self in the forehead….duh! I’m not really sure why this happens, but it appears to be something with a custom component. In my case I had a VBox that I was extending and it was called Subject. In the VBox and Advanced Datagrid existed which I was trying to get the columns for so that I could use actionscript to add a column. so to get the columns I was doing.

var cols:Array = this.TabNavigator.selectedChild.grid.columns as Array; //where grid is my ADG<br />

This gave me the error, so to work around it, I chopped the object (i.e the datagrid off) Made the changes, and then put it back together. Here is my code line for line. As always comments or other work arounds are welcome.

var obj:Object = this.stn.selectedChild;
var cols:Array = obj.grid.columns;
var col:AdvancedDataGridColumn = newAdvancedDataGridColumn();
col.headerText = "My Column";
col.dataField = "mycol";
cols.push(col);
obj.grid.columns = cols;
this.stn.selectedChild = obj as Subject;

Greg FLEX

Using Weborb Generated Code in Actionscript

January 19th, 2009

WebOrb has an excellent feature built in which allows you to generate Actionscript/Flex code from you deployed Java or .Net objects.  The example on their website shows you how to use this code in MXML but not in actionscript. However, it is quite simple. Here is an example function I have used below.

//Dashboard Settings

[Bindable]

private var swooshmodel:swooshModel = new swooshModel();

private var swooshProxy:swoosh;

private function LoadUserSettings () : void 

{ 

// Create a Responder for the call 

var responder:mx.rpc.Responder = new mx.rpc.Responder(OnUserSettings,onFault);

this.swooshProxy = new swoosh( swooshmodel ); 

swooshProxy.getUserSettings(responder); 

}

private function OnUserSettings (e:ResultEvent) : void 

{ }

Greg FLEX, WEBORB

Flex 3 AdvancedDatagrid cannot convert mx.managers::DragManagerImpl to mx.managers.IDragManager

August 5th, 2008

I was getting this error when clicking my AdvancedDatagrid. This only seemed to occur after converting the app to a module.

The answer to the problem was to add the following to your main application.
Hope this helps you spend a lot less time than I did resolving the problem :)

import mx.managers.IDragManager;
private var iDragManager:IDragManager;

Here is the exact error message:
TypeError: Error #1034: Type Coercion failed: cannot convert mx.managers::DragManagerImpl@2256be49 to mx.managers.IDragManager.
at mx.managers::DragManager$/get impl()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\managers\DragManager.as:152]
at mx.managers::DragManager$/get isDragging()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\managers\DragManager.as:187]
at mx.controls.listClasses::AdvancedListBase/dragScroll()[C:\Work\flex\dmv_automation\projects\datavisualisation\src\mx\controls\listClasses\AdvancedListBase.as:6617]
at Function/http://adobe.com/AS3/2006/builtin::apply()
at ()
at SetIntervalTimer/onTimer()
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()

Greg FLEX , , , ,

FLEX 3 Catch Browser Exit or Close Event using Javascript and ExternalInterface

July 30th, 2008

Well after doing a bunch of searching and hacking away, I have managed to come up with a solution!

What I wanted was to set a variable when a change was made in my Flex application. (In my case it meant that a new module was loaded to my dashboard application) This way if a user loaded or deleted a module, the app would save their environment to a Shared Object.
Originally I had it was saving automatically, but user feedback said, only if I want to. This led me to prompting them when the close, but only if something has changed.

Here is how I did it:

First I declare a Bindable variable up at the top of my code (oh also import ExternalInterface)

import flash.external.ExternalInterface;
[Bindable] private var saveRequired:Boolean;

Second in my creationcomplete Event called init(), I add a callback to the ExternalInterface like so:

 private function init():void
		 {
          		if ( ExternalInterface.available ) {       			

          			ExternalInterface.addCallback("checkForUnsavedData",function():String {
          				if (saveRequired ) {
          					unsavedAlert();
          					return UNSAVED_DATA_WARNING;
          				}
						else return "";
					});
          		}
		 }

The following 2 functions are added to handle the Alert when the Javascript kicks off

private function unsavedAlert():void {
           Alert.show("Save?", "Save Alert", Alert.YES|Alert.NO ,this,SaveAlertHandler,null,Alert.YES);
          }

		private function SaveAlertHandler(e:CloseEvent):void {
		  	    if (e.detail == Alert.YES) {
		  	   		 setLSO();
		  	    }
		  	    saveRequired = new Boolean;
		  }

When you determine that a save is required set the variable saveRequired to anything. I wanted it to be a reminder when I went back to debug, so mine look like this…

saveRequired = "Popup on Browser Exit";

Finally….add this code between in your ./html-template/index.template.html

 <script language="JavaScript" type="text/javascript">
<!--
//alert(navigator.appName);
// Give user a chance to save modified data
window.onbeforeunload = function () {

	var warning = getFlexApp('SharedObjectBoard').checkForUnsavedData();
	if (warning != "")
		return warning;
	else
	return;
}

function getFlexApp(appName) {
  if (navigator.appName.indexOf ("Microsoft") !=-1) {
    return window[appName];
	alert(appName);
  }
  else {
    return document[appName];
	}
}
 -->
</script>

Greg FLEX

FLEX 3 Custom Event Listener with Popup window

July 1st, 2008

Create the custom Event.

In this case I will need to pass an object along with the event.
Save the actionscript as ParseFixClickEvent.as
package modules.FIXParser.Events
{
import flash.events.Event;
 
public class ParseFixClickEvent extends Event
{
public var params:Object;
public static const PARSE:String = “parseEvent”;
public function ParseFixClickEvent(params:Object, type:String )
{
super(type);
this.params = params;
}
public override function clone():Event {      
     return new ParseFixClickEvent(params,type);
    }
public override function toString():String
  {
   return formatToString(”ParseFixClickEvent”,”type”);
  }
}
}
 
 
In my case I have a datagrid, where if I click an item in column 3, I fire an event that creates a popup window.
Here it is:
 
private function itemClickEvent( event:ListEvent ):void
{
            //loglink.visible = “true”;
            //details.visible = “true”;
            if (event.columnIndex == 2) {
            logdir = event.itemRenderer.data.rmi_ip;
            logserver = event.itemRenderer.data.Cluster_Name;
            var parseWindow:ParseFixForm = ParseFixForm(PopUpManager.createPopUp(this, ParseFixForm, true));       
        parseWindow.addEventListener(modules.FIXParser.Events.ParseFixClickEvent.PARSE,doParse);
        parseWindow.mylogdir = logdir;
        parseWindow.myserver = logserver;
        parseWindow.target = event.itemRenderer.data.CounterpartyCompID;
        parseWindow.sender = event.itemRenderer.data.CompID;
        CurrentDestination = event.itemRenderer.data.DestinationName;
       
}
 
When the event is fired from the popup, doParse is called.
 
public function doParse(e:ParseFixClickEvent):void {
var Parser:FIXParser = new FIXParser;
Parser.FixParameters = e.params;
Parser.label = CurrentDestination;
TN.addChild(Parser);
TN.selectedIndex = TN.numChildren - 1;
}

Greg FLEX

Dividend Reinvestment Calculator

May 15th, 2008

I have been a moderate investor in Dividend Reinvestment Plans. aka (DRIPS) If you are not sure what that is, check out http://www.fool.com/school/drips.htm as they do a pretty good job explaining it.

But basically it allows investors to buy shares of a particular equity on a periodic basis (bi-weekly, monthly,quarterly etc). Dividends on that equitiy are automatically reinvested when they are distributed, thus buying fractional shares of the company.

My calculator below simulate a DRIP over time.

View code
Title: DRIP Calculator
Description: Click the link to see it full screen

I have not found a tool out there that really tracks how a stock + dividend reinvestment performs over time. So I wrote this little tool to track it. You can find it at http://www.gregjessup.com/DRIP If you know of something similar, please post a comment with the link. If you think my math is wrong, also post a comment and challenge me.

If you want to see some changes made to it, send me an email. I’ll have a look and try to post a change.

Happy DRIPing!

By the way..This is by no means guaranteed to be accurate. Although I use the tool myself, and trust my work…it is not investment advice. Use it at your own risk. Persons seeking investment advice should consult a financial professional. Data not guaranteed to be accurate.

Greg FLEX, Finance

FLEX and Perl Export to Excel

May 1st, 2008

Need to export a Flex Datagrid to Excel CSV?

Here is a link to the Flex code

The flex code will convert the DataGrid to a CSV string. Which you will then post to a cgi….code below.

You can see it in action on my Dividend Reinvestment Tool 

#!/usr/bin/perl
use CGI qw(:standard);
my $cgi = new CGI;
my $count = 0;
use CGI::Carp qw(fatalsToBrowser);
$title=$cgi->param('title');
$html=$cgi->param('htmltable');
$type = $cgi->param('type');
if ($type = "CSV") {
print $cgi->header(-expires=>'now', -type=>'application/x-csv', -content_disposition=>"attachment; filename=$title.csv");
print "$html";
}
else {
print $cgi->header(-expires=>'now', -type=>'application/octet_stream', -content_disposition=>"attachment; filename=$title.xls");
print $cgi->start_html(-title => 'Export'
);
print "$html";
print $cgi->end_html;

Greg FLEX, How-To, Perl

Windows Authentication using WebOrb and Flex Client

March 22nd, 2008

1) First make sure that the security level in IIS (at least for the WebOrb virtual Directory is set to Windows Integrated security)

2) CREATE A C# CLASS with the following function

public string getUsername()
{

System.Security.Principal

.WindowsPrincipal p = System.Threading.Thread.CurrentPrincipal as System.Security.Principal.WindowsPrincipal;
string strName = p.Identity.Name;
return strName;
}

Flex Client Code Action Script

<mx:Script>
<![CDATA[
import mx.rpc.events.ResultEvent;

//import mx.rpc.remoting.RemoteObject;
import flash.net.registerClassAlias;
import mx.controls.Alert;
import mx.messaging.config.ServerConfig;
private var nc:NetConnection;
private var so:SharedObject;

private function establishConnection():void
{

var ro:RemoteObject = new RemoteObject();
ro.destination = "PANO2";
ro.addEventListener(ResultEvent.RESULT, dataHandler);
ro.getUsername();

}
private function dataHandler( event:ResultEvent ):void
{
var uname:String = new String();
uname = event.result.toString();
//At this point you have uname as a string. Do what you want with it.
}

]]>

Greg FLEX, WEBORB