LocalConnection works when it should fail - actionscript-3

in my page i have a main swf, which should check the existence of a second swf - if its missing, the main swf should display a certain message to the user, otherwise it should work as planned.
i thought to achieve this by using LocalConnection - the main swf is set as the sending swf, and it should call a certain function on the other swf. i was thinking that if the second swf is missing, the local connection would fail - either throw an error or its STATUS event listener would receive an 'error' in the event's level property.
if you think as i did - well think again. no error was thrown and the listener got a 'status' in the event's level property, although there's nobody to handle the LocalConnection 'send' method.
what did i miss? or is there a better way to achieve my goal?
cheers,
eRez

Related

OSMF uncaught Error

I am using the OSMF to play HDS videos, the player is hosted in a 'parent' player that removes the OSMF using unloadAndStop() which results with the following error:
Error: Error #2154: The NetStream Object is invalid. This may be due to a failed NetConnection.
at flash.net::NetStream/play2()
at org.osmf.net.rtmpstreaming::RTMPDynamicStreamingNetLoader/reconnectStream()
at Function/<anonymous>()
When removing the OSMF using unload() the error does not occur .
I have made many attempts to resolve this or to try and catch the error but so far with no success, please share if you have any clue on how this might be resolved.
Thanks!
Eran
UnloadAndStop completely clears out everything (ready for Garbage Collector to free up the previously used memory) so now when your Play2() comes in, it finds access to nothing. You can try and separate a part of your code into smaller functions. i.e
Function One for setting up new netStream & netConnection etc
Function Two for playing netstream
Function Three can be for play2() where you have If/Else to check if not_unloaded == true then do play2(); else do Function One from here as a reset
PS: also these two links might help you as I dont (nor need to) know the rest of your code setup. Wether they talk about SWF files or Netstream it all applies the same
http://www.nikesh.me/blog/2010/04/unload-loaded-swf-file-by-unloadandstop-method/
http://www.breaktrycatch.com/problems-with-unloadandstop-a-guide-to-some-undocumented-caveats/

in what situation,gotoAndStop is not working

I have 3 frames, I don't show the whole code, it's too huge.and the main code is
gotoAndStop(2);
trace('frame:',currentFrame)
the output should be frame: 2
But in fact it's frame: 1, and objects in frame 2 cannot be loaded and become null
no compiler errors
When I delete some codes after it, the application sometimes operate right and stops at frame 2.
This shouldn't happen as any code after it should not involve the output
although I can solve this when I delete the first frame,but it's quite risky to keep developing.
Any ideas why this happen?
Before keep going,I should mention I actually have compiler errors due to null objects,but it's not the main point.
And I have a class called host,the code gotoAndStop is also in the first place of constructor.
I have put override function in host, and the output is
stopping at frame: 2 Called from: Error
at host/gotoAndStop()
at host()
frame: 1
TypeError: Error #1009: Cannot access a property or method of a null object reference
at host()
Then I tried the method2 Creative Magic says,the result shows
stopping at frame: 2 Called from: Error
at host/gotoAndStop()
at host()
displaying frame: 1
frame: 1
TypeError: Error #1009: Cannot access a property or method of a null object reference
at host()
displaying frame: 2
This quite confuses me what's happening in the frame,I wonder the cause is like you say old version of SDK,thanks for help
Your problem can be either you've written buggy code or you use old Flash SDK.
In the first case you should check if you're calling gotoAndStop(), play() or gotoAndPlay() methods of your MovieClip. To do so you can edit the class of your MC:
In Flash Professional in the library panel right-click on the MC
Select "Edit Class"
In your selected IDE add following function
override public function gotoAndStop(frame:Object, scene:String = null):void
{
trace("stopping at frame:", frame, "Called from:", new Error().getStackTrace());
super(this).gotoAndStop(frame, scene);
}
It will trace when the gotoAndStop() method was called and who called it. It will let you see if the frame was set to frame by something else. I recommend you to override play() and gotoAndPlay() functions as well.
If you're intimidated by this code you could just add a trace() on each frame of your MC, since it's only 3 frames it shouldn't be too much work. Your trace could look something like that:
trace("displaying frame:", this.currentFrame);
The other possible cause could lie within the SDK you're using. I, myself had a strange bug when the loaded MC wouldn't listen to stop(), gotoAndStop() and other functions. The problem was solved by upgrading the SDK: http://www.adobe.com/devnet/flex/flex-sdk-download.html
The explanation on how to replace the old SDK is there as well.

Citrus Engine Flash Game not compiling correctly

