Getting error while maintaining flash code - actionscript-3

I am new to flashbuilder. I have got this existing code to maintain. All of the mxml files have outermost tag s:WindowedApplication. The navigation from one page to another is done using code as follows:
public function help_clickHandler(event:MouseEvent):void
{
var dTracker:aboutProduct = new aboutProduct();
this.addElement(dTracker);
}
After navigating to a new page I get following error on clicking any where on newly loaded page:
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/getChildIndex()
at mx.managers::SystemManager/getChildIndex() [E:\dev\4.y\frameworks\projects\framework\src\mx\managers\SystemManager.as:1823]
at mx.managers.systemClasses::ActiveWindowManager/mouseDownHandler() [E:\dev\4.y\frameworks\projects\framework\src\mx\managers\systemClasses\ActiveWindowManager.as:483]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\UIComponent.as:13152]
at mx.managers::SystemManager/mouseEventHandler() [E:\dev\4.y\frameworks\projects\framework\src\mx\managers\SystemManager.as:2918]
Error: Error #3003: File or directory does not exist.
at flash.filesystem::File/copyTo()
at studyTopics/studytopic_changeHandler()[C:\flash\46\HondaLMS\src\studyTopics.mxml:81]
at studyTopics/__lst_change()[C:\flash\46\HondaLMS\src\studyTopics.mxml:136]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\UIComponent.as:13152]
at spark.components::List/commitSelection()[E:\dev\4.y\frameworks\projects\spark\src\spark\components\List.as:1278]
at spark.components::List/commitProperties()[E:\dev\4.y\frameworks\projects\spark\src\spark\components\List.as:1148]
at mx.core::UIComponent/validateProperties()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\UIComponent.as:8219]
at spark.components::List/item_mouseDownHandler()[E:\dev\4.y\frameworks\projects\spark\src\spark\components\List.as:1915]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\UIComponent.as:13152]
at mx.managers::SystemManager/mouseEventHandler()[E:\dev\4.y\frameworks\projects\framework\src\mx\managers\SystemManager.as:2918]
Please help me solve this runtime error.
Update:
There is a technical error in the design of application, i.e., all of the mxml have WindowApplication. There should be only one WindowApplication and rest of them should be Application type (reference). Still I have to figure out, how to navigate from one page to another page and return back to main page or previous page.

In one flex application there can be only one mxml with WindowApplication container. Rest of the containers should be Group.
I left landing page as WindowApplication and changed rest in Group, this revolved the issue I was facing.

Related

How to fix an error #1009 in a class added to Main?

