Flash AS3 - Importing external SWF causes Error #2007 - actionscript-3

I have a weird issue with importing external SWF in ActionScript 3.0.
I want to import a SWF made with EasyPano TourWeaver 7.96 but when I'm doing this I'm getting the Error #2007: Parameter child must be non-null. Here is the code:
var VRArea:MovieClip = new MovieClip();
VRArea.x = 0;
VRArea.y = 96;
addChild(VRArea);
var my_Loader:Loader = new Loader();
var urlRequest : URLRequest = new URLRequest("vr/vr_Candela.swf");
my_Loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaderComplete);
my_Loader.load(urlRequest);
function loaderComplete(event:Event):void {
VRArea.addChild(my_Loader);
}
The complete error is shown below:
TypeError: Error #2007: Il valore del parametro type deve essere diverso da null.
at flash.events::EventDispatcher/addEventListener()
at `[::-V/5?()
at ->::4J/Step4_2_startUI()
at ->::4J/`Z()
at [A::&=/1?()
at [A::%c/dispatch()
at !A::%D/load()
at ->::4J/Step3_1_LoadConfig()
at ->::4J/Step3()
at ->::4J/Step2_createContext3D()
at ->::4J/%$()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at $::TWLoadingWindow/+&()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at 0M::1X/;$()
at 0M::1X/3#()
at Function/http://adobe.com/AS3/2006/builtin::apply()
at 0M::>5/&S()
Additional info: I'm getting only the loading screen of the external SWF.

You should use event.target in your listener to add the loader object. More, since you've assigned the listener to loaderInfo property, you need to get the object's content that is the object with loaded SWF.
function loaderComplete(event:Event):void {
var li:LoaderInfo=event.target as LoaderInfo;
if (!li) return; // failed typecast
VRArea.addChild(li.content); // add content
}

I solved the issue: The SWF I tried to embed was made with Flash 11.x (at least Flash CS6) and mine was Flash 10.0 (Flash CS5). I solved by upgrading to Flash CS6 and publishing again. Now it's fine.

Related

How to fix 'TypeError: Error #1009' error in ActionScript3.0 Adobe Animate

I'm setting up a button on the first frame which when clicked will transfer the user to the 2nd frame using this code:
stop();
Btn_1.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndPlayFromFrame_2);
function fl_ClickToGoToAndPlayFromFrame_2(event:MouseEvent):void
{
gotoAndPlay(2);
}
and on the second frame, I set up a dynamic text that will perform a countdown using this code:
var myTimer:Timer = new Timer(1000,60); // every second for 60 seconds
myTimer.addEventListener(TimerEvent.TIMER, onTimer);
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onComplete);
myTimer.start();
function onTimer(e: TimerEvent):void {
countdown_text.text = String(myTimer.repeatCount - myTimer.currentCount);
}
function onComplete(e: TimerEvent):void{
gotoAndStop(3);
}
the thing is keep getting TypeError: Error #1009 message after debugging it. I know the fault is in line 7 of the 2nd code but I have no idea what is wrong with it. Pls help!
I should see your source fla, but it is most likely related to countdown_text not being accessible in that frame. Error description is "Cannot access a property or method of a null object reference", that means it cannot find the reference which is "countdown_text".
It is very very bad practice to write AS directly in frames. Convert code into a class and assign it as a document class.
You can find Adobe documentation for document class here: https://helpx.adobe.com/animate/using/actionscript-publish-settings.html

addChild() issue: error 2007 on AS3

I have this piece of code that's suppose to add a swf file (homePage.swf) inside my main file (skeleton.fla).
Code:
var mcHome:MovieClip;
var newPage:Loader = new Loader();
newPage.load(new URLRequest("homePage.swf"));
newPage.contentLoaderInfo.addEventListener(Event.COMPLETE, homeLoaded);
function homeLoaded(event:Event):void {
mcHome = MovieClip(newPage.contentLoaderInfo.content);
newPage.contentLoaderInfo.removeEventListener(Event.COMPLETE, homeLoaded);
addChild(mcHome);
}
I keep getting this error:
TypeError: Error #2007: Parameter child must be non-null. at
flash.display::DisplayObjectContainer/addChild() at
skeleton_fla::MainTimeline/homeLoaded()
I don't know how to solve it, or what to change!
Help please, I'm a bit desperate.
Is better to add to the displayList the Loader object instead its contentLoaderInfo.content. The Loader is a DisplayObject by itself. There is not need to access to the MovieClip inside of the Loader object although it is possible in the most of environments.
If you try to load an SWF that resides in other domain, you could add the Loader object to the displayList but you can't access to the content property if you don't create a crossdomain.xml file.
var newPage:Loader = new Loader();
newPage.load(new URLRequest("homePage.swf"));
newPage.contentLoaderInfo.addEventListener(Event.COMPLETE, homeLoaded);
function homeLoaded(event:Event):void {
newPage.contentLoaderInfo.removeEventListener(Event.COMPLETE, homeLoaded);
addChild(newPage);
}
Here you have an example.

How to fix AS3 TypeError: Error #1009: Cannot access a property or method of a null object reference?