Im developing a flash game based on the citrus engine for a uni project.
All of it is done and handed in but im trying to compile the entire project into a release for web.
In flahs builder ive gone file --> export --> release build and compiled the game.
the .swf file opens up fine and initiatze the spirte menu but when clicking the start game button it begins to initiate the game state but then hangs up on a solid colour, in flash debugger im getting these errors
SecurityError: Error #2000: No active security context.
Started
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.citrusengine.utils::ObjectMaker$/FromMovieClip()
at GameState/initialize()
at com.citrusengine.core::CitrusEngine/handleEnterFrame()
SecurityError: Error #2000: No active security context.
Started
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.citrusengine.utils::ObjectMaker$/FromMovieClip()
at GameState/initialize()
at com.citrusengine.core::CitrusEngine/handleEnterFrame()
Any suggestion appreciated
Error #2000 is usually a file not found error. You can get more info from running an IOErrorEvent like so:
myLoader.addEventListener(IOErrorEvent.IO_ERROR, IOError)
function IOError(e:IOErrorEvent):void {
trace(e.text);
}
Likely an issue with pathing to the correct file.
Error #1009 is likely a domino effect of not being able to work on the asset that hasn't been loaded due to the IOError. It could also be an issue if you're loading other SWFs to the stage and those child SWFs attempt to utilize the stage before it's ready, in which case you'd want to only start your scripts until after the addedToStage event has fired. You can set that up like so:
if (this.parent is Stage) {
stageReady();
} else {
addEventListener("addedToStage", stageReady);
}
function stageReady(e:Event = null):void {
// begin your setup code here.
}
The logic here being that if your swf is not encapsulated inside a loader, the parent object should be the stage, otherwise, you can safely add a listener to the loaded swf's timeline that listens for the addedToStage event.
Maybe the following will resolve your problem:
Wrap all the init code to a custom function (lets say: initFunctionOfApplication). Set a delay timer before this init function is called. It's a issue I've had before, and got it fixed with a small delay... Maybe this will fix your problem.
setTimeout(function():void{initFunctionOfApplication();}, 3000);
Keep us posted!

NetStream.info, getting Error #2154

In my application I have a video playing from a NetStream. Every second on timer I update a text label with statistics like stream.info.currentBytesPerSecond. The problem occurs when the NetConnection associated with this NetStream closes: the getter for stream.info throws
Error: Error #2154:The NetStream Object is invalid.
The only solution for this seems to be to listen to NetStatus event and stop the timer when "NetConnection.Connect.Closed" gets caught.
Isn't there a better way to do this?
You could wrap your test for stream.info in a try..catch, I suppose. Or you could test to see if the object exists first:
if (stream && stream.info) stream.info ...
Really, though, the cleanest way would be to remove the applicable listener and perform cleanup when your connection closes.

Flash AS3 security errors attempting to load chromeless YouTube

I am getting flash-base security errors when attempting to load a chromeless YouTube swf...
Warning: Domain www.youtube.com does not explicitly specify a meta-policy, but Content-Type of policy file http://www.youtube.com/crossdomain.xml is 'text/x-cross-domain-policy'. Applying meta-policy 'by-content-type'.
Error: Request for resource at http://www.youtube.com/apiplayer?version=3 by requestor from http://... is denied due to lack of policy file permissions.
*** Security Sandbox Violation ***
Connection to http://www.youtube.com/apiplayer?version=3 halted - not permitted from http://...
I've attempted all relevant variations of Security.loadPolicyFile and Security.allowDomain, but I continue to get these errors.
If I ignore these trace errors (I get no callback errors from the Loader) and attempt to use the player (via loader.content during the Loader's Event.INIT), then any attempts to access the YouTube APIs causes a crash.
If I look at my player (Object) variable in a debugger, I see that it is actually a com.goggle.youtube.application::SwfProxy which is derived from Sprite. Outside of the standard Sprite vars and functions, it contains enableJsApi = false, loader = null, and player = "http://s.ytimg.com/yt/swfbin/apiplayer3-vfljSpMoI.swf"
But attempts to call functions such as player.setSize or player.loadVideoByUrl will cause a crash such as...
Exception thrown (TypeError: Error #1006: setSize is not a function.
Please advise.
I have worked with the Chromeless player before and gotten these errors. They are so frustrating. A number of the errors can be ignored because YouTube still hasn't renewed their default policy file.
Whevener you try to add any mouse event listeners to the gadget directly you will get errors that will cripple the runtime process. What I had to do to add mouse interactivity was to add a sprite above the movie clip with a hole where their logo shows up (so that someone can still click their logo) and then add event listeners to your own srite.
Hope this helps.
What finally worked to remove the errors was specifying... LoaderContext(false, new ApplicationDomain())