Archive for the 'Actionscript' Category

Visibility and parent clips

Sunday, April 27th, 2008

“visible” works a little differently in as3. Seems that it disables button actions and turns the alpha to 0, but keeps the item as part of the display list. This means that my old tricks of turning things visible = false then getting the parent size do not work correctly anymore. At first this was frustrating until I realized that removing an object from the display list is much more clear and effective.

It’s a slightly different way of thinking:

package{

  import flash.display.*;

  public class SomeObject extends Sprite{

    public function SomeObject(){
      super();
    }

    /**
     * Will add and remove the child object from the sprite if needed.
     * @param  targetChild  The child to add or remove.
     * @param  isVisible  Add or remove it.  Default is true.
     */
    public function setChildVisibility(targetChild:DisplayObject, isVisible:Boolean = true):void{
      if(isVisible){
        if( !contains(targetChild) ){
          addChild(targetChild);
        }
      }else{
        if( contains(targetChild) ){
          removeChild(targetChild);
        }
      }
    }
  }
}

As usual a tad bit more code, but a lot clearer about what results we want. The hardest part is the transition in a production environment where all the old shortcuts just don’t work anymore.

scale9 with bitmaps

Saturday, April 26th, 2008

Looks like the flash 9 editor does not allow for the trick of using a bitmap pattern fill for scale9 slicing. Still seems strange to me that they would not encourage working with bitmaps for scale9. I’m happy I did a search, because I was about to write my own class before I came across this post. It does exactly what I wanted it to do: apply scale9 properties to a bitmap. This is something that is really nice about as3, lots more people are building compartmentalized little tools that can just be grabbed and plugged into your project.

Number, int

Friday, March 28th, 2008

Still on the fence about how to get down to the nitty gritty with Number and int in as3. There are a lot of people running low level tests and writing articles:

http://kuwamoto.org/2006/06/15/avoid-ints-in-actionscript/

http://flextips.corank.com/tech/framed/fastest-numeric-datatype

Feels like Number is still the way to go for most coordinate based stuff and int is good for indexing, unless I am building something that has to keep track of aloooot of things.

AS3 is time consuming

Friday, March 21st, 2008

Spent today getting together an flv player that is lightweight in as3. Realized how much code you need to do some really simple stuff. I’m getting a little irritated with the static type errors. It really doesn’t feel like good practice to put Event as a parameter for public functions so that means creating a new function to use as a middle layer between the listener and the function that is called. I suppose this makes it so that everything is very specific but man it makes life time consuming. Time consuming + ad agency = trouble.

Code Page

Wednesday, March 19th, 2008

Set up a google code page. They have a pretty nice setup for keeping random actionscript files. I like the fact that I do not have to set up and maintain my own subversion server. Should be easier to keep my stuff centralized and public now.