I am getting this error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Skool_fla::MainTimeline/frame1()[Skool_fla.MainTimeline::frame1:10]
at flash.display::MovieClip/gotoAndStop()
at Skool_fla::MainTimeline/goback()[Skool_fla.MainTimeline::frame2:22]
What is causing this error and how do I fix it?
This is my code for both the frames:
Frame 1: This is the main menu screen where you can access the credit section
import flash.events.MouseEvent;
//setting up the variables
//events
//stop the timeline
stop();
//the play button
play_btn.addEventListener(MouseEvent.CLICK, playani);
function playani(e:MouseEvent)
{
//asking it to progress to the load menu
gotoAndStop(3);
}
//the credits button
credit_btn.addEventListener(MouseEvent.CLICK, creditslide);
function creditslide(e:MouseEvent)
{
//asking it to go the credits frame
gotoAndStop(2);
}
Frame 2: This is where the credits appear
//
//
//all the imports
//events
var credit:credits_bck = new credits_bck ();
var credits_name: credit_nm = new credit_nm ();
var back_butn: back_button = new back_button ();
addChild (credit);
addChild (credits_name);
addChild (back_butn);
back_butn.addEventListener(MouseEvent.CLICK,goback);
function goback(G:MouseEvent)
{
removeChild (credit);
removeChild (credits_name);
gotoAndStop(1);
}
Either play_btn or back_butn is null. Your error message's line numbers don't correspond to your code so it's hard to say. But the gist is you're trying to access a property of something that isn't anything. Check to make sure you're initializing your variables/references properly.
Maybe your problem is Flash bug too.
In my FLA there was a layer with one empty keyframe. If I puted a vector graphics on it, the error was gone. If there was one or multiple MovieClips and there was no vector graphic - the error was there again.
Then I made a new layer and copy pasted all the objects from damaged layer to new and deleted the damaged layer. It solved the problem.
NOTE: Don't copy the keyframes. Only copy the contents.
Now my project is much more complicated and sadly the error came back again.
Test movie frequently and if the error comes back, check the last keyframes and layers you created.

Error #1034 while running flash application

Alright, I know that this error is occurring because of something to do with addchild() function. On frame 2. How do I know? Because when I remove the snippets of code that dynamically place an object onto the stage it works fine. The error is below and the source code for frame 2 is below the error messages.
Error Code
TypeError: Error #1034: Type Coercion failed: cannot convert 0 to flash.display.DisplayObject.
at fl.motion::AnimatorBase/play()
at fl.motion::AnimatorBase$/processCurrentFrame()
at fl.motion::AnimatorBase/handleEnterFrame()
at flash.display::MovieClip/nextFrame()
at Lemonade_fla::MainTimeline/begin()[Lemonade_fla.MainTimeline::frame1:27]
TypeError: Error #1034: Type Coercion failed: cannot convert 0 to
FRAME 2 CODE
flash.display.DisplayObject.
stop();
var guide_tut:guide = new guide();
addChild(guide_tut);
//stand.addEventListener(MouseEvent.CLICK, check);
addEventListener(Event.ENTER_FRAME, check);
function check(ev : Event) : void {
cash.text.text = cash1;
lemons_count.text.text = lemons1;
cups_count.text.text = cups;
straws_count.text.text = straws;
ice_count.text.text = ice;
}
shop_mc.addEventListener(MouseEvent.CLICK, shopnow);
function shopnow(event:MouseEvent):void{
nextFrame();
}
1) I ran your code it works fine, the only place the error could be generated is:
flash.display.DisplayObject.
should be: flash.display.DisplayObject;
but you don't need it.
and
var guide_tut:guide = new guide();
addChild(guide_tut);
I ran it with just an empty mc, it works fine.
2) no reason to have (i know its commented out) but there never a reason to have
stand.addEventListener(MouseEvent.CLICK, check) ever since check is EnterFrame
basically you're error is within either display, most likely you're not extending the class from MovieClip
public class guide extends MovieClip
instead of movieclip it can be sprite or other displayobject...

External SWF Loading problem

I have an SWF loading in an SWF containing a papervision scene.
I've done it before yet problem is, I get an error - I'm not sure what the issue really is.
private function downloadSWF(url:String):void
{
trace(url);
var urlRequest:URLRequest = new URLRequest(url);
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loaderProgressEventHandler);
loader.load(urlRequest);
}
private function loaderProgressEventHandler(ev:ProgressEvent):void
{
loader.preloaderCircle.percent = ev.bytesLoaded / ev.bytesTotal;
}
When the application runs the code - I get the error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.dehash.pv3d.examples.physics::WowDemo()
Why am I getting this if the loading hasn't even complete yet?
Thanks in advance guys.
Edit: Try a blank child swf, see if the other one was trying access something in the parent. – Jorge
I did this, it seems, even with a simple SWF with a mouse click listener causes the Error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at simple_fla::MainTimeline/frame1()
My code for that is:
import flash.events.MouseEvent;
this.stage.addEventListener(MouseEvent.CLICK, onClick);
function onClick(ev:MouseEvent):void
{
trace("MouseClick");
}
Am I missing something blatantly obvious??
The problem is that the loaded swf starts running without it being added to the stage. So stage is null, resulting in that error.
The second example with the addedToStageEventHandler works because there stage is only referenced after the object was added to the stage, so stage is not null anymore.
A possible solution for the first error is adding the loader to the stage. That way, when the swf is loaded and starts, it already has a stage reference.
It won't even load if there's an error. You're accessing an unreferenced object on the WowDemo() class...did you instantiate correctly the class?
this seems to work inside my child SWF:
this.addEventListener(Event.ADDED_TO_STAGE, addedToStageEventHandler);
function onClick(ev:MouseEvent):void
{
trace("MouseClick");
var event:Event = new Event("END", true, false);
this.dispatchEvent(event);
}
function addedToStageEventHandler(ev:Event):void
{
this.stage.addEventListener(MouseEvent.CLICK, onClick);
}
does anyone know Why?