Critter’s Code

This is a picture of a bridge and a city. I like bridges and cities. They make me smile.

Archive for the ‘Samples’ Category

Jan-17-2008

Changing button icons at runtime using Actionscript

I had to do quite a bit of searching around this morning to figure out how to change the icons on my video player at runtime.

phoenix-032   phoenix-031

I thought I could easily modify the [button].icon property, but I could not access that at runtime. You can, however, do the following:

//    embed your icons
[Embed(source='com/images/play.png')]
[Bindable]
public var imagePlay:Class; 

[Embed(source='com/images/pause.png')]
[Bindable]
public var imagePause:Class;

//    using one button to toggle play and pause of video
private function playpause():void
{
    if (seesmicVideo.playing)
    {
        seesmicVideo.pause();
        btn_play.setStyle("icon",imagePlay);
    }
    else
    {
        seesmicVideo.play();
        btn_play.setStyle("icon",imagePause);
    }
}        

Using [button].setStyle() will allow you to change the icon at runtime.

Posted under AIR, ActionScript, Flex, Samples
Jan-6-2008

Using ColdFusion.navigate() from within a cfgrid.

I had what seemed like a simple task. Load a query into an html cfgid. Users could then click on a row (record) and be taken to an edit/update page.

Piece of cake. I have done this many times before. Unfortunately, this was my first time attempting it with ColdFusion 8 and all it’s ajaxy goodness. CFGRIDCOLUMN has an ‘href’ attribute, but I was not able to fire off javascript from it, it would only execute regular links. I wanted my edit screen to open up below the grid in a CFDIV.

After much googling and mucking around, I was able to piece together the following. Which adds a click event to the cell.

   1:  addLinksforaTasks = function()
   2:  {
   3:      gTask = ColdFusion.Grid.getGridObject('agrid_tasks');
   4:      cm = gTask.getColumnModel();
   5:      gTask.on('cellclick',function(grid,rowIndex,columnIndex,e)
   6:      {
   7:      var unitID = ColdFusion.getElementValue('agrid_tasks','taskform','taskid');
   8:      ColdFusion.navigate('atasks.cfm?action=edit&taskid='+unitID,'taskedit');
   9:       }
  10:      )
  11:  }

The hardest part to figure out was how to get the id field value (in this case taskid).  It is such a simple thing that I was sure is used constantly, but I could not find much help on the web. Here is the function explained:  ColdFusion.getElementValue(’grid_name’,'form_name’,'columnid’). That gave me the taksid of the selected row in the grid.

To execute the function when the grid loads you need to add

<cfset ajaxOnLoad(’addLinksforaTasks’)> to the page containing the grid.

One other thing to note, if you are loading a grid into a CFDIV, you need to put all helper functions on the parent page. They do not seem to execute correctly if they are included on the page loaded into the CFDIV.

Anyway… hope that can help someone…

Posted under Ajax, ColdFusion, Samples