Run-Time Errors Over Multiple Layers - actionscript-3

I notice that when Flash warns me of run-time errors over multiple layers of script the line of error doesn't seem accurate (I'm pretty sure it just tells me what line of all the code the error is on, not the specific line of the layer I'm working with). The warning doesn't even tell me what layer the problem is on. For example:
TypeError: Error #1009: Cannot access a property or method of a null
object reference. at
_example_fla::MainTimeline/my_function()[_example_fla.MainTimeline::frame1:523]
Is there anyway I can get Flash to tell me what layer, frame and line (on that layer) the issue occurs?

No, unfortunately, Flash doesn't give this information about layers. You have to do a little math.
The error is occurring on Frame 1 (you can see that after the :: on the message.)
To find the layer, you have to count the lines of code on each layer, from the top down. Flash sees it all as one long block of code. Thus, FOR EXAMPLE, if layer 1 has 452 lines, layer 2 has 12, and layer 3 has 59, you can do the math and find your error on line 57 of that third layer.
523-452=71
71-12=59
Thus, line 57, layer 3
This can get annoying. It is for this reason that the standard practice at my company for code on the timeline is to put all code (except, usually, event listeners)on a layer by itself, at the top of the stack, called SCRIPTS. Nothing else lives in that layer - it is just empty with code. It makes life so much easier.

Related

AS3 - Catch ANY Error thrown and keep track of them?

I would like to have many devices testing a game, and I find the best way to debug a game and solve specific code problems is to have the device connected and in debug mode in Adobe ANIMATE, that way I can catch any Errors in the Output window.
For Example, if I am debugging and connected to Animate, the output window will throw errors like :
ReferenceError: Error #1065: Variable bg_storage is not defined.
at global/flash.utils::getDefinitionByName()
at Game/stageAdd()[/Users/**/Game.as:360]
Now I know exactly what the problem is and where to find it. I love errors like this.
My question :
If I didn't have a device connected to Animate in Debugging mode, is there a way to make the game detect any errors thrown and store them as a String, that way I can put up a big text block on the game of the error string and keep track.
or at least a way to log them some how?
Ex :
If an error is thrown, have that error text set as a String variable, then have a text box write out that String variable.
I hope that isn't too confusing. If I am going about debugging in a poor way, I would love to know what you guys do to keep track of errors without being connected to debug mode.
EDIT
I can see an approach is you to add an uncaughtErrorEvent event to each function to be able to catch these errors...
loadbar.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR ... )
I am trying to make it so any error thrown in any part of the game will trace that error somewhere to a String value that I can call, so that I can see any error thrown during a play test session without being connected to debug mode.
Thanks!
Sure. There's a class intended exactly for that: https://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/UncaughtErrorEvent.html See examples at the bottom of the page to listen to the right instances for that event.
You are also free go grab my own class that does the thing you want: https://bitbucket.org/thydmitry/ru.delimiter/src/2756fadd741a6d44276fde1701470daf24cebfa8/classes/ru/delimiter/utils/Log.as?at=default&fileviewer=file-view-default
You will need to add it to your project and then call in the main document class (in constructor, preferably):
Log.create(this);
Log.handleExceptions(this, true);

Access of undefined property " "

I am trying to make a skip button in Adobe Flash with Action Script 3.0, but when I go to test it I get the error:
gameMenu, Layer 'Actions', Frame 107, Line 4, Column 1 1120: Access of undefined property gamePlay.
I am not sure how to fix this, any help would be appreciated.
skip_btn.addEventListener(MouseEvent.CLICK,skipF);
function skipF(e:Event):void{
gotAndStop(105);
}
Can't find any errors. There are others like the ones in the comments other users have posted. If you're using Adobe Flash CC or CS4-6 permit debugging or launch your movies in debug mode using cntrl+shift+enter. You'll get the exact line of the error as well as any active variables that might be related to the issue.
skip_btn.addEventListener(MouseEvent.CLICK, skipF);
function skipF(e:MouseEvent):void
{
gotoAndStop(105);
}

AS3 error- when trying to hit test object

I am trying to test for the collision of two objects. Both are on the display list. They are movie clips, each containing a hit box. One is called hitboxx, and the other is called hits. However, when I test the following code:
if (character2.hitboxx.hitTestObject(Spike1.hits)||character2.hitboxx.hitTestObject(Spike2.hits)||character2.hitboxx.hitTestObject(Spike3.hits))
{
currLives--;
}
I get this error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at SpikeJungle_fla::MainTimeline/frame1()[SpikeJungle_fla.MainTimeline::frame1:126]
it's difficult to say anything on the code. The code seems correct. May be you forget to add variable name or something. Or try to check one movie clip at a time. means try to remove the other condition in and check with one and see whether it's working. And also in Publish Settings >> Advanced >> permit Debugging check this option and compile again and you will get more about the errors.

(cocos2d-x 3.1 + VS2012) TextureCache::addImageAsync causes a crash occasionally

