Category: flash

Flash Event.COMPLETE sometimes doesn’t fire in Firefox

3:24 pm on December 14th, 2009, by Ryan Gibson

I have run into some strange behaviour in Flash and Firefox recently. We had a Flash movie (AS3) that loads up, in its document classes constructor it sets a few event handlers on loaderInfo:

this.loaderInfo.addEventListener(Event.COMPLETE, loadComplete);
this.loaderInfo.addEventListener(ProgressEvent.PROGRESS, progress);
this.loaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
this.loaderInfo.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);

The problem taht seemed to be happening (most of the time, ie not 100% reproducible) was that the movie was failing to fire the Event.COMPLETE event handler. After some browsing I found Marguera’s post which suggests adding another event handler, Event.INIT and pointing it at the same handler as the Event.COMPLETE event.

this.loaderInfo.addEventListener(Event.INIT, loadComplete);

Then updating the loadComplete method to check if we had actually finished loading, if so remove the event handlers and carry on setting up the movie.

private function loadComplete(e:Event):void {
  if(this.loaderInfo.bytesLoaded == this.loaderInfo.bytesTotal){
    this.loaderInfo.removeEventListener (Event.INIT, loadComplete);
    this.loaderInfo.removeEventListener (Event.COMPLETE, loadComplete);
    // Finish setting up the movie
    // ...
  }
}

This approach fixed our issue, and hopefully this post will point anyone else seeing similar irregularities in the right direction. The Flash documentation states that the Event.INIT event is fired when:

  • All properties and methods associated with the loaded object and those associated with the LoaderInfo object are accessible.
  • The constructors for all child objects have completed.

And that the init event always precedes the complete event. That wasn’t what we were seeing in practice, as our complete event was failing to fire completely. hth.

8 comments » | Adobe, development, flash, web

AS3 Json integration quick and dirty

4:03 pm on November 2nd, 2009, by Jeff Khan

Ive been dealing with Json data recently which may be a faster/less convoluted alternative for handling data between backend and frontend interfaces than xml. This is probably the quickest and lightweight serialization i’ve found that works.

Credit goes to http://www.ekameleon.net for the class file, and can be found here.

Implementation goes something like this:-

import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
import flash.net.URLVariables;
import com.serialization.json.json;

var uvars:URLVariables = new URLVariables();
var ureq:URLRequest = new URLRequest();
ureq.url = “http://blah.com”;
ureq.method = URLRequestMethod.POST;
ureq.data = json.serialize(uvars);
ureq.contentType = “application / json”;

var uload:URLLoader = new URLLoader();
uload.addEventListener(Event.COMPLETE, jsonLoadComplete);
uload.load(ureq);

private function jsonLoadComplete(e:Event) {

var data= json.deserialize(e.currentTarget.data);

}

Comment » | flash

AS3 mouseEnabled not working with nested Movieclips

3:38 pm on November 2nd, 2009, by Jeff Khan

Had a little bit of a problem with mouseEnabled= false not working.

I had two movieclips. One was a button and one a ‘tooltip’ mc that was on top of the button. The button mc had mouseEvent listeners for mouseover and mouseout. Now the standard thing to do to stop recieving mouse interactivity on a display object is to set mouseEnabled = false. (It is set to true by default and stops you pressing ‘thru’ display objects)  However it was not working. In my setup i had nested Moviclips but i had assumed setting this on the parent would affect all mouse ‘enabling’

The thing to use is:

mouseEnabled = false; //as well as
mouseChildren = false;

this should tell actionscript to stop listening to nested mc’s as well.

8 comments » | flash

html5 under the radar; or a standards compliant way to embed video on the web

6:01 pm on July 2nd, 2009, by Ryan Gibson

With the release of Mozilla’s Firefox 3.5 another browser—along with Apple’s Safari and Google’s Chrome—now supports html5’s video tag. We’re still a long way from complete browser support, and a working standard. Ian Hickson, among other things, editor of the html5 spec lays the land out as follows:

“Apple refuses to implement Ogg Theora in Quicktime by default (as used by Safari), citing lack of hardware support and an uncertain patent landscape.

Google has implemented H.264 and Ogg Theora in Chrome, but cannot provide the H.264 codec license to third-party distributors of Chromium, and have indicated a belief that Ogg Theora’s quality-per-bit is not yet suitable for the volume handled by YouTube.

Opera refuses to implement H.264, citing the obscene cost of the relevant patent licenses.

Mozilla refuses to implement H.264, as they would not be able to obtain a license that covers their downstream distributors.

Microsoft has not commented on their intent to support <video> at all.”

So where does this leave us, still embedding video with the propriety Flash pluggin, well not exactly. Kroc Camen has a standards compliant, non-javascript alternative that takes advantage of html object-fallback. Yes the code is a little verbose, and adding non-native controls still requires javascript—but the concept seems sound and the extra work of compressing an Ogg Theora video is nothing to bork at.

This seems like a really cool way of allowing video for those without Flash, or unwilling to use Flash. I’d argue against it needing any attribution—as its a collection of html used in the expected way—although Kroc is the first to suggest this particular series of embeds.

Anyway, check it out and have fun with Video for Everyone.

2 comments » | flash, html, web

fbjs-bridge over troubled waters.

1:07 pm on October 21st, 2008, by Gareth Evans

Well I know that’s a bad title, but when you develop Facebook apps you need something to lighten your day and I’ve been developing them for the past six months.

The one thing I’ve noticed over all things is that nothing is simple, not even the simple things. You see Facebook take it upon themselves to screw with all of your code and what’s worse is that the documentation for what and how they’ve ‘altered’ it just seems quite cold and unnurturing.

For example, we developed an application that had a form, you see, a nice simple form sending POST data. If I was to tell you how long it took to figure out my code was fine and that Facebook had changed it to GET, then I’d probably blush.

It’s the accumulation of marginal dis-advantages that can grind Facebook development to a sickening halt. You sometimes feel like you spend more time discovering (the hard way) what you can’t do rather than getting on with the things you think you already can.

If I’m honest, it’s something I love to hate. Maybe it’s because every pit of despair has ended with a high-five, or maybe I’m just a masochist, either way here’s my latest  Facebook exploit:

Flash in Facebook isn’t that difficult, once you realise you need to use an Fb:swf tag that is. But one thing that could quite possibly bake your noodle is that no matter what you put in your AS3, navigating to a URL will always open in a new window.

In order to open a page in the same window via Flash, you are required to call Facebook JavaScript (fbjs.) This is achieved by using a LocalConnection method to call the fbjs method “document.setLocation” to navigate to the url passed, in this case “http://www.google.com.”

var connectionName:String = stage.loaderInfo.parameters.fb_local_connection;
var connection:LocalConnection = new LocalConnection();
var cResult = connection.send(connectionName, "callFBJS", "document.setLocation", ["http://www.google.com"]);

But it doesn’t stop there, no that would be too easy, you need to enable the fbjs bridge by putting the fbjs:bridge tag on your HTML page and this must also (no I don’t know why either, but it works) be accompanied by an empty script tag:

<fb:fbjs-bridge/>
<script> <!-- --> </script>

Ta da, a simple button in Flash that opens a URL in the same window.

8 comments » | development, flash, web

Adobe Air htmlLoader flash content doesn’t appear

4:42 pm on August 14th, 2008, by Jeff Khan

More Air conditioning…Under certain circumstances Flash and PDF content will not display in a htmlLoader when

  • You scale the HTMLLoader object to a factor other that 1.0.
  • You set the alpha property of the HTMLLoader object to a value other than 1.0.
  • You rotate the HTMLLoader content

    AND IT WILL NOT DISPLAY IF THE WINDOW IS TRANSPARENT CHROMELESS
    When i think about it it makes sense not to render but this has been annoying me to no end, since the stage i was working with had a background (but the windows were set to tranparent)

    found this on live docs..

    http://livedocs.adobe.com/air/1/devappsflash/help.html?content=ScriptingHTMLContainer_2.html

