AIR iOS app hangs when clicking button inside imported swf - actionscript-3

Been bangin my head against a wall all day, thought I'd see if anyone can shed some light on this -
I have an iOS air app that imports a remote swf. Once imported, an event listener is added to a button inside the imported swf. Clicking the button causes the app to hang. Here's some code -
private function loadRemoteSWF():void{
var urlRequest:URLRequest = new URLRequest("http://www.domain.com/remote.swf");
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaded);
loader.load(urlRequest);
}
private function onLoaded(e:Event):void{
var loaderInfo:LoaderInfo = e.currentTarget as LoaderInfo;
var adPanel:MovieClip = loaderInfo.content as MovieClip;
adPanel.continueButton.addEventListener(TouchEvent.TOUCH_BEGIN, onContinueClicked);
addChild(adPanel)
}
private function onContinueClicked(e:TouchEvent):void{
trace("onContinueClicked");
}
I'm using Flash Builder 4.7 AIR SDK 3.5 ASC 2.0.
This only happens on a release build, debug builds work fine so near impossible to find the cause. It also works fine when using the legacy compiler on the same SDK version.
Dispatching a touch event programatically on the button also works fine. (thought I could do a try/catch to find an error)
adPanel.continueButton.dispatchEvent(new TouchEvent(TouchEvent.TOUCH_BEGIN));
Touching the button just kills the app, it doesn't even hit the trace.
Anyone got any ideas how to debug this, or why this problem might be happening?
Thanks
Dave

can you do a test: instead of using the the native loader, try using an API, like greensocks api - SWFLoader.
Also, try setting the accepted domains through the security class prior to loading the swf file:
import flash.system.Security;
public class Main extends MovieClip{
public function Main(){
Security.allowDomain("*");
}
}
I would suggest trying to compile with the same setup on a different machine, just to make sure that the Builder install doesn't have some issues.
Also, have you tried on different devices, (could be an issue with the device you are using)?

Related

ActionScript 3 - sound mp3 is not played without error

Help me, I use Adobe Flash CS3 Professional.
// i have try using this import, but still not work
/*import flash.events.Event;
import flash.media.Sound;
import flash.net.URLRequest;
*/
// here is the code
var req:URLRequest=new URLRequest("music.mp3");
var snd:Sound=new Sound();
snd.load(req);
var chan:SoundChannel=snd.play();// not work using 'snd.play(1);' too
chan.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);
function onPlaybackComplete(event:Event){
trace("Musik Complete");
}
When i run the swf or ctrl+enter, the output Musik Complete without any sound played, but the animation still played. For the animation i just create simple twin motion.
i work on this directory
C:/flash/example.fla
C:/flash/example.swf
C:/flash/music.mp3
I have try to import music.mp3 into the library too.
Note: I get the example from my friend(.swf, .fla, .mp3). I play the .swf that shared by my friend and work, but when i try to create by my self, is not work. So, i think music.mp3 was fine to use for Flash. Here is my friend code:
var Audio:musik = new musik();
var chan:SoundChannel = new SoundChannel();
// play
chan=Audio.play();
// stop
chan.stop();
// i am so confuse i run my friend project and work fine (sound and other), if i write from scrap even i write the same code, there is an error, and this the error:
// 1046: Type was not found or was not a compile-time constant: musik.
// 1180: Call to a possibly undefined method musik.
I just watch on youtube, i missing one step.
In library, open properties of music.mp3 and give it class name.
So, we can call the class using this var Audio:musik=new musik();.
Then, create the Sound Channel.
At least, function to play and stop using this:
//play
chan=Audio.play();
// stop
chan.stop();

Adobe Air loading external swf with allowDomain('*') inside

What i have
Large amount of swfs without it's sources (so i couldn't modify its)
What i need
To load and play this swfs with my AIR app.
The problem
The problem is that this swfs seems having
Security.allowDomain('*')
in their source, so they would throw
SecurityError: Error #3207: Application-sandbox content cannot access
this feature.
after i load it. I know that Air doesn't need to use this line, but instead of ignoring or warning on it my full app would stop to executing after loading one of this swfs. If only i could try/catch this string, but as i said i don't have an source of that swfs, so the only thing i could do is to modify my AIR app.
What i tried
What i already tried is to catch all errors inside loader by doning
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, loaderIOErrorHandler);
private function loaderIOErrorHandler(e:IOErrorEvent):void {
e.preventDefault();
}
but it seems it isn't catch errors inside loader at all
Update
I couldn't share one of this swfs, but here is simulation i made that reproduce problem https://www.dropbox.com/s/0spbdzijfpboi47/problematicSwf.swf?dl=0
Here it's init code
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
Security.allowDomain('*');
tf = new TextField();
tf.text = 'Me loaded!';
addChild(tf);
}
As you could see it is crashing on allowDomain inside loaded swf.
And here is how i load it
var ctx:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain);
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaded);
loader.load(new URLRequest(path), ctx);
This is a typical security restriction but it's a very strict one and it's purpose is to make sure the served swf will never be used outside of what it was made for in the first place.
So the short answer to your problem is this: externally loaded swf that are sandboxed with "Security.allowDomain('*');" will not allow a sandboxed AIR app to interact with them in anyway. Instead those swf will be able to interact with the parent AIR app under restrictions via a sandbox bridge.
If truly you cannot modify those swf then you will never be able to add them to a display list in a AIR app or call any of their methods. A sandbox bridge will also be of no use to you.
It's not the answer you want to hear I bet but it's the only one you'll get.

