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 ‘ActionScript’ 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-15-2008

I need AIR / Actionscript assistance

I have a TileList in my AIR application. Previously, I was including the itemRender directly in the tag like:

<mx:TileList itemRenderer="Timeline" >
<mx:itemRenderer>
   <mx:Component>
    <mx:HBox verticalGap="0" backgroundColor="{outerDocument.checkUser(data.publisher.value)}">
       <mx:Image click="outerDocument.PlaySeesmicVideo(data.flv.value,data.videoUri.value)" />
       <mx:VBox width="100%" height="100%" verticalGap="0" verticalScrollPolicy="off">
       <mx:Label buttonMode="true" width="100%" textAlign="left" />
       <mx:Label text="({data.language.value})" fontSize="9" />
       <mx:Text fontSize="10" text="{outerDocument.StripRE(data.title.value)}"  />
       </mx:VBox>
     </mx:HBox>
   </mx:Component>
</mx:itemRenderer>
</mx:TileList>

I need to move the itemRenderer into it’s own component, but as soon as I do that I get errors on my functions that are fired from within the component. "outerDocument" no longer works.

So, my question, is, how do I reference a function in "main.mxml" from "timeline.mxml" ?

Posted under AIR, ActionScript