jQuery “g is undefined”

2:33 pm on April 30th, 2010, by Clare

OK totally quick post this. Was getting this error inexplicably in the console, couldn’t work out what was causing it, commented out all but the most simple lines of code….. Still there! If in doubt – check the version of jQuery you’re using and try upgrading it. Worked for me. Incidentally this had nothing to do with AJAX/JSON – as I was still getting the error even without making any calls to any AJAX methods, BUT all the search results I’d found seemed to suggest a probelm in this area.

Comment » | Uncategorized

Flash Event.COMPLETE sometimes doesn’t fire in Firefox

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

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.

2 comments » | Adobe, development, flash, web

iPhone development: Setting dimensions on View elements in Interface Builder

5:36 pm on December 4th, 2009, by Clare

A minor point – but if you can’t set the dimensions or x,y of an element in the Size inspector (the boxes appear to be disabled) check the Attributes inspector and make sure that all the ‘Simulated Interface Elements’ (e.g. status bar, toolbar etc) are set to none. That should fix it!

Comment » | Interface Builder, iPhone

CSS alphaimageloader png fix for IE6: Images not showing up?

5:32 pm on December 4th, 2009, by Clare

Don’t forget, this method actually embeds an <img> tag in the document, so the path to the image in your CSS file needs to be relative to the actual webpage, and not the CSS file. So if you’re copying and pasting the CSS for a background image from your main CSS file, don’t forget to change the path or your image won’t show up. This was a bit of a head-scratcher until I realised that!

Comment » | css, ie6

Notes on iPhone CoreLocation framework

4:17 pm on December 2nd, 2009, by Clare

If you tell the Location Manager to start updating, it will keep returning updates indefinitely until it’s told to stop. It returns the new location to its delegate method: didUpdateToLocation (Like a callback).

It will keep trying to get you the most accurate location it can – when you create the Location Manager you can specify the level of accuracy (in metres) using the property: desiredAccuracy.

I haven’t ever experienced it returning more than 3 location updates, however I’ve read on some forums that people havegot up to 10 location updates back. To prevent the user waiting indefinitely for a response, I started a timer after the call to startUpdatingLocation and then if no response had come back after a certain time I could return and let the user know.

Every time you stop updating (i.e. every time you call stopUpdatingLocation) the Location Manager will cache the last location returned, and then give you this cached location next time you start updating again, so if a fresh position is important, check the timestamp property of the returned location.

It’s not possible to make the delegate method return (it wants to get you the best location it can!) but you can examine the properties of the location returned each time and work out whether or not you want to use it, or wait for a better one.

Here’s an example of how we used it: (Sorry it’s a bit compressed, it’s a skinny column!)

- (void)didUpdateToLocation {

// get lat and lon here from the response

// Check if we're interested in the response
if(ignoreAllOtherResponses == NO){

 // and are we within agreed number of updates
 if(numberOfUpdates < maxNumLocationUpdates){

   // check accuracy and timestamp of response
   if(response < requiredLocationAccuracy
   	&& interval < maxCachedLocationAge){

    // we've got the location we need so stop
    // updating and ignore any subsequent responses
    [locationManager stopUpdatingLocation];
    ignoreAllOtherResponses = YES;

   }
   else {

    // Feedback: "Got location to within n meters
    still trying etc etc.."

   }

  // And if we're still listening, then by the time
  // we've reached our agreed maximum number of
  // updates just take this as the final answer as long
  // as it's *at least as accurate as the previous one*
 }
 else {

   double finalResponse = newLoc.horizontalAccuracy;
   double lastResponse = oldLoc.horizontalAccuracy;

   if(finalResponse <= lastResponse) {

     [locationManager stopUpdatingLocation];
     ignoreAllOtherResponses = YES;

   }
  else {

    // Feedback: "Cant get an accurate enough
    location at the moment"

  }

  // stop the timer and stop updating location
  [locationManager stopUpdatingLocation];
  [updateTimer invalidate];

 } // end if (numberOfUpdates < maxNumLocationUpdates)

 numberOfUpdates++;
 [newLat release];
 [newLon release];

 } // end if(ignoreAllOtherResponses == NO)

}

Comment » | CoreLocation, development, iPhone

Papervision InteractiveScene3DEvent object_over & object_out broken mouse interactivity

4:23 pm on November 26th, 2009, by jeff

When creating a 3d environment with lots of movement, beware of InteractiveScene3DEvent.

Im my scene i have a number of moving objects that have listeners that fire InteractiveScene3DEvent’s.

Object_over and object_out, (the equivalents to mouse_over and mouse_out on a display object in 2D) will NOT RECEIVE those events if the mouse is kept still.

Think thats quite ridiculous to be honest, they should be active on idle by default. Apparently this is a know issue in the papervision project pages.

http://code.google.com/p/papervision3d/issues/detail?id=205

The standard workaround increases the CPU load. Im going to look into the issue more and see if i can find a efficient solution… I let you know how i get on.

Comment » | Uncategorized

AS3 Json integration quick and dirty

4:03 pm on November 2nd, 2009, by jeff

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

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.

Comment » | 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

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

Loading JSON from another domain with jQuery

12:15 pm on March 25th, 2009, by Clare

Following this example on the JQuery docs only got me so far.
I knew that you needed to pass a URL to getJSON() and append a callback parameter to the end of it:

$.getJSON(“http://www.example.com? jsoncallback=?”);

But then what? JQuery will look at the data returned for a call to ‘jsoncallback’ so
to get this to work you’ll need your server side code to return a snippet of JavaScript too.
Wrap the JSON output in a call to ‘jsoncallback’:

jsoncallback ({"name" : "hello world"});

jQuery will replace the questionmark at the end of the URL with this function call which will be executed by the client, so therefore we need to define the jsoncallback function too:

function jsoncallback(data){

// do some stuff with the JSON here!

}

1 comment » | ajax, javascript, js