AS3:loading XML is not working after exporting the air file?

import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
names();
function names()
{
var url:URLRequest = new URLRequest("http://artbeatmedia.net/application/xmlkpisname.php?username=adel_artbeat&password=ADL1530");
url.contentType = "text/xml";
url.method = URLRequestMethod.POST;
var loader:URLLoader = new URLLoader();
loader.load(url);
loader.addEventListener(Event.COMPLETE, onLoadComplete);
}
function onLoadComplete(event:Event):void
{
trace('good');
}
i used adobe air to load xml using as3,this code works only in the .fla file,but when i export the .air file it does not work.
if you export a program, trace messages won't be visible.
you can still use MonsterDebugger, but thats a security hazard.
Vizzy tracer will still capture trace calls from an Air app. Get Vizzy from Google code
I tried your code with no modifications just now and it worked just fine, so I suppose your problem is just a failed trace out. Have a go, Vizzy shows even traces from within Flash IDE, so see what happens. If it still fails, then it might be some connection/permission issue.
Are you including the XML file when you publish the AiR app? Happened to me once, forgot to include the file in the publish dialogue....an hour of my life I'll never get back.

flash filereference select event not firing after using browse() and after selecting a file

This is the first time i am working in action script. I have seen a flash programmer working with it. since i know javascript i was able to work in action script.
I am creating a file upload component for my php projects.
Until now i have advanced to show the file dialog box using the FileReference api.
The select event is not firing for me. and i did not get any error.
import fl.controls.Button;
import flash.events.*
import flash.net.FileReference
var fr:FileReference = new FileReference();
fr.addEventListener(Event.SELECT,sico);
var myButton:Button = new Button();
addChild(myButton);
myButton.label = "Click Me";
myButton.addEventListener(MouseEvent.CLICK, function(e:MouseEvent)
{
myButton.label = "clicked";
fr.browse();
trace('clicked');
})
function sico(event:Event):void
{
//var file:FileReference = FileReference(e.target);
myButton.label = "selected";
trace('selected');
//trace("progressHandler: name=" + file.name + " bytesLoaded=" + e.bytesLoaded + " bytesTotal=" + e.bytesTotal);
}
The documentation said that file references should be called only during an event like mouse or keyboard.
what am i missing in the above code?
The example you posted works in Flash CS5 and Flash Player 10.3 which means the problem is not with the code.
Other potential causes of the issue could be:
The version of Flash Player which you are using is too old. FileReference requires Flash Player 9 or better. Right-click on the Flash Player or use trace(Capabilities.version) to see the version number.
Another part of the application is using a FileReference method (eg: FileReference.browse(), FileReference.upload(), FileReference.download(), FileReference.load(), FileReference.save()). Flash player 10+ allows only one file operation at a time.
If you are using a Mac, then FileReference may only dispatch the SELECT event when the SWF is run inside of a browser.
IT was like as stated by user:lukevanin in the comment section of his answer. and me too found the same. The problem was i had many frames in the timeline. since i was new to action script while toggling between F9 i was trying F5 so it created frames and it was looping continuously between that.

Flash saves in Windows, not in Linux, FileReference.save()

The code below compiles fine on the Flex 4 SDK on Fedora 15. Mouse-click opens the dialog box, I click okay, and a file is saved, but the file is empty. I run the same SWF file (that was compiled on the Linux machine) on a Windows machine, and the created file contains the expected data.
Then I broke the FileReference declaration out of the function into the class level, hoping to avoid a known bug, but the same problem persists.
Hoping to set up a workaround, I added the debug Flash player to my path and ran the file from Flash without the benefit of the browser, and it works. So now a Flex problem has become a Firefox problem, maybe owing to a shady procedure I used to install the plugin without really understanding what was happening. I am running Firefox 5.0.
In essence my workflow is fixed, but perhaps people who performed the above will not be able to use projects with FileReference.save()? Should I be worried about this edge case?
/*
WriteTheFile.as
Original code by Brian Hodge (brian#hodgedev.com)
Test to see if ActionScript/Flash can write files
*/
package{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.utils.ByteArray;
import flash.net.FileReference;
public class WriteTheFile extends Sprite
{
private var _xml:String;
private var fr:FileReference;
public function WriteTheFile():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
//Calling the save method requires user interaction and Flash Player 10
stage.addEventListener(MouseEvent.MOUSE_DOWN, _onMouseDown);
}
private function _onMouseDown(e:MouseEvent):void
{
fr = new FileReference()
fr.save("<xml><test>data</test></xml>", "filename.txt");
}
}
}
EDIT: was missing a line, fixed above
EDIT: addressed answer in code above, but the same problem exists.
EDIT: This works on the same system when the standalone player is invoked. Therefore this is a browser (FF 5.0) plugin problem.
Try putting the line
var fr:FileReference = new FileReference();
at class level (outside the function). Apparently this is a known bug:
http://www.techper.net/2007/12/30/flash-filereferencebrowse-problems-on-linux/