I have a class called ChestScene that represents a scene/MovieClip in a .fla file I'm working on. I've had tons of issues that seem to be rooted in a fundamental misunderstanding of how to properly use objects that have code attached to them. It is my understanding that adding the object to the stage automatically instantiates it, so right now all I'm trying to do is instantiate and add to stage ChestScene() in the constructor of my Main method. I thought it would be as simple as this:
public class Main extends MovieClip {
var chest:Chest = new Chest();
public function Main() {
stage.addChild(chest);
}
But I get this error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Chest()/startScene()
at Chest()
at Main()
So my first question is why is Chest null? The object exists in my fla. If I add it to the stage by dragging from the library, the class works as intended. addChild seems to work on other objects that I am using the same way so I don't get why I can't use it on this object.
How to use the Main method to instantiate an object and access/change properties of said object relative to the stage? And how can I do the same thing for the objects nested inside of my initial object?
***** Edit after answer
Thanks for your reply and for teaching me how to read the debug message. startScreen() was indeed the culprit, and the issue there was this:
stage.addEventListener(Event.ENTER_FRAME, gameLoop)
Removing stage and adding the listener to the object fixed that error, so kudos! But I'm still confused; why does trying to add the listener to the stage cause a null error? I don't understand why the stage would be null at this point. Also, removing "stag." from the addEventListener caused the size of the frame that holds the scene to be way smaller, which cropped a lot of my image. Why is an event listener affecting my stageWidth and height? This is why I also asked questions about how to correctly position things relative to the stage width and height, because I know it has something to do with the errors.
why is Chest null?
Chest is not null. It's the constructor of the class and cannot be null.
You should pay attention to the Stack trace attached to the error (the lines with "at …" below the message).
It tells you where the error occurred. Reading it from the bottom up gives you the order of method calls performed.
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Chest()/startScene()
at Chest()
at Main()
Main() called Chest(), Chest() called startScene() and BOOM! this is where the error occurred.
To debug this error look at startScene() . Something in there is null.
Looking at your current code:
stage.addChild(chest);
I guess that you also try to add something to stage in Chest(). But stage is not available ( null) in Chest().
In general, it's bad practice to add things to stage as can be read in the documentation of addChild()
Simply add to the object and not stage :
addChild(chest);

ActionScript 3 Error 1009. Basic coding really

So I'm writing a really basic app for an app dev class but I'm a designer than a developer so bear with me on this.
It involves using Caurina tweeners just moving stuff around.
import caurina.transitions.*;
import flash.events.MouseEvent;
stop();trace(fab_mc);
//Scene 2 Nav Scripts
//fab 1&2
fab_mc.fab2_btn.addEventListener(MouseEvent.CLICK, fab2);
function fab2(event:MouseEvent):void
{
Tweener.addTween(fab_mc,{x:-637.4,time:1,transition:"easeInOutQuart"});
}
fab_mc.fab1_btn.addEventListener(MouseEvent.CLICK, fab1);
function fab1(event:MouseEvent):void
{
Tweener.addTween(fab_mc,{x:-136.70,time:1,transition:"easeInOutQuart"});
}
It blows up (according to the debugger ) at line 7 due to "fab_mc" being apparently null. Frankly, I had no idea what a null is about until just this morning - I wrote the code yesterday, it worked fine.
But when I added some more content and coded it, it started complaining. The code for is essentially a lot of tweeners. Sorry if I'm not providing a lot of info, but it's all I have really.
Error code:
null
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Arafabricator_fla::MainTimeline/frame2()[Arafabricator_fla.MainTimeline::frame2:7]
at flash.display::Sprite/constructChildren()
at flash.display::Sprite()
at flash.display::MovieClip()
at Arafabricator_fla::fab_mc_10()
at flash.display::MovieClip/nextScene()
at Arafabricator_fla::MainTimeline/menu07()[Arafabricator_fla.MainTimeline::frame1:64]
If fab_mc is null it means it does not exist on the frame that you have that code. Just make sure you put that code on a frame where the fab_mc symbol also exists. You can't, for example, put that code on frame 1 but the symbol first exists on a keyframe on frame 5. In that case put the code on a keyframe on frame 5 as well.

TypeError: Error #1009: Cannot access a property or method of a null object reference. When trying to create a button.

Heyy, Im having some problems with my buttons. What I have is 4 buttons on the page. They will run an animation while not being pressed, and that animation will change when it is being pressed.
I keep getting the error TypeError: Error #1009: Cannot access a property or method of a null object reference.
at MultimediaAssignment_fla::MainTimeline/frame51()[MultimediaAssignment_fla.MainTimeline::frame51:3]
And I have searched high and low but I cant seem to find anyone who is having the same problem as me.
stop();
btn_volcano.addEventListener(MouseEvent.CLICK, volcano);
btn_Storm.addEventListener(MouseEvent.CLICK, stormbtn);
btn_Tsunami.addEventListener(MouseEvent.CLICK, tsunamibtn);
btn_Earthquake.addEventListener(MouseEvent.CLICK, earthquakebtn);
function volcano(e:MouseEvent):void {
gotoAndPlay(52);
}
function tsunamibtn(e:MouseEvent):void {
gotoAndPlay(54);
}
function stormbtn(e:MouseEvent):void {
gotoAndPlay(53);
}
function earthquakebtn(e:MouseEvent):void {
gotoAndPlay(55);
}
My buttons do have correct instance names and for some reason it worked when I turned the "up" movie clip into a button and called it e.g. btn_volcano. Except if I do that the animation doesn't run anymore.
If I remove the instance name from in front of the event listener I don't get the error but it will only ever run the last code.
Please help!
error TypeError: Error #1009: Cannot access a property or method of a null object reference. at MultimediaAssignment_fla::MainTimeline/frame51()
This line suggests you have some code in frame 51. I presume in Flash IDE in main timeline.
Click on this frame on timeline and open actions window. Problem may be there.

Error #1009: Cannot access a property or method of a null object reference

This is quite frustrating. I am simply trying to create a dynamic text and put some text into it on runtime.
I get this error though
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at MethodInfo-1()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
I have a text object named textLabel, which is inside a movieclip named MC_state.
I get it because I use:
MC_state.textLabel.text = "asdasd";
And I wish I knew what the problem was. I have other objects set up quite the same way which don't give me that problem. I just don't know how debug that.
Thanks!
The error is telling you that there is no object somewhere along MC_state.textLabel.text, so either flash cannot find MC_state, or textLabelinside MC_state or (unlikely) text inside MC_state.textLabel.
If I may venture a guess though, I think you're seeing this because this happened:
you have somewhere a movieclip called MC_state that has more than one frames. You tied to do gotoAndStop or gotoAndPlay to a frame that has the textfield called textLabel and that's the text you're trying to change.
The problem, and it comes up often for people transitioning from AS2, is that when you execute the gotoAndPlay/gotoAndStop function, the movieClip doesn't update right away, this happens iin the render phase. The code after that function however executes right away, so the movieclip is still at the old frame.
there are two ways you can handle it
set up a event handler that updates the render event, and change the text then. You can hurry the stage rendering by running stage.invalidate example
the other (better) option is to have the text in all the frames, and have it hidden or invisible, that way you can access it at any time.

What is the correct way to add components to the library of a Swf?

I've been having a problem that's plagued me many times in the course of developing a Flash project. It looks something like this:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at fl.containers::BaseScrollPane/fl.containers:BaseScrollPane::drawBackground()
at fl.controls::TileList/fl.controls:TileList::draw()
at fl.core::UIComponent/::callLaterDispatcher()
TypeError: Error #2007: Parameter child must be non-null.
at flash.display::DisplayObjectContainer/addChildAt()
at fl.controls::BaseButton/fl.controls:BaseButton::drawBackground()
at fl.controls::BaseButton/fl.controls:BaseButton::draw()
at fl.core::UIComponent/drawNow()
at fl.controls::ScrollBar/fl.controls:ScrollBar::draw()
at fl.core::UIComponent/::callLaterDispatcher()
Now, in my case, this error stems from initializing components in code when they have not been explicitly added to the fla's component library in CS4. In the past, I have run into this issue when trying to dynamically create ScrollPanes in code. I have solved it by adding ScrollPane components to my Main.fla's library. This seemed to work for a while.
Now, I am trying to use an AstraFlash AutoComplete box. I have imported the proper fla files into CS4, and placed an AutoComplete box into my Swf. Everything builds fine, but the above error occurs when the Swf is loaded. My thought is that the AutoComplete box is trying to create a ScrollPane as part of its functionality. Ok, I understand this, so I add the ScrollPane component to the library as well with the same results.
Usually I would just mess with the library components/settings until I get rid of the error, but I'm sick of running into this, and I want to know the correct way to solve the problem. So, here are a few questions I have:
When are you required to add a component to a Fla's library rather than just creating the component in code?
Which Flas do you need to add the component to? Just the one using it? Or all of parents of that Fla as well?
Let's say the Autocomplete component requires a ScrollPane component. Why isn't this dependency recognized when I add the one component? Why must I explicitly add it?
What is the difference between adding a component to the library, and adding it to the library's 'Component Assets' folder? What is this folder's purpose?
I really need this AutoComplete component to work. Assuming the AS3 code is correct, and I am still getting the above error, what settings do you think are probably incorrect? Out of frustration, I have tried adding every possible component to the library, as well as to the library's component assets folder just to have a starting point, but I still get the error.
Any help is appreciated.
I'm not sure I understand you're setup. What I'm assuming is you have a child fla that contains some components and you need to create instances of those components in a parent(loader) fla.
It should work if you compile the classes from the child fla into the parent fla, but that would duplicate things.
The issue is when you load a swf, the classes sit in a different ApplicationDomain.
Simply put, that's the thing that manages classes in a swf so you don't have class collisions between a loader and loaded swf and some other security stuff.
I made a simple fla that holds a Button component(fl.controls.Button) and loaded that from a loader fla. I didn't add the Button component to the loader fla, but did create a button instance, using the loaded swf's application domain. Here's how:
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaded);
loader.load(new URLRequest('componentContainer.swf'));
function loaded(event:Event):void {
addChild(loader.content);
var SWFButton:Class = loader.contentLoaderInfo.applicationDomain.getDefinition('fl.controls.Button') as Class;
var button = new SWFButton();
button.label = 'Test';
addChild(button);
}
There is a page in Programming Actionscript 3.0 about thise kind of issues and how to use ApplicationDomain, but I didn't fully understand it to be honest.
HTH,
George