Archive

Archive for March, 2009

Change Browser Title in FLEX using Javascript

March 27th, 2009

If you only need to statically set the Browser Title in FLEX, then just set the pageTitle property of your <mx:Application>

<mx:Application backgroundColor="#ffffff" pageTitle="My Application: By Greg Jessup"
    xmlns:mx="http://www.adobe.com/2006/mxml"
    layout="absolute"
    initialize="init()"
    width="100%"
    height="100%"
>

Howerver, sometimes you want to do it dynamically. The only way to do this is by making a call from Flex to the HTML template and invoking a JavaScript function.

We use the flash.external.ExternalInterface to accomplish this task.

Here is how its done…..

FLEX CODE

import flash.external.ExternalInterface;
 
private function SetBrowserTitle(newTitle:String) : void {
                if ( ExternalInterface.available ) {                     
                    ExternalInterface.call("changeTitle",newTitle);        
                }            
}

 

Javascript

Simply edit the html-template/index.template.html in you project. Your header will look something like this. The main thing you are concerned with here is adding the changeTitle function….see below

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>${title}</title>
<script src="AC_OETags.js" language="javascript"></script>
<script language="JavaScript" type="text/javascript">
    function changeTitle(newTitle) {      
      document.title=newTitle;  // this works with IE only      
     }
</script>
<style>
body { margin: 0px; overflow:hidden }
</style>
</head>

Greg Uncategorized

Replace Non Printable Characters in PERL String

March 26th, 2009
#replace non printable characters in the description
my %good = map {$_=>1} (9,10,13,32..126);
$description =~ s/(.)/$good{ord($1)} ? $1 : ' '/eg;

Greg Uncategorized

ComboBox ItemRenderer in Flex AdvancedDatagrid

March 9th, 2009

image

 

If you are declaring your AdvancedDataGridColumn in MXML then simply add

headerRenderer="View.HeaderRenderer"

<mx:AdvancedDataGridColumn wordWrap="true"  headerRenderer="View.HeaderRenderer"  
    sortable="false" dataField="chkbox" width="200" textAlign="center">

 

Then Create your ComboBox in either MXML or ActionScript. I chose MXML in this case.

<?xml version="1.0"?>
 
<mx:HBox creationComplete="setStyles()" horizontalAlign="center" xmlns:mx="http://www.adobe.com/2006/mxml">
    <mx:Style>
        HeaderComboBox {
           cornerRadius: 0;
           arrowButtonWidth: 0;
           openDuration: 10;
           closeDuration: 10;
           textAlign: left;
           fontSize: 10;
        }
    </mx:Style>
    
    <mx:Script>
        <![CDATA[
            import mx.events.ListEvent;         
            [Bindable]    public var headerRendererData: Array = [ {label:"Select Action", data:0, buttonName: ""}, 
                    {label:"Close Selected", data:"close",  buttonName: "Close these Tickets"},                
                    {label:"Update Selected", data:"update",  buttonName: "Update these Tickets"}];                   
 
 
 
               public function doWork(e:ListEvent) : void {                   
                   //Put code here to action a selection event
                   combo.selectedIndex = 0;  //reset combo to first value
                   trace (e);
               }
               private function setStyles() : void {
                   
                try {
                   combo.dataProvider = this.headerRendererData;;
                   combo.setStyle("cornerRadius",0);
                   combo.setStyle("openDuration",10);
                   combo.setStyle("closeDuration",10);
                }
                catch (e:Error) {}
               }
               
        ]]>
    </mx:Script>
 
    <mx:ComboBox id="combo" width="98%" dataProvider="{this.headerRendererData}" change="doWork(event)">
        
    </mx:ComboBox>
    
 
</mx:HBox>
 

Greg Uncategorized

SubSonic Multiple Databases ConnectionString or DataProviders

March 6th, 2009

So you have a SubSonic Project that you now need to connect to multiple Databases. In my case, I didn’t let SubSonic build the database infrastructure, but for my 2nd database, I just used and inline query. Why? Because I needed it done YESTERDAY…So it was just easier at the time.

To configure SubSonic to connect to the other database. I did the following.

Below in the XML…notice I have 2 connectionStrings and 2 providers

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="SubSonicService" type="SubSonic.SubSonicSection, SubSonic" allowDefinition="MachineToApplication" restartOnExternalChanges="true" requirePermission="false"/>
  </configSections>
  <connectionStrings>
    <add name="SQLDashboard" connectionString="Data Source=MYQSTMGTDB01; Database=SQLPerfmonStats; Integrated Security=true;"/>
    <add name="MYDevicesDB" connectionString="Data Source=MYDevicesDB; Database=MYDevices; Integrated Security=true;"/>
  
  </connectionStrings>
  <SubSonicService defaultProvider="SQLDashboard" enableTrace="false" templateDirectory="">
    <providers>
      <clear/>
      <add name="MYDevicesDB" type="SubSonic.SqlDataProvider, SubSonic" connectionStringName="MYDevicesDB"/>
      <add name="SQLDashboard" type="SubSonic.SqlDataProvider, SubSonic" connectionStringName="SQLDashboard"/>
    </providers>
  </SubSonicService>
</configuration>

 

In my C# code I did the following using Subsonic.InlineQuery

String sql = @"select * from myTable";
 
IDataReader rdr = new SubSonic.InlineQuery("SACDevicesDB").ExecuteReader(sql);
             DataTable dt = new DataTable();
                 using (rdr)
                 {
                  dt.Load(rdr);
                 }
             return dt;

Greg Uncategorized

Taxed to excess

March 6th, 2009

Excellent letter to the editor Times Record News Witchita Falls Kansas

image

