ActionScript ReferenceError: Error #1056

ReferenceError: Error #1056: Cannot create property _x on flash.display.Sprite

or

ReferenceError: Error #1056: Cannot create property someVar on flash.text.TextField.

ActionScript 3 Error #1056 Description:
AS3 error 1056 appears when you have improperly referenced a property of an object. This will happen when you misspell something or when you reference variables in the AS2 fashion with a leading underscore ( _ ). AS3 error 1056 is actually pretty nice to work with because it tells you exactly what variable didn’t work and it tells you which object it didn’t work on.

You can also get this error if you try to dynamically assign a variable to an object that doesn’t naturally accept one like a textField.  See Bad Code 3.

Flash / Flex Error 1056 Fix:
Simply spell the property correctly or make sure that you are using AS3 Syntax instead of AS2.


Bad Code 1:

var s = new Sprite();
s._x = 100;

Good Code 1:

var s = new Sprite();
s.x = 100;

Bad Code 2:

var t = new Timer(1000, 4);
t.dela = 500;

Good Code 2:

var t = new Timer(1000, 4);
t.delay = 500;

Bad Code 3:

myTextField.someVar = “something”;

This should help you resolve Flex / Flash Error #1056

Thanks and as always Happy Flashing

Curtis J. Morley

Related ActionScript Error(s):
Flash / Flex Error 1119
– You will get AS3 Error 1056 instead of 1119 if you don’t properly type your object before referencing a property on it. For example var s:Sprite = new Sprite(); s._x = 10; will give error 1119 but var s = new Sprite(); s._x = 10; will give Error 1056.
Flash / Flex Error 1151
Flash / Flex Error 1069
– This is the error you will get if you try and call a method with a misspelled name in the same way as calling a property with a misspelled name.

Flash / Flex 3 Error #1061: Call to a possibly undefined method gotoAndStop through a reference with static type flash.display:DisplayObject.

ActionScript 3 Error #1061: Call to a possibly undefined method gotoAndStop through a reference with static type flash.display:DisplayObject.

ActionScript 3 Error #1061: Call to a possibly undefined method gotoAndStop through a reference with static type flash.display:DisplayObjectContainer.

ActionScript 3 Error #1061: Call to a possibly undefined method gotoAndStop through a reference with static type flash.display:Stage.

Description:
AS3 error 1061 will pop up when you trying to referencee an object from within a function that receives an Event. When you do this it will reference the DisplayObject or if you call out to this.parent rather than event.target.parent it will reference the DisplayObjectContainer which doesn’t have a lot of methods with it.

Fix:
One solution to solve Flex/Flash Error 1061 is to make sure that you are using the event that is passed as the target by using

Bad Code 1:

getStarted_btn.addEventListener(MouseEvent.MOUSE_UP,gotoFrame10 );

function gotoFrame10 (e:MouseEvent)
{
this.parent.gotoAndStop(10);
}

Good Code 1:

getStarted_btn.addEventListener(MouseEvent.MOUSE_UP, gotoFrame10);

function gotoFrame10 (e:MouseEvent)
{
e.target.parent.gotoAndStop(10);
}

This should help you resolve Flash / Flex Error #1061

Thanks and as always Happy Flashing

Curtis J. Morley

Flex / Flash Error #1151

ActionScript Error #1151: A conflict exists with definition progBar in namespace internal.

ActionScript 3 Error #1151
Description:
AS3 error 1151 is an easy one. This means that within your ActionScript class(namespace internal) there is already a variable or function by that name.

Fix:
To solve Flex/Flash Error 11151 just hit CTRL-F(Apple-F) and search for that term that has a conflict and change it to something appropriate. You may have been building a particle system or working with an X or Y variable and forgot to change one of them so that they both read exactly the same. The example below shows what I mean and how to solve the issue.

Bad Code 1:

public class Particle extends Sprite
{
public var xVelocity:Number;
public var xVelocity:Number;

Good Code 1:

public class Particle extends Sprite
{
public var xVelocity:Number;
public var yVelocity:Number;

This should help you resolve Flash / Flex Error #1151

Thanks and as always Happy Flashing

Curtis J. Morley

Related Error(s) : ActionScript Error #1024 , ActionScript Error #1056

Flash CS3 / Flex 2 AS3 Error #1118

ActionScript Error #1118: Implicit coercion of a value with static type Object to a possibly unrelated type flash.display:DisplayObject

ActionScript Error #1118 can be caused by working with the Display Object. What happens is that as soon as you put a MovieClip, Sprite, etc… into the DisplayObject Flash/Flex thinks that any parent is of Type DisplayObject. Even though you know perfectly well that the object that contains your Sprite is another Sprite or MovieClip Flex and Flash don’t know it. You may have encountered this Flex/Flash Error when you tried to call this.parent from within a Sprite or Flash MovieClip after using addChild() (among others) to display or modify the display of a MovieClip/Sprite on the stage. The compiler doesn’t keep track of the Type that the parent is so when you call parent the compiler is confused. Instead it assigns the Type DisplayObject. Your code should still keep working even if you get this error, but there is a reason why the compiler gives you this error. I will show you how to get around this error and how to prevent yourself from getting this error in the future. This AS3 Error can happen any time that you are using any of the following methods:

  • addChild(); Adds a child DisplayObject instance to this DisplayObjectContainer instance.
  • addChildAt(); Adds a child DisplayObject instance to this DisplayObjectContainer instance.
  • contains(): Determines whether a display object is a child of a DisplayObjectContainer.
  • getChildAt(); Returns the child display object instance that exists at the specified index.
  • getChildByName(): Retrieves a display object by name.
  • getChildIndex(): Returns the index position of a display object.
  • setChildIndex(): Changes the position of a child display object.
  • swapChildren(): Swaps the front-to-back order of two display objects.
  • swapChildrenAt(): Swaps the front-to-back order of two display objects, specified by their index values.

Another reason you may get this ActionScript3 Error is by having an external class that is assigned to an object at runtime. Because the class is not predetermined therefore the compiler chokes.

AS3 Error #1118 Solution. You can resolve AS3 Error #1118 by doing one of three things. The first and most highly suggested is to change the way you code. Think from an outside-in perspective when coding rather than an inside-out mentality. The second is to cast the object as the proper Type which explicitly tells the compiler the type of the parent. The third is to just turn off verbose comments in your settings. I don’t suggest doing this last fix as it could lead to many more headaches and is horrible when working with a team.

AS3 Error 1118: Fix #1 – Object Oriented Scripting. Code with an outside-in perspective. This means that instead of the child telling the parent what to do the parent tells the child what to do. This may become tricky if you are completing an animation and need an event to happen when the inner movieClip reaches a certain frame. It is still possible and I may post a tutorial on how to do this with Flash in the near future. But this post is not the right place for it. You can pick up Essential ActionsCript 3 by Collin Moock for a great reference and starting point.

AS3 Error 1118: Fix #2 – Cast the object as the type that you know it is. If you know that it is a MovieClip then tell Flash that it is a MovieClip. You do this by Casting the object as shown below.

Bad Code:

this.parent.doSomething();

Good Code:

MovieClip(this.parent).doSomething();

or

(this.parent as MovieClip).doSomething();

AS3 Error 1118: Fix #3*Warning* This method will solve the problem temporarily and allow you to publish your code BUT it will cause you many headaches later. You will not get any warnings or error messages and this is a bad thing I Promise! If you are going to proceed down this path make sure to recheck these boxes after you are done publishing your one problem movie. With that much said, The way you do this is to turn off Strict (Verbose) Error Messages in your preferences as shown below.

Go to File >> Publish Settings >> Click on the “Flash” tab >> Next to “ActionScript version:” click the “Settings…”

AS3 Error 1118 -Implicit Coercion

Thanks and as always Happy Flashing,

Curtis J. Morley

ActionScript Error #1024

ActionScript Error #1024: Overriding a function that is not marked for override.

Description:
AS3 error 1024 means that Flash or Flex already has a function by that name.

Fix:
To solve Flex/Flash Error 1024 all you need to do is either correctly name the function something besides a reserved function in Flex/Flash or properly override the function. The example below shows how to solve issue number one. Notice that the good code solves Error 1024 because it doesn’t use the same name as a function that already exists in ActionScript.

Bad Code 1:

function nextFrame (e:MouseEvent):void
{
this.nextFrame();
}

Good Code 1:

function onNextFrame (e:MouseEvent):void
{
this.nextFrame();
}

This should help you resolve Flash / Flex Error #1024

Thanks and as always Happy Flashing

Curtis J. Morley

Speaking on Flash and Flex at UVSC

Thanks to Thor for having me come present in the Multimedia Dept. The class was great. As promised here are the links to examples, applications, and books that I talked about.

Applications that I have been a part of

Rifle Builder – Shopping Cart application built originally in Flash 5
LDS.org/cm – The Original Interactive Sheet Music Player
MusicRain.com
– Commercial Interactive Sheet Music
LogoMaker.com – HP Purchased LogoMaker in-part because of the success of this application.
Thanksgiving Point Dinosaur Games – Click on the “Games and Coupons” button
RideHarder.com – New design by Element
SolutionOverview.com – Green Screen interactive video
BrainHoney – Learning tool for self publication, uses mashups and Facebook integration. upload whatever files you want and make a lesson or learn what you don’t know.

Applications turned into web apps:

Photoshop:
http://www.flauntr.com/
http://www.picnik.com/app#/home/welcome

http://www.splashup.com/
– Fauxto now caled Splashup This is the most fully featured one I have found.

Mapping –
FlashEarth.com
maps.yahoo.com

Microsoft Word:
BuzzWord.com
Grant Skinner Spell Checker for text editing

Image seam carving:
http://swieskowski.net/carve/ – Neat example
http://www.quasimondo.com/archives/000652.php – Example with code
http://rsizr.com/ this one is amazing and you can do it yourself

Video Editing:
RichFLV – Flash Based Video Editing Tool done with Flash/Flex and published with AIR

Motion detection & Vid Cam like Minority Report etc..
incomplet.gskinner.com

Sheet Music Applications –
LDS.org/cm – The Original Interactive Sheet Music Player
MusicRain.com
– Commercial Interactive Sheet Music

Books:
Adobe Digital Editions

Quicken:
mint.com – Web based version of Quickenfor money management

The Radio:
www.pandora.com – the music genome project

iTunes:
www.anywhere.fm/player

Outlook:
www.goowy.com/index.aspx – Flash web based Outlook knock-off.

Great Books For Flash, Flex, and ActionScript –

ActionScript

Intermediate Books

Begining Books

Books not to buy

