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

31 posts in 31 days all in May

I am going to post every day this month.  Most posts with be ActionScript Errors but I will also include tutorials and Flash SEO and Google Analytics reports and info.  Sometimes just for kicks I will throw in some marketing and random thoughts.  So look for daily post in May.

FYI – Because Sunday is a special day for me I will not be posting on Sundays but will make up for that on other days.

Thanks and Happy Flashing

Curtis J. Morley

Google Analytics and Flash

Google Analytics and Flash – Pick a Logo Experiment?

Thanks for your help in picking a new logo for my site. This experiment is a follow-on to my posts about integrating Google Anayltics and Flash. Thanks to Clint Rogers for the opportunity to present my findings at BYU on March 27, 2008. There are many things to consider when considering how to Integrate Flash and Google Analytics. With your help I can test my assumptions. This will gather data and tally votes using nothing more than Google Analytics.

I want to give a special thanks to my friend and fantastic designer Larry Lee Lentz II for his help on these logos and design.

Thanks and 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

AS3 Error 1120

ActionScript 3 Error #1120: Access of undefined property myButton_btn.

Description:
ActionScript error #1120 means that an object “property” within Flash or Flex is not defined. But this doesn’t really help you fix it. One main reason for this AS3 Error is that you haven’t given the MovieClip or Button an instance name when you placed it on the stage in Flash. Another reason is that the reference is not correct.

AS3 Error 1120 –Fix1:
Give your instances a proper instance name.

Bad Example:

Flash properties dialog without an instance name Flash properties dialog without an instance name

Good Example:

Flash Properties Dialog with Instance Name Flash properties dialog with MovieClip instance name

ActionScript 3 Error #1120: Access of undefined property myBatton_btn.

AS3 Error 1120 –Fix2:
Check that your reference is the proper instance name.

Bad Code:

myBatton_btn.addEventListener(MouseEvent.CLICK, someFunction);

Good Code:

myButton_btn.addEventListener(MouseEvent.CLICK, someFunction);

 

ActionScript 3 Error #1120: Access of undefined property ftouchBeginHandler.

AS3 Error 1120 – Fix3:
Make sure that you are calling the function with the correct name.

Bad Code:

square.addEventListener(TouchEvent.TOUCH_BEGIN, touchBeginHandler);
function fl_TouchBeginHandler(event:TouchEvent):void
{
//Drag something
}

Good Code:

square.addEventListener(TouchEvent.TOUCH_BEGIN, touchBeginHandler);
function touchBeginHandler(event:TouchEvent):void
{
//Drag something
}

 

This should help you fix Flash AS3 Error #1120.

As Always, Happy Flashing

Curtis J Morley

ActionScript Warning #1100

Warning: 1100: Assignment within conditional.  Did you mean == instead of =?

Description:
AS3 warning 1100 is Adobe watching out for you and helping you out.  Flash/Flex let’s you know that you are assigning a variable while at the same time evaluating to see if it is true.  This AS3 warning is quite easy to understand and well written.

Fix:
To solve Flex/Flash Warning 1100 all you need to do is add another ” = ” sign inside your conditional making 2 == rather than just one.

Bad Code 1:

if (topFive[i]=“one”) {

Good Code 1:

if (topFive[i]==”one”) {

Note: This is not ActionScript Error #1100.  Click this link to find AS3 Error #1100.
This should help you resolve Flash / Flex Warning #1100

Thanks and as always Happy Flashing

Curtis J. Morley

Google Releases the New YouTube API’s for Flash

Google has finally caught up with the likes of FaceBook, Flickr, Photobucket, MorgueFile, Webshots, Picasa, and Smugmug. I knew it wouldn’t take them long. The new API sounds like the perfect solution for Flash YouTube Mashups. Web based applications like BrainHoney, SlideShare, Sprout and worldtv will be able to integrate the solution fairly effortlessly now and keep the look and feel that they want. I imagine that more online and Flash based video editing applications like Jumpcut, Aviary, and RichFLV will be developed.

An article on InternetNews.com has the following to say:

“The new APIs will enable developers to create “chromeless” Flash players with a customizable interface built on YouTube software, but without the YouTube branding. Instead, YouTube is asking developers to place a “Powered by YouTube” button on the pages of their sites that contain the API-enabled video players.

Developers will be able to upload videos and responses to YouTube from any device, including cell phones and other handhelds. The APIs will also allow developers to augment the video content on their sites with metadata, such as titles, descriptions, ratings and comments.”

Article/press release on the subject.
www.InternetNews.com

To get into the details of the YouTube API

http://google-code-updates.blogspot.com/2008/03/youtube-apis-for-developers-and-for.html

To find out about the features including the chromeless player and get a look at who Geoff Stearns the SwfObject Genius is.
http://youtube.com/watch?v=u1zgFlCw8Aw

This is great news for all of us Flashers in the worlds 🙂 Thanks Jasson and Thanks YouTube.

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