About Orland MediaDevelopmentTrainingBlogRSS FeedContact us
Microphone

getDefinitionByName() produces ReferenceError: Error #1065: Variable is not defined

Date: Thursday 3rd September 2009
Time: 16:44
Category: ActionScript 3.0
Views: 585
Comments: 4 Comments

Scenario

Something we often do here is get the “id” of a clicked menu button and instantiate a section of a site, depending on the ID passed. Usually all sections of a site inherit from a generic “Section” class, then have additional specific capabilities depending on the section. So, depending on the ID passed, we need to create an instance of the particular class. This means we need to get the class name dynamically from the string passed by the button.

Let’s imagine the “music” button was pressed. We’ll either have a listener for this or we’ll directly call a method called loadSection(), passing the ID (the name of the button usually). We name instances in camel notation, so that’ll be “music”.

This string goes over to the loadSection() method and in here we use a custom StringUtils class to covert the first letter to upper case, getting us the required class name as a string. So this gives us “Music”. A string is no good on its own though – we need to get the class reference for this, as follows:

// required "dummy" ref to ensure class is compiled...
var dummyRef:Music;
...
// get class reference
var classRef = getDefinitionByName(id);
// instantiate class instance as current section
section = new classRef();


Problem

All well and good. The trouble is sometimes it just doesn’t work and you’ll get:

ReferenceError: Error #1065: Variable Music is not defined

There’s a thread here where the person was getting this, and it drifted off into another debate without being solved. The import statement is there. The dummy class reference is there, but still it doesn’t work.


Solution

What is not immediately clear is that you need to provide a fully qualified class path to getDefinitionByName() – even though you have set up an import.

Amend as follows (for example) and your problem is solved:

// var classRef = getDefinitionByName(id);
var classRef = getDefinitionByName("sections." + id);

“sections.” here is a reference to our package structure.

We hope this helps you.

Social bookmarks
  • Digg
  • Twitter
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • email
  • Reddit
  • StumbleUpon
  • LinkedIn
  • Print
Rate this post
1 star2 stars3 stars4 stars5 stars   (1 votes, average: 5.00 out of 5)

Shadowbox not loading images or flash

Date: Saturday 29th August 2009
Time: 12:45
Category: Other
Views: 482
Comments: No comments

An excellent alternative to the Lightbox script is Shadowbox, because it enables the display of multiple formats, including Flash. We use it on our projects page.

The trouble is, you might find that it just isn’t loading images – or Flash content. Yet again this seems to be a side-effect of Adblock Plus. It seems like avoiding ads comes at a price! Just disable Adblock Plus in Firefox and the problem will go away.

We don’t have a work-around for this yet, so if you do, please comment. :)

Social bookmarks
  • Digg
  • Twitter
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • email
  • Reddit
  • StumbleUpon
  • LinkedIn
  • Print
Rate this post
1 star2 stars3 stars4 stars5 stars   (1 votes, average: 3.00 out of 5)

Fullscreen Flash Player on dual monitors

Date: Wednesday 12th August 2009
Time: 11:23
Category: Adobe Flash
Views: 824
Comments: No comments

If you are using dual monitors, as many developers do, it might be that you sometimes want a video running, fullscreen, on one monitor while you work on the other. The trouble is, Flash Player 10 is so designed that once the former monitor loses “focus” (i.e. you click on the other one), it will exit fullscreen. Some people even consider this a bug.

Luckily, there’s a fix available. Since it is not obvious how this issue could be a security concern, perhaps Adobe will consider implementing the functionality in the next Flash Player.

Social bookmarks
  • Digg
  • Twitter
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • email
  • Reddit
  • StumbleUpon
  • LinkedIn
  • Print
Rate this post
1 star2 stars3 stars4 stars5 stars   (1 votes, average: 2.00 out of 5)

Taylor Swift plays our game

Date: Wednesday 5th August 2009
Time: 00:26
Category: Other
Views: 186
Comments: No comments

The latest free Adobe Flash Player™ is required to view this content.

Get Adobe Flash Player

We designed and programmed a Love Calculator for the BBC back in 2001. The algorithm inside it mimics a children’s playground game by sorting through the letters in names.

The game still pulls in traffic to the BBC’s site 8 years later, and here you can see none other than country/pop star Taylor Swift playing it live on air. :)

Social bookmarks
  • Digg
  • Twitter
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • email
  • Reddit
  • StumbleUpon
  • LinkedIn
  • Print
Rate this post
1 star2 stars3 stars4 stars5 stars   (Roll over and click)

AS3 training course

Date: Wednesday 29th July 2009
Time: 11:11
Category: ActionScript 3.0
Views: 121
Comments: 1 Comment

Due to popular demand, we are scheduling another ActionScript training course for 26-28th August 2009, in central London.

If you would like to reserve a place please get in touch.

Social bookmarks
  • Digg
  • Twitter
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • email
  • Reddit
  • StumbleUpon
  • LinkedIn
  • Print
Rate this post
1 star2 stars3 stars4 stars5 stars   (Roll over and click)
Older posts
Lenovo Microsoft Adobe Heart Internet Envirowise
Copyright © 2008 Orland Media Ltd | All rights reserved Company details Ethical policy Terms & conditions Privacy policy