Jim Rogers

Lives in Baton Rouge, LA, with two dogs, one cat, and one lovely wife. I'm a lead developer for GCR Incorporated.

Katrin and Jim

Month List

Embedding the application background image in Flex

by jim Mar 01, 2012 1:34 PM

I was trying to switch to an embedded background image for my Flex application, and this syntax works:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                backgroundImage="@Embed(source='./images/soselec_bg.jpg')"  
                backgroundGradientAlphas="[1.0, 0.0]" 
                backgroundGradientColors="[#E7EEFA, #E7EEFA]"
                verticalScrollPolicy="off">

However, I had fiddler open at the time, and noticed that flash was getting a 404 Not Found, while trying to retrieve an image at http://mydomain/@Embed(source='./images/soselec_bg.jpg'). Fail.

I couldn’t figure out why this was happening, but did find a different way to embed the image, that doesn’t result in the failed request for a file that doesn’t exist. I used the standard embedding format:

[Bindable]
[Embed(source="./images/soselec_bg.jpg")]
protected var BackgroundImage:Class;

Then programmatically assigned the background in my preInitialize handler:

protected function preinitializeHandler(event:FlexEvent):void
{
    Application.application.setStyle("backgroundImage", BackgroundImage);
}

Tags:

Code

RBG from HSV

by Jim Nov 13, 2007 3:10 PM

I needed to convert HSV (Hue, Saturation, Value) colors to RGB to make a hue control for my AS3 project. I found a function to do this and ported it, so here goes:

// Get an RGB value as uint from hue, saturation, value
// Each argument has the range 0 to 1
private function getRBGfromHSV(H:Number, S:Number, V:Number):uint
{
  // Adapted from: http://easyrgb.com/math.php?MATH=M21#text21
  var R:uint, G:uint, B:uint;
  var var_h:Number;
  var var_i:int;
  var var_1:Number, var_2:Number, var_3:Number;
  var var_r:Number, var_g:Number, var_b:Number;
 
  if (S == 0)
  {
     R = V * 255;
     G = V * 255;
     B = V * 255;
  }
  else
  {
     var_h = H * 6;
     if ( var_h >= 6 )
       var_h = 0;         // H must be < 1
     var_i = Math.floor(var_h);   
     var_1 = V * ( 1 - S );
     var_2 = V * ( 1 - S * ( var_h - var_i ) );
     var_3 = V * ( 1 - S * ( 1 - ( var_h - var_i ) ) );

     if      ( var_i == 0 ) { var_r = V     ; var_g = var_3 ; var_b = var_1; }
     else if ( var_i == 1 ) { var_r = var_2 ; var_g = V     ; var_b = var_1; }
     else if ( var_i == 2 ) { var_r = var_1 ; var_g = V     ; var_b = var_3; }
     else if ( var_i == 3 ) { var_r = var_1 ; var_g = var_2 ; var_b = V    ; }
     else if ( var_i == 4 ) { var_r = var_3 ; var_g = var_1 ; var_b = V    ; }
     else                   { var_r = V     ; var_g = var_1 ; var_b = var_2; }
 
     R = var_r * 255;
     G = var_g * 255;
     B = var_b * 255;
  }
  return (R << 16) + (G << 8) + B;
}

That's in ActionScript 3, but it would be trivial to convert it to Javascript.

And to make a hue gradient, or "rainbow" gradient:

var g:Graphics = mDialog.graphics;

g.lineStyle(0, 0, 0);

var colors:Array = new Array();
var positions:Array = new Array();
var alphas:Array = new Array();
for (var h:Number = 0; h <= 1.01; h += .0833333)
{
  colors.push(getRBGfromHSV(h, 1.0, 1.0));
  positions.push(255 * h);
  alphas.push(1.0);
}

// The matrix will rotate my gradient 90 degrees
var gradientMatrix:Matrix = new Matrix();
gradientMatrix.createGradientBox(mHueRect.width, mHueRect.height, Math.PI/2.0);
gradientMatrix.translate(mHueRect.x, mHueRect.y);
g.beginGradientFill(GradientType.LINEAR, 
  colors,
  alphas, 
  positions, 
  gradientMatrix);
g.drawRect(mHueRect.x, mHueRect.y, mHueRect.width, mHueRect.height);
g.endFill();

Tags:

Code

Flash Debug Version

by Jim Oct 22, 2007 3:00 PM

I started working with Flex again after a little hiatus and suddenly I couldn't debug:

C:\WINDOWS\system32\Macromed\Flash\Flash9d.ocx

Flex Builder cannot locate the required debug version of the Flash Player. You may need to install the debug version of Flash Player 9.0 or reinstall Flex Builder. Do you want to try to debug with the current version?

The flash player seems to have a new version every week and I vaguely remember installing a newer one to view some neato photo manipulation program that a coworker sent me to.

Thinking that I needed a previous build, I tried installing flashplayer9r16_win_debug.exe from the previous version archive (which is handy for testing purposes.) No luck; this didn't appear to do anything at all.

What you need to do is go to the Adobe Flash Player Support Center and download the "Windows Flash Player 9 ActiveX control content debugger" for your browser. This will uninstall previous versions and make everything right.

Tags:

Code

Flash Compiler Bug?

by Jim May 10, 2007 8:52 AM

I got the following error when running my flash program:

VerifyError: Error #1030: Stack depth is unbalanced. 2 != 0

The adobe documentation implies that the SWF file is corrupt; presumably this is due to a bug in the compiler, or a bug related to interpreting the compiled code.

I panicked for a second there - how do you work around a bug in the compiler? Wait for the next version? But I started playing with the code and found the source of the problem. Here's my function:

private function clickHandler(event:MouseEvent):void
{
    // Is the click on the region of the main "button"?
    if (SymbolMenuButton(getChildAt(0)).hitTestPoint(event.stageX, event.stageY))
    {
        showSubs(getChildAt(1).visible != true);
    }
    else if (mSymbols.visible && mSymbols.hitTestPoint(event.stageX, event.stageY))
    {
        // ToDo: Determine which symbol was clicked
        dispatchEvent(new TextEvent(SYMBOL_CLICK, true, false, 
            mGlyphs[mSymbolsIndex, 1, 1]));
    }
    event.stopPropagation();
}

 The exception was thrown in the first if block, not on the offending line, which is the dispatchEvent; specifically, the array access is causing the problem. If I change this to mGlyphs[mSymbolsIndex][1][1], then everything is fine.

It would appear that the compiler allows the incorrect array access, then the flash player gets confused by the compiled code and throws an error.

Tags:

Code