AS3 FLVPlayback seekBar problem

I’m customizing the FLVPlayback component with the individual video control components, but the SeekBar wouldn’t work no matter what I did, though the PlayPauseButton worked fine.

vidPlayer.seekBar = controls_mc.seek_mc;

Turns out that you need to set the SeekBar property of the FLVPlayback component AFTER you call play().

It took me a while to find the resolution to this annoying issue; hopefully google will index this post and help someone out.

jvanpelt - February 10th, 2009

bulkloader content null problem

Ok, so i’ve been trying to track down a BulkLoader bug in my framework for days now and I FINALLY managed to figure out what it was. First let me say that I don’t like try…catch statements very much. They obscure where an error is occuring in your app.

The way the framework works is, when it initiates it starts loading all of the external swfs that it needs, starting with home.swf on down the list. If you navigate to a page that isn’t loaded it’ll display a loading dialog and force BulkLoader to move that page’s assets to the top of the queue. This works well with SWFAddress, which allows you to start the application (site) from any page via deep-linking. Bla bla bla. The problem I was having was that the first item loaded by BulkLoader, no matter which page it was, would sometimes error out.

What I eventually found was that in BulkLoader’s ImageItem class, where the actual loader exists, the COMPLETE Event was being called but there was no content in the loader’s content property. But ImageItem’s onCompleteHandler doesn’t verify that the content exists, it just sets _content = loader.content and calls super.onCompleteHandler(evt). Flash has always had these weird little timing errors that’ll pop up where something is supposed to be ready to go, but it’s just not quite there.

override public function onCompleteHandler(evt : Event) : void {   _content = loader.content;

   if (!_content){       var t = new Timer(50, 1);       t.addEventListener(TimerEvent.TIMER_COMPLETE, onCompleteHandler);       t.start();   } else {       super.onCompleteHandler(evt);   }}

So I added in a quick check to see if the content is there. If it’s not, run a timer for 50ms then try again and Yay! it works. I don’t know if the other LoadingItem types have this same problem, but I do know that I had trouble finding any info on this issue. Hopefully this helps somebody.

jvanpelt - November 24th, 2008

referencing library items in an external swf by "linkage name"

I’m working on a base framework for Flash projects at work using PureMVC, SWFAddress, and BulkLoader. I’ve gone back and forth for a while now on the issue of loading one 600k swf that contains all of your assets, or loading page assets as individual swfs, which I think is the better way. What I wanted to avoid was having to compile individual “functioning” swfs that aren’t really part of the system. I want to simply use swfs as asset libraries and nothing else. The problem comes when you go to add an object from your loaded library.

If I try to add a graphic asset from the external library to the stage in my mediator I’ll get an error because basically that object does not exist yet. After doing a bit of research yesterday I found a work-around that I don’t particulaly like, but it works.

First of all, you have to define an ApplicationDomain in your Loader — or in this case, BulkLoader — with a LoaderContext object:

var context:LoaderContext = new LoaderContext(false,ApplicationDomain.currentDomain);bulkLoader.add(HomeMediator.ASSETS,{context:context});bulkLoader.add(AboutMediator.ASSETS,{context:context});etc...

Then you have to use the handy getDefinitionByName method in flash.utils. I have to say, though, that as useful as this little bit of code it, I don’t really like it. It feels like a hack. But it works, so let me show you the difference. First, the old way:

var header_mc = viewComponent.addChild(new HomeHeader());header_mc.init({x:100, y:200, name:"header_mc"});

became:

var ClassName:Class = getDefinitionByName("HomeHeader") as Class;var header_mc = viewComponent.addChild(new ClassName());header_mc.init({x:100, y:200, name:"header_mc"});

I can tell you, I hated this right off the bat. The idea of adding another line of code for every graphic element I add to the stage made me cringe. You’ll notice I’ve got this init() method that I’m calling on my objects as well. I’ll explain that in a minute.

The final solution I came up with for addressing adding elements to the stage was to create a DisplayManager class with a single static method:

public static function attachObject(viewComponent:*, ClassName:String, initObject:Object = null):Object{   var _ClassName:Class = getDefinitionByName(ClassName) as Class;   var _mc = viewComponent.addChild(new _ClassName());

   if (initObject){ _mc.init(initObject); }

   return _mc;}

which boils three lines of code in my mediators down to one:

var header_mc = DisplayManager.attachObject(viewComponent, "HomeHeader", {x:100, y:100, name:"header_mc"});

Lovely.

Ok, so let me quickly fill you in on the init() thing, which I thought I had posted on in the past, but it turns out I had only posted about the thought that lead up to it, simple proptery setting. I took this idea and created a very simple class, DisplayClip, that extends MovieClip and adds an init method that takes an initObject as a parameter and transfers those parameters to the MovieClip. I’ve got TypicalBtn and TypicalMenuBtn classes that extend DisplayClip, and I have to say it’s come in extremely handy.

package com.peteramayer.as3.display {

    import flash.display.*;    import flash.text.*;    import flash.events.*;

    public class DisplayClip extends MovieClip implements IEventDispatcher{

        public function DisplayClip() {            trace("[DisplayClip]");        }

        public function init(initObj:Object ) {            for (var prop in initObj) {                this[prop] = initObj[prop];            }        }

    }

}

jvanpelt - November 18th, 2008

simple property setter

still working on that post mardi gras thing. actually, my tablet has become disabled, so writing is slow. but i don’t make excuses.

this idea just came to me, and i don’t know why it too so long but i really wish it hadn’t. i’ll start with this simple code snippet:

var bla = {x:200,y:100,alpha:50};

// box_mc is just a square movieclip on the stage
for(var props in bla){
box_mc[props] = bla[props];
}

I’ve been trying to think of ways to reconstruct my flash work-flow in AS3 in the post-AS2 world, replacing attachMovie with something similarly easy to use. I don’t like to have anything on my timelines. Not code, not graphics. I want everything to be drawn from libraries within swfs. In AS3 everything is an object. A graphic in your library is a…

var gfx = new LibraryItem();

…custom object that does or does not have a corresponding class.

So i was thinking about creating a base class for my library item movieclips that extends MovieClip but that accepts properties that can be dynamically set. But how to set those properties? With a for … in loop, duh. Something like:

var gfx = new LibraryLinkageName({x:200,y:100,alpha:50});

so much easier than

var gfx = new LibraryItem();
gfx.x = 200;
gfx.y = 100;
gfx.alpha = 50;
addChild(gfx);

I haven’t decided about having objects attach and remove themselves from the display list yet, but I’m thinking probably not.

jvanpelt - February 27th, 2008