http://www.timesrecordnews.com/news/2009/feb/05/no-headline—2-6_oped_letters/

Dear IRS,

I am sorry to inform you that I will not be able to pay taxes owed April 15, but all is not lost.

I have paid these taxes: accounts receivable tax, building permit tax, CDL tax, cigarette tax, corporate income tax, dog licence tax, federal income tax, unemployment tax, gasoline tax, hunting licence tax, fishing licence tax, waterfowl stamp tax, inheritance tax, inventory tax, liquor tax, luxury tax, medicare tax, city, school and county property tax (up 33 percent last 4 years), real estate tax, social security tax, road usage tax, toll road tax, state and city sales tax, recreational vehicle tax, state franchise tax, state unemployment tax, telephone federal excise tax, telephone federal state and local surcharge tax, telephone minimum usage surcharge tax, telephone state and local tax, utility tax, vehicle licence registration tax, capitol gains tax, lease severance tax, oil and gas assessment tax, Colorado property tax, Texas, Colorado, Wyoming, Oklahoma and New Mexico sales tax, and many more that I can’t recall but I have run out of space and money.

When you do not receive my check April 15, just know that it is an honest mistake. Please treat me the same way you treated Congressmen Charles Rangle, Chris Dodd, Barney Frank and ex-Congressman Tom Dashelle and, of course, your boss Timothy Geithner. No penalties and no interest.

P.S. I will make at least a partial payment as soon as I get my stimulus check.

Ed Barnett

Wichita Falls

Greg Uncategorized

Create a Key Value Pair Object in Actionscript

March 5th, 2009

 

If this is essentially an ActionScript Dictionary, but if you don’t need some of the overhead a dictionary brings along, you can make a nice key value pair like this.

private var keyValuePair:Object = {"processor_TotalPercentTime_value" : "processor_color",
                                         "network_value" : "network_color",
                                         "network_value" : "network_color",
                                         "disk_DiskSecPerTransfer_value" : "disk_color",    
                                         "disk_KBytesPerTransfer_value" : "disk_color",
                                         "memory_PLE_value" : "memory_color",
                                         "memory_LazyWrites_value" : "memory_color",
                                         "memory_AvailableMBytes_value" : "memory_color",
                                         "MachineName":"sql_color"};

 

You would reference the keyValuePair as follows:

var myVal = keyValuePair["processor_TotalPercentTime"].toString();

Greg Uncategorized

Error #1034: Type Coercion failed: cannot convert mx.graphics::Stroke to mx.graphics.IStroke.

March 5th, 2009

This turned out to be a pretty haunting bug, and I still don’t quite understand what I did to fix it, but I did.

You’ve probably already seen the Adobe Bug SDK-9480 

And of couse you’ve seen an error that looks like so…..

TypeError: Error #1034: Type Coercion failed: cannot convert mx.graphics::Stroke@dfd3e21 to mx.graphics.IStroke.
    at mx.charts::AxisRenderer/measure()
    at mx.core::UIComponent/measureSizes()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:5956]
    at mx.core::UIComponent/validateSize()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:5902]
    at
mx.managers::LayoutManager/validateSize()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\managers\LayoutManager.as:579]
    at mx.managers::LayoutManager/doPhasedInstantiation()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\managers\LayoutManager.as:668]
    at Function/http://adobe.com/AS3/2006/builtin::apply()
    at mx.core::UIComponent/callLaterDispatcher2()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:8628]
    at mx.core::UIComponent/callLaterDispatcher()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:8568]

 

The situation only appears to occur when I am running a Module across Application Domains.  For me it worked fine, as I was developing the module stand alone with a Main.mxml that I was using as my loader for the Module. When I ported the module to my global application….I was not so lucky and it broke things.

To fix the bug you will need to make a change in the code that is loading the module. In 1 of the following 2 ways. I used the 2nd because forcing all modules into the same “currentDomain” broke other modules that were using shared classes.

Here are the 2 ways I know of to fix it.

 

1) Set the Application Domain in your ModuleLoader as follows

var Mod:ModuleLoader = new ModuleLoader();
Mod.applicationDomain = ApplicationDomain.currentDomain;

2) In your Parent Application not in the module itself. (Every module needs and application)

import mx.graphics.IStroke;
private var uStroke:IStroke;

Greg Uncategorized

Use your Keyboard to turn your monitors off [ PushMonitOff v1.0 ]

March 5th, 2009

Found a handy piece of Software (Available Here) which allows you to quickly turn your monitors off using a keyboard shortcut. The default is Shift-F1. But can be changed using the task manager (seen below).

image

 

PushMonitOff v1.0

Greg Uncategorized

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

FLEX ItemRenderer in Actionscript 3.0 (AdvancedDataGridRenderer)

March 2nd, 2009

In the following example, I wanted to have a custom Renderer when I expanded a row in the AdvancedDataGrid. I need to do it in Actionscript, so here is what I did.

private function ExpandClick (e:AdvancedDataGridEvent) : void {
            trace(e);
            var children:ArrayCollection = new ArrayCollection([{Name:"Greg",Status:"O",Top:e.item}]);
            e.item.children =  children;            
            var renderer:AdvancedDataGridRendererProvider = new AdvancedDataGridRendererProvider();
            
            renderer.dataField = "Name";
            renderer.renderer = new ClassFactory(View.MagicRenderer);
            renderer.columnSpan = 0;
            renderer.columnIndex = 0;
            var rp:Array = new Array();
            rp.push(renderer);
            trace(tickets.selectedItem);
            tickets.rendererProviders = rp;            
            tickets.expandItem(e.item,true,true,false,null);    
            
        }

Greg Uncategorized