  • AS3 Game Programming University – Only buy this book if you have never used Flash. The games are good BASIC games but the graphics are horrible and the examples don’t really teach the prinicples behind game design.
  • Flash CS3 The missing manual. – You might as well buy the Dummies book(see below) if you are going to buy this one. Not a good place to start. Not comprehensive. Not well written.
  • Flash CS3 On Demand – This book should not be allowed to be called CS3 because some of the examples are not even using AS3. If you own Flash 8 then you will want this book but not for CS3.
  • Flash CS3 for Dummies – You are not a dumb, but may feel like it after spending any money on this book. They do have good cartoons though.

Thanks,

Curtis J. Morley

Flex / Flash ActionScript Error #1065

ActionScript Error #1065: Variable MyClassName is not defined.

Description:
This ActionScript error means that Flash or Flex does not understand the definition of your Class. One reason for this is that you forgot to declare your class as public. Another reason is that the reference is not correct. Don’t be deceived by the word Variable in this error it is really a class.

Fix:
Add public before the name of your class.

Bad Code:

class MyClassName extends MovieClip

Good Code:

public class MyClassName extends MovieClip

Fix 2:

Correctly reference the class that is being used.

Good luck trouble shooting ActionScript Error #1065 and,
As always Happy Flashing

New info on ActionScript Error #1093

I have posted new 3 more fixes for ActionScript Error #1093. Thanks to grildCheese for leaving the comment about fix #3. You can view AS3 Error #1093 here. This Flash error is absolutely nondescript so read this fix and instead of going nuts trying to fix it.

Thanks and Happy Flashing.

SWFObject.addVariable() in AS3

SWFObject.addVariable() in AS3

SWFObject is the standard for embedding Flash files into HTML. If you haven’t used it run on over to Geoff Stearns site and download yourself a heapin’ helpin’ of some SWFObject. If you are feeling especially adventuresome and want to test out the latest features in the new SwfObject 2.0 then head over to the SwfFix development blog. SWFObject eliminates the need to click on the Flash piece on a website before being able to interact with it, it has plug-in detection, it can be used with popular blogging software on sites such as this, and there are plugins for Dreamweaver and as a publish setting right in Flash. You should be using this for every website you build.  As of the 15th of February (I wonder what they were doing on Valentines Day) you can even download an SWFObject Adobe Air app for generating the proper code to embed your SwfObject into your website.  It employs the new SWFObject 2.0.  Or for quick and easy access just use the web version to generate your swfObject code

Now that you are totally sold and will never build anything Flash without it, you may want to inject variables (FlashVars) into your swf.  The methods are different for AS2 and AS3.  It is quite easy, yet different in each of these versions of ActionScript.  You simply throw the following code into the HTML and then …

<div id=”flashcontent”>
Swf Audio is not loaded Please check your path. this should be an audio control built in flash.</div>

<script type=”text/javascript”>

var so = new SWFObject(“SoundControlTest2.swf”, “audioControl”, “240”, “24”, “8”, “#EFECDD”);
so.addVariable(“audioURL”, “AllThatIWant.mp3”);
so.addVariable(“audioURL2”, “Comfort.mp3”);
so.addVariable(“audioURL3”, “Jolene.mp3”);
so.addVariable(“audioURL4”, “Amazing.mp3”);
so.write(“flashcontent”);
</script>

…then in your Document class (or on the MainTimeline if you are not using a Document Class) you will need to reference the parameters property of the loaderInfo property like this:

myTextBox.text = this.loaderInfo.parameters.audioURL;

In AS2 you only can access the variable directly on the mainTimeline using something like this:

myTextBox.text = audioURL;

Hope this helps you (and your users) have a better Flash experience on the web.

As always Happy Flashing.

Curtis J. Morley

Flex 2 / Flash CS3 ActionScript Error #1105

ActionScript Error #1105: Target of assignment must be a reference value.

Description:
This ActionScript error simply means that you are trying to assign a value to something that is already a value and not a variable or a writable property. Adobe Live Docs actually has a pretty good definition about this one. It says, ” You can assign a value to a variable, but you cannot assign a value to another value.” To make this simple let me use an example. An array has a property length. An XMLList also has a property called length() . Pay attention to the parenthesis. An array will let you change the length of the array simply by calling my_array.length = 2; because it is a readable and writable property. When using XML however the length property is only readable so my_xml.length() = 0; is like saying 2 = 0; You can not change the value 2.

Fix:
When you get this ActionScript error make sure to check that you are not trying to change a value. Also make sure that the property is readable and writable.

Bad Code:

my_xml.children().length() = 0;

Good Code:

package{
	public class MySize {
		private var size:uint = 40;
		protected function Connection():void{
			trace(size);
		}
	}
}

Good luck trouble shooting ActionScript Error #1105 and,
As always Happy Flashing