AddChild in AS3 error
In Flash CS5 I am trying to load an image from a class and I am getting
Call to a possibly undefined method addChild. In the class file
Not sure how to fix this as I have a sprite class and believe I have done everthing correct.
The image is in the same folder as the .fla and .as file
//class
package {
import flash.display.*;
public class ClassImg extends Sprite{
import flash.display.Bitmap;
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLRequest;
import flash.text.*;
public function ClassImg() {
var loader:Loader = new Loader;
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
loader.load(new URLRequest("ladybug.png"));
private function imageLoaded(event:Event):void
var image:Bitmap = new Bitmap(event.target.content.bitmapData);
image.x=10;
image.y=10;
this.addChild(image); //error is here and I tried just addchild
//in .fla
var li:ClassImg= new ClassImg();
addChild(li);
yes it works with the import statements in the other area. I must say it took over a day for someone to find the answer to this so well done again.
q1)Now I am new to this so I believe I need to display an image in a sprite or movie clip container and by extending the class with sprite I am doing this?
q2) Say I want to make a call to a method in the class which moves the image position to say 200,200.
How do I set the image to a variable and simply move it?
The issue is I need an event to tell me the bitmap has loaded so in the fla file I can then be able to move the image.
PS I dont get that error and I need the sprite and not movie clip. I am using flash CS5 trial. I would like to know why you get this problem
Similar Messages
-
When I click a leaf in the Tree Component I have a function
called using the itemClick Property. When I click a node (the
folder icons) I get the AS3 error below. Does this only show up
with Debug versions of Flash Player. Plus how do I stop this error
from occurring if the user happens to have the debug version
installed?
Error #2044: Unhandled ioError:. text=Error #2032: Stream
Error.
at main/loadMyXML()
at main/collectionSelect()
at main/__gTree_itemClick()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()
at mx.controls.listClasses::ListBase/mouseClickHandler()
at mx.controls::Tree/mouseClickHandler()ORA-00600 internal errors should be reported to Oracle Support by SR. If you don't have a support contract try searching the web for more information and possible fixes or workarounds.
From the information available on MOS, if the type of the PG.ID_PAR_PLANO_GER column is not VARCHAR2, then try converting P22_ID_PAR_PLANO_GER to the same type. -
Captivate AS3 errors in firefox?
Hello,
I'm having an issue with AS3 errors coming up on the first slide of my training/quiz in firefox. I am using captivate 4. This is what is showing up:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at captivate.Veela_AS3::rdQuizPlaybackController/get currentSlideContainer()
at MMQuizzingV4_AS3.MMQuizClasses::PlaybackController/allowedToGoToSlide()
at captivate.Veela_AS3::rdMovie/gotoSlide()
at captivate.Veela_AS3::rdMovie/JumpToSlide()
at captivate.Veela_AS3::cpTOCManager/delayedGoToSlide()
at Function/http://adobe.com/AS3/2006/builtin::apply()
at SetIntervalTimer/onTimer()
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()
The error will not show up in IE.
I have doublechecked my project preferences and it is indeed set to AS3. I have imported a small .swf to each slide with VERY basic animation just simple tweens. There is some actionscript on the imported .swfs such as stop or switch statements. Nothing that is rocket science and it validated in flash. These errors seem to be coming from the captivate program itself. I have to integrate this training into an LMS will these errors mess that up?If anyone had some time or insight I would be very appreciative!
Cheers!
-MattPossibly the problem discussed in these threads:
strange tags
HTML tags showing up in the pages also in 2.0? -
AddChild gives an error#2006
When I populate a TabNavigator through mxml, it works
perfectly
When I do it using ActionScript with the
addChild(item:DisplayObject) method i get an out of bounds error.
How is this possible as i don't manipulate the childIndex?
=_=
Hopefully, someone got the same error :(
LaurentOk, just found an answer..
the displayObject I am trying to add is a canvas in which I
just add a children. So I think the chain of addChild method calls
was too quick and the computer couldn't follow.
Remember to let some delay between addChild ;)
Hope, it will help people.
Laurent -
Full Browser in AS3 - Error #1009
Please Help...
I'm learning AS3 and Flash CS4 right now and I'm trying to do what I have been doing in AS2 for years and I'm having some problems. I'm trying to make a Full-Browser Flash site and upon resizing the screen I get an error #1009.
I am able to to resize the mc's on the screen without a problem, but once I add simple interactivity, I get an error upon resizing the window.
To duplicate this problem,
1. Test the movie
2. Click on either circle
3. Then click on the opposite circle.
4. Then either resize or maximize the window and you will see the "Output window" with the Error #1009
I'm sure I'm doing something very stupid, but I just don't know what I'm doing wrong.
Here's a link to the fla file: http://plusonedesigngroup.com/test/nosaletest.fla
Please Help!
Thanks in advance,
Mike.doghouse.
Yes, I was able to download your file and Thank You for trying to help. The problem for me is I have no idea where to begin with your file... There are 35 ".as" files controlling this movie and I'm very new to AS3.
Isn't there a simple way to control the timeline of a flash movie while using the full browser?
Thanks,
Mike. -
Why does AS3 error when opening AS2 sharedObject
I have a .sol file that can be opened using AS2 but when AS3 opens it i get RangeError: Error #2006: The supplied index is out of bounds.
at flash.net::SharedObject$/getLocal()
I have tried the SharedObject.defaultObjectEncoding = ObjectEncoding.AMF0 but this is for writing, not for reading. Not sure what to do but to trap/suppress the error. Does not solve the issue, any takers? If it works in AS2 then it should work in AS3!If it works in AS2 then it should work in AS3!
no. you can expect the as3 compiler (when in strict mode) to detect errors that as2 bypasses.
click file/publish settings/flash and tick "permit debugging". retest. the problematic line number will be in the error message. -
I have a class on compilaton it shows some error.
/// the class ///
package bin{
import flash.display.MovieClip;
import flash.events.*;
import flash.display.LoaderInfo;
public class Preloader extends MovieClip {
public var ldrInfo:LoaderInfo;
//var textFieldCount:TextField;
public function Preloader(ldrInfo:LoaderInfo = null) {
// constructor code
addEventListener(Event.ENTER_FRAME,playme);
this.ldrInfo=ldrInfo;
stop();
function checkFrame(e:Event):void {
if (this.totalFrames==this.currentFrame) {
dispatchEvent(new Event("animationComplete"));
function playme(e:Event):void {
trace("playme...");
textFieldCount.text=String(Math.floor(ldrInfo.bytesLoaded/ldrInfo.bytesTotal*100));
trace(ldrInfo.bytesTotal);
if (ldrInfo.bytesLoaded==ldrInfo.bytesTotal && ldrInfo.bytesTotal!=0) {
play();
removeEventListener(Event.ENTER_FRAME,playme);
addEventListener(Event.ENTER_FRAME,checkFrame);
Following line
textFieldCount.text=String(Math.floor(ldrInfo.bytesLoaded/ldrInfo.bytesTotal*100));
generates error
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at bin::Preloader/playme()
please suggest me what it is!!package {
import flash.display.MovieClip;
import flash.events.*;
import flash.display.LoaderInfo;
public class Preloader extends MovieClip {
public var ldrInfo:LoaderInfo;
//var textFieldCount:TextField;
public function Preloader() {
// constructor code
addEventListener(Event.ENTER_FRAME,playme);
stop();
function checkFrame(e:Event):void {
if (this.totalFrames==this.currentFrame) {
dispatchEvent(new Event("animationComplete"));
function playme(e:Event):void {
trace("playme...");
// textFieldCount.text=String(Math.floor(ldrInfo.bytesLoaded/ldrInfo.bytesTotal*100));
var total:Number = this.stage.loaderInfo.bytesTotal;
var loaded:Number = this.stage.loaderInfo.bytesLoaded;
trace(total);
if (loaded==total && total!=0) {
play();
removeEventListener(Event.ENTER_FRAME,playme);
addEventListener(Event.ENTER_FRAME,checkFrame); -
1084: syntax Error : colon was expected before minus. I can't
work it out. neither to solve ityes. line 40
return {backgroundColor:"#000000",
backgroundGradientAlphas:"backgroundGradientColors",
compiledLocales:["en_UK"],
compiledResourceBundleNames:["containers", "controls", "core",
"effects", "skins", "styles"], creationComplete:"init()",
currentDomain:ApplicationDomain.currentDomain,
fonts:{Gotham-Light:{regular:true, bold:false, italic:false,
boldItalic:false}}, horizontalScrollPolicy:"off",
layout:"absolute", mainClassName:"Lafactorie",
mixins:["_Lafactorie_FlexInit", "_alertButtonStyleStyle",
"_ScrollBarStyle", "_activeTabStyleStyle",
"_textAreaHScrollBarStyleStyle", "_ToolTipStyle",
"_advancedDataGridStylesStyle", "_comboDropdownStyle",
"_ContainerStyle", "_textAreaVScrollBarStyleStyle",
"_linkButtonStyleStyle", "_globalStyle", "_windowStatusStyle",
"_windowStylesStyle", "_activeButtonStyleStyle", "_errorTipStyle",
"_richTextEditorTextAreaStyleStyle", "_CursorManagerStyle",
"_todayStyleStyle", "_dateFieldPopupStyle", "_plainStyle",
"_dataGridStylesStyle", "_ApplicationStyle", "_SWFLoaderStyle",
"_headerDateTextStyle", "_ButtonStyle", "_popUpMenuStyle",
"_swatchPanelTextFieldStyle", "_opaquePanelStyle",
"_weekDayStyleStyle", "_headerDragProxyStyleStyle",
"_LafactorieWatcherSetupUtil",
"_de_metascreen_Lafactorie_contents_ContentContactWatcherSetupUtil",
"_de_metascreen_Lafactorie_contents_ContentEventsWatcherSetupUtil",
"_de_metascreen_Lafactorie_contents_ContentStoresWatcherSetupUtil",
"_de_metascreen_Lafactorie_contents_ContentAboutWatcherSetupUtil",
"_de_metascreen_Lafactorie_navigation_NaviItemWatcherSetupUtil",
"_de_metascreen_Lafactorie_views_ContentBereichWatcherSetupUtil"],
paddingBottom:"0", paddingLeft:"0", paddingRight:"0",
paddingTop:"0", preloader:PreloaderDisplayBase,
verticalScrollPolicy:"off"}; -
Custom Combo Box. Error # 2025
package files{
import flash.display.MovieClip;
import fl.data.DataProvider;
import fl.controls.ComboBox;
import flash.text.*;
import flash.display.Sprite;
import flash.filters.*
public class CustomComboBox extends MovieClip {
public var xLoca:Number;
public var yLoca:Number;
public var dataProvider:DataProvider;
public var cboClip:MovieClip;
public function CustomComboBox(xLoca:Number, yLoca:Number, dataProvider:DataProvider, prompt:String = "Select") {
cboClip = new MovieClip;
this.xLoca = xLoca
this.yLoca = yLoca
this.dataProvider = dataProvider;
var typeTextFormat:TextFormat = new TextFormat();
typeTextFormat.color = 0x333333;
typeTextFormat.size = 11;
typeTextFormat.font = "Verdana";
var menu1:ComboBox = new ComboBox();
cboClip.addChild(menu1);
var typeButton:Sprite = new Sprite();
menu1.addChild(typeButton);
typeButton.graphics.beginFill(0xCCCCCC);
typeButton.graphics.drawRect(0, 0, 109, 34);
typeButton.graphics.endFill();
typeButton.alpha = 0.75;
typeButton.filters = [new DropShadowFilter(3,120,0x000000,0.5,0,0,1,1,false,false,false)];
var dropButton:Sprite = new Sprite();
dropButton.graphics.beginFill(0x99CCFF);
dropButton.graphics.drawRect(0, 0, 109, 34);
dropButton.graphics.endFill();
dropButton.alpha = 0.75;
dropButton.filters = [new DropShadowFilter(3,120,0x000000,0.5,0,0,1,1,false,false,false)];
menu1.dropdown.addChild(dropButton);
menu1.setStyle("upSkin", typeButton);
menu1.setStyle("overSkin", typeButton);
menu1.setStyle("downSkin", typeButton);
menu1.setSize(109, 34);
menu1.dropdown.setRendererStyle("upSkin", dropButton);
menu1.dropdown.setRendererStyle("overSkin", dropButton);
menu1.dropdown.setRendererStyle("downSkin", dropButton);
menu1.dropdown.setSize(109, 34);
menu1.textField.setStyle("textFormat", typeTextFormat);
menu1.dropdown.setRendererStyle("textFormat", typeTextFormat);
menu1.move(xLoca, yLoca);
menu1.prompt = prompt;
menu1.dataProvider = dataProvider;// constructor code
addChild(cboClip);
Running the class above with the code below. At first everything works fine, but when you select something and then make a change you get
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/removeChild()
Does anyone have any ideas why?
var dp:DataProvider = new DataProvider();
dp.addItem( { label: "Some Data", data: "Some" } );
dp.addItem( { label: "More Data", data: "More" } );
dp.addItem( { label: "Way More Data", data: "Way More" } );
dp.addItem( { label: "No Data", data: "None" } );
var c:CustomComboBox = new CustomComboBox(50, 50, dp, "How Much Data?");
addChild(c)The error is indicating a problem with a removeChild() method call, and none of the code you show has that as far as I can see. So you probably need to look elsewhere for the problemed code.
-
1180: Call to a possibly undefined method addChild.
Hi - I get the folowing error in one of my classes and not too sure why? Would appreciate some enlightenment
package {
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.*;
import flash.display.*;
//import flash.display.MovieClip;
//public class LoadActivities extends MovieClip {
public class LoadActivities {
//public var isACoin:Boolean;
public function LoadActivities(game):void
var loader:Loader = new Loader;
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, handler);
loader.load(new URLRequest(game));
public function handler(e:Event):void
var mc:MovieClip = MovieClip(e.target.loader);
addChild(mc);TypeError: Error #1034: Error de conversión forzada: no se puede convertir "game.swf" en LoadActivities.
Thanks for your answer re: extends MovieClip that worked but now I get the following error.
I have a main fla and its document class.
The part of the code in document class that causes the problem:
MAIN DOCUMENT CLASS
private function processCollisions():void
if (thePlayer.hitTestPoint(q.x, q.y))
this.removeEventListener(Event.ENTER_FRAME,mainGameLoop);
LoadActivities("game.swf");
return;
This is a platform game. When the player hit tests q (which is my quiz) I want to stop the main loop of the platform (container) game and import a quiz.swf.
I use a dedicated class LoadActivities to do this
LoadActivities
package {
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.*;
import flash.display.*;
public class LoadActivities extends MovieClip {
public function LoadActivities(game):void
var loader:Loader = new Loader;
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, handler);
loader.load(new URLRequest(game));
public function handler(e:Event):void
var mc:MovieClip = MovieClip(e.target.loader);
addChild(mc); -
Error with mouse event function
Hi,
I have inserted two keyframes in the timeline, then i included scripts on each keyframe. The script in first keyframe is following:
stop();
var mc:MovieClip = new MovieClip();
mc.graphics.beginFill(0xFF0000);
mc.graphics.drawRect(0,0,300,20);
mc.graphics.endFill();
addChild(mc);
mc.addEventListener(MouseEvent.CLICK,clicked)
function clicked(){
gotoAndPlay(2);
The script in the second keyframe is following:
var mc1:MovieClip = new MovieClip();
mc1.graphics.beginFill(0xFF00FF);
mc1.graphics.drawRect(0,0,300,20);
mc1.graphics.endFill();
addChild(mc1);
The error which was reported while compiling is defined as follows:
When i click on the movieclip 'mc' created in the first frame, an error like "ArgumentError: Error #1063: Argument count mismatch on gallery_fla::MainTimeline/clicked(). Expected 0, got 1." is showing. Actually i need to go to the second frame while clicking on the movieclip on first keyframe.
Regards,
SreelashUse following:
stop();
var mc:MovieClip = new MovieClip();
mc.graphics.beginFill(0xFF0000);
mc.graphics.drawRect(0,0,300,20);
mc.graphics.endFill();
addChild(mc);
mc.addEventListener(MouseEvent.CLICK,clicked)
function clicked(evnt:MouseEvent)
gotoAndPlay(2);
When we use a function as an event listener it should catch the event as an argument. that is why you are getting this error. -
Hi, getting OOM error when doing a build of a project using
flash builder 4 standalone (on windows 7, 64bit).
I've tried all manner of increasing the heap size. Below is the stack trace from the log file (in .metadata/.log). One thing i did notice is the java.version. This jre is not one i have installed, so it must be the one which is installed with the product (in FLEX_HOME/jre). Now, how does one control the vmargs for this invocation? I tried messing with FlashBuilder.ini, as well as jvm.config in the sdks directories; to no avail.
!SESSION 2011-03-21 18:20:55.867 -----------------------------------------------
eclipse.buildId=unknown
java.version=1.6.0_16
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=en_US
Command-line arguments: -os win32 -ws win32 -arch x86
!ENTRY org.eclipse.core.jobs 4 2 2011-03-21 18:34:47.120
!MESSAGE An internal error occurred during: "Building workspace".
!STACK 0
java.lang.OutOfMemoryError: Java heap space
at flash.swf.TagDecoder.decodeDefineBitsLossless2(TagDecoder.java:1199)
at flash.swf.TagDecoder.decodeTag(TagDecoder.java:301)
at flash.swf.TagDecoder.decodeTags(TagDecoder.java:179)
at flash.swf.TagDecoder.parse(TagDecoder.java:127)
at flex2.compiler.swc.SwcLibrary.parse(SwcLibrary.java:157)
at flex2.compiler.swc.SwcScript.getDoABC(SwcScript.java:60)
at flex2.compiler.swc.SwcGroup.updateMaps(SwcGroup.java:273)
at flex2.compiler.swc.SwcGroup.<init>(SwcGroup.java:52)Just to simplify, I created another mobile project in 4.5 prerelease, this one is a "supported" ActionScript only project, with the same results. The code for the entire iphone project is below. I'm including lccsFlash.swc (10.1 version). Image of the result on the phone is attached (same as before).
The code is here:
private var debugtext:String;
private var auth:AdobeHSAuthenticator;
private var txtfld:TextField = new TextField();
private function myLccsTrace(debugStr:String):void{debugtext += debugStr +
"\n";txtfld.text = debugtext;
private function updateDebug(event:Event):void{txtfld.text = debugtext;
public function ActionScriptMobile(){
super();
// support autoOrientsstage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
startConnect();
private function startConnect():void{DebugUtil.traceFunction = myLccsTrace;
DebugUtil.suppressDebugTraces=
false;debugtext +=
"Starting viewactivatehandler... \n";
debugtext +=
"Creating auth \n";auth =
new AdobeHSAuthenticator();auth.userName =
"Guest";auth.requireRTMFP=
false;
cSession =
new ConnectSession();debugtext +=
"Created ConnectSession \n";cSession.authenticator = auth;
cSession.roomURL=
http://collaboration.adobelivecycle.com/MYACCT/MYROOM;cSession.addEventListener(SessionEvent.SYNCHRONIZATION_CHANGE, updateDebug);
debugtext +=
"Trying login... \n";cSession.login();
debugtext +=
"After login \n";
txtfld.width=800;
txtfld.height=1200;
txtfld.text = debugtext;
this.addChild(txtfld) }
Same error as before. Also, the "guk=" is from the LCCS code after the login(), I'm not adding any additional parameters, all the code is above. -
Can C++ Container Determine AS2 vs AS3
I have a C++ container of Flash Player 11 (I have also tried
Player 9 and Player 10). How can the container ask the player what
type of content it is playing (AS2 or AS3)?
If I create an event handler (ExternalInterface.addCallback)
in AS3 which returns true (depicting AS3), and call
m_FlashPlayer.CallFunction in my container, I am able to
receive/parse the ActionScript response ("<true/>").
However, if the content is "old" (i.e. AS2 which does not
have the necessary event handler) ... or if the content is AS3 and
I deliberately throw an exception (throw new Error("AS3 Error") in
my event handler) ... the C++ container has no way of
differentiating between AS2 or AS3. My container catches the
COleDispatchException, but there is no information within the
exception. Both scenarios result with an m_scError = 0x80004005
(E_FAIL).
Is there a prescribed way for a container to ask the
Shockwave player if it is playing AS2 or AS3 content?You are confusing the Shockwave Player (which runs
Director-created
content) with the Flash Player -
The attached MXML file gives the following error at the line
this.addChild(square);
TypeError: Error #1034: Type Coercion failed: cannot convert
flash.display::Shape@5fc5301 to mx.core.IUIComponent.
Now I know I can put the code in a seperate class package and
instantiate the class from Sprite, but is there a way to fix this
code to work from inside the Application MXML file?
ThanksComponents have two types of children, content children and
non-content children.
Content children are placed in the component where the
component acts as the container. Non-content children are placed on
the component where they make up the component.
e.g. I can add a Label to a Canvas using addChild. I can add
a background to a Canvas using rawChildren.addChild.
To use an analogy, an apple can be placed in a basket with
addChild while an handle can be added to the basket with
rawChildren.addChild. -
iv made a flash site using as3 using the actionscript on the
first frame, this by itself works fine.
iv also used an online tutorial to help create a dynamic
slideshow/photo gallery which again works fine, but this time using
an external .as file.
When i try to load the external slideshow/gallery into a
movieclip in the site it dosnt work and i get this error:
TypeError: Error #1009: Cannot access a property or method of
a null object reference.
im pretty sure its because the code used in the main flash
file is on the timeline and the code in the external file to be
loaded in is in an external as file.
any help on how to get this to work would be much
appreciated!
the code im using to load the external flash file is:
var toload =new Loader();
toload.load(new URLRequest("newfile.swf"));
photography.buttonThumb.addChild(toload);This error, in my experience, is usually triggered by some
code in the loaded movie trying to use some property value that it
cannot find. In my case it is usually a reference to the size of
the stage, either its width or height or both. So, if you have some
code that is executing immediately in this loaded movie, try
changing this to a function that can be called once the movie has
fully loaded.
Maybe you are looking for
-
Primary Keys and VARCHAR2 vs CHAR datatypes???
Could someone please tell me if there is documentation concerning the performance implications of creating a Primary Key using a VARCHAR2 datatype vs a CHAR datatype?
-
every thing works on my ipod classic but there no sound
-
Hi, I have an airport extreme connected to a modem and an XP PC. I am trying to connect an airport express using airport utility, and have reset the AE during the process. AU can find the AE if I use a cable, and identifies it as an AE using factor
-
Placing .png in illustrator
Hi folks! I don't know what I am doing different.... I have created an icon in illustrator and saved for web, but when I try to place it in illustrator it has a white background. When saving for web I left the transparency box ticked... Does anyone h
-
How to move Organizational unit in PPOMA_BBP
Hello, I would like to know how i can move Org unit in PPOMA_BBP Regards, Lina