I load some textures in asynchronously at the beginning of my game, about 40-50 of them.
vector<string> textureFileNames;
textureFileNames.push_back("textures/particle.png");
textureFileNames.push_back("textures/menu_title.png");
...
textureFileNames.push_back("textures/timer_bar.png");
for (auto fileName: textureFileNames)
{
Director::getInstance()->getTextureCache()
->addImageAsync(fileName, CC_CALLBACK_1(LoadingLayer::textureLoadedCallback, this));
}
My textureLoadedCallback method does nothing funky; at this stage it simply increments a value and updates a progress timer. The callback is called from the main thread by cocos2d-x design, so I don't suspect any problems arise from there.
90% of the time this works fine. But sometimes it crashes in VS2012 midway through loading the textures:
Debug Assertion Failed!
Program: C:\Windows\system32\MSVCP110D.dll
File: C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\vector
Line: 1140
Expression: vector subscript out of range
Breaking at this point, I can see that it dies in the internals of vector, specifically the [] operator, and traces back through _Hash to the TextureCache::loadImage() method: auto it = _textures.find(asyncStruct->filename) on line 174 of CCTextureCache.cpp. _textures is defined as std::unordered_map<std::string, Texture2D*> _textures, a standard library unordered map. asyncStruct->filename resolves to the full path and filename of a texture to load.
Using the debugger, I can see that the filename is fine. I can see that _textures already contains the 19 textures before this one that it has processed just fine.
The fact that it seems to just be dying in the midst of the standard library doesn't strike me as right... but I'm unable to determine where CCTextureCache goes wrong. Only that it doesn't always fail, and that it's failing in an asynchronous thread. There's no concurrency bollocks going on with my code (as far as I know).
Is this a cocos2d-x bug, a VS2012 bug or a bug with my code I pasted above?
I think a potential cause could be that the for loop issues like 19 async image loads all at once, which may or may not be supported by that method. Try issuing the next async load only after your texture callback is called. That way no two async loads are performed simultaneously.

How do i find which variable is undefined? (flash builder)

A flash application in flash builder is currently throwing this error:
ReferenceError: Error #1065: Variable
is not defined.
Not telling me which variable it is that's not defined, but note there are two spaces between 'variable' and 'is'. and it gives me some more feedback as to what lines of code are having trouble, but those lines are all within the actual flash/mxml packages and not any of the files in my own project.
I suspect it's related to my php data/services, but I don't see what variable would not be defined. I'm not very familiar with debugging, so I'm not sure how to determine with it where the problem is cropping up.
at global/flash.utils::getDefinitionByName()
at mx.utils::DescribeTypeCache$/describeType()[E:\dev\4.x\frameworks\projects\framework\src\mx\utils\DescribeTypeCache.as:106]
at com.adobe.serializers.utility::TypeUtility$/getType()[/Users/sameer/depot/flex/ide_builder/com.adobe.flexbuilder.dcrad/serializers/src/com/adobe/serializers/utility/TypeUtility.as:90]
at com.adobe.serializers.utility::TypeUtility$/assignProperty()[/Users/sameer/depot/flex/ide_builder/com.adobe.flexbuilder.dcrad/serializers/src/com/adobe/serializers/utility/TypeUtility.as:516]
at com.adobe.serializers.utility::TypeUtility$/convertToStrongType()[/Users/sameer/depot/flex/ide_builder/com.adobe.flexbuilder.dcrad/serializers/src/com/adobe/serializers/utility/TypeUtility.as:498]
at com.adobe.serializers.utility::TypeUtility$/convertListToStrongType()[/Users/sameer/depot/flex/ide_builder/com.adobe.flexbuilder.dcrad/serializers/src/com/adobe/serializers/utility/TypeUtility.as:454]
at com.adobe.serializers.utility::TypeUtility$/convertResultHandler()[/Users/sameer/depot/flex/ide_builder/com.adobe.flexbuilder.dcrad/serializers/src/com/adobe/serializers/utility/TypeUtility.as:367]
at mx.rpc.remoting::Operation/http://www.adobe.com/2006/flex/mx/internal::processResult()[E:\dev\4.x\frameworks\projects\rpc\src\mx\rpc\remoting\Operation.as:316]
at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler()[E:\dev\4.x\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.as:313]
at mx.rpc::Responder/result()[E:\dev\4.x\frameworks\projects\rpc\src\mx\rpc\Responder.as:56]
at mx.rpc::AsyncRequest/acknowledge()[E:\dev\4.x\frameworks\projects\rpc\src\mx\rpc\AsyncRequest.as:84]
at NetConnectionMessageResponder/resultHandler()[E:\dev\4.x\frameworks\projects\rpc\src\mx\messaging\channels\NetConnectionChannel.as:547]
at mx.messaging::MessageResponder/result()[E:\dev\4.x\frameworks\projects\rpc\src\mx\messaging\MessageResponder.as:235]
look at line 106 for DescribeTypeCache.as There will likely be two variables, one of them is undefined