2 comments » | Adobe, AIR, flash

Adobe Air htmlLoader scales content by default

2:15 pm on August 14th, 2008, by Jeff Khan

More AIR conditioning for you..

When adding a HTMLLoader to the stage the contents by default scale to the size of the window. And this is not so helpful if you want to open one up in a new window.

you should be setting these properties too:

stage.scaleMode = StageScaleMode.NO_SCALE
stage.align = StageAlign.TOP_LEFT

If you are loading HTMLLoader using a new window i.e:-

var options:NativeWindowInitOptions = new NativeWindowInitOptions();
options.systemChrome = NativeWindowSystemChrome.NONE;

var window:NativeWindow = new NativeWindow(options);
var htmlLoader:HTMLLoader = new HTMLLoader();

// SET THIS–
window.stage.scaleMode = StageScaleMode.NO_SCALE
window. stage.align = StageAlign.TOP_LEFT

before you do your loading..

htmlLoader.load(new URLRequest(blah))

1 comment » | Adobe, AIR, flash

Adobe AIR jsfl publish swf and create AIR package at once

11:52 am on August 1st, 2008, by Jeff Khan

In order to publish an air package you have to create it from the latest swf file. However the Flash AIR extension gives you commands to create and publish air files but not publish the swf in one go.

On windows in ..
C:\Program Files\Adobe\Adobe Flash CS3\en\First Run\Commands

You can add dom.publish() to the AIR – Create AIR File.jsfl just before this line:-

FLAir.PackageAIRFile(flaFilePath);

Alternatively copy and paste the following into your own custom publish and create AIR jsfl file! Useful and i’ll be working on a network debugging window to test air apps running desktop commands soon..useful as you cant test in the authoring environment.

//fl.trace(“Artemis”);
var dom = fl.getDocumentDOM();

if (dom == null)
{
alert(“Failed to get current document.”);
}
else
{

var flaFilePath = dom.path;
//fl.trace(flaFilePath);
//fl.trace(dom.playerVersion);
//fl.trace(dom.asVersion);
//fl.trace(dom.getSWFPathFromProfile());

if(!flaFilePath)
{
alert(“The Flash AIR file must be saved before opening AIR Application and Installer Settings and before creating the AIR file.”);
}
else
{
if(dom.getPlayerVersion() == ‘AdobeAIR1_0′)
{
dom.publish()
FLAir.PackageAIRFile(flaFilePath);
}
else
{
//alert(“The Publish target is not Adobe AIR 1.0.”);
var gotOK = FLAir.PackageAlert(flaFilePath);
if (gotOK == 1)
{
dom.setPlayerVersion(‘AdobeAIR1_0′);
dom.save();
FLAir.OpenSettingDialog(flaFilePath);
}
}
}
}

Comment » | Adobe, AIR, flash

Adobe Air badge install Error# 2023

12:14 pm on July 31st, 2008, by Jeff Khan

Another AIR gotcha..
As well as allowing your server access to the .air filetype make sure the location to the air file is the absolute path unlike the relative path in Adobe’s own example!

credit to this blog entry:
http://blog.joshbuhler.com/2008/06/30/air-installer-badge-error-2032/

Comment » | Adobe, AIR, flash

Adobe Air launch at startup in Flash AS3 Class

11:52 am on July 31st, 2008, by Jeff Khan

As Adobe AIR is still relatively new, i’ll be documenting my train of thought my finds and roadblocks on Labs, it could get messy – you have been warned! Here’s another:-

To force an application to launch at startup,when a user logs in, you must use this

NativeApplication.nativeApplication.startAtLogin = true;

When it’s used in an AS3 class and not on the root of the flash document you must import

import flash.desktop.*;

Was previously importing all the AIR classes to no avail..

5 comments » | Adobe, AIR, flash

Back to top