AS3 MouseEvent.RIGHT_MOUSE_UP doesn't work - actionscript-3

I am trying to create a boolean where it checks if the right-mouse button is pressed or not. With the left mouse button this method works, but with the right mouse button the boolean stays true, how do I fix this?
public var mDown:Boolean = false;
public var rmDown:Boolean = false;
stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseHandler);
stage.addEventListener(MouseEvent.MOUSE_UP, mouseHandler);
stage.addEventListener(MouseEvent.RIGHT_MOUSE_DOWN, mouseHandler);
stage.addEventListener(MouseEvent.RIGHT_MOUSE_UP, mouseHandler);
private function mouseHandler(e:MouseEvent){
switch(e.type){
case MouseEvent.MOUSE_DOWN: mDown = true;
break;
case MouseEvent.MOUSE_UP: mDown = false;
break;
case MouseEvent.RIGHT_MOUSE_DOWN: rmDown = true;
break;
case MouseEvent.RIGHT_MOUSE_UP: rmDown = false;
}
}
My Flash exports to Flash Player 11.2! Maybe I can try something with RIGHT_CLICK?

This seems to be a player version problem. Right-click-up compiles, but fails silently at runtime in 11.2. It compiles and runs fine in 11.4. I tested in Flash CS6, where my player version is WIN 11,2,202,228, and got exactly the same silent failure that you report.
I then tested in FlashDevelop (swapping the right mouse enums for "rightMouseDown" and "rightMouseUp", because completion on my version doesn't recognise the new enum event values), and tested with projector debugger version WIN 11,4,402,265, and right mouse down and up both worked fine. It also works fine in the latest production release of the plugin and active X players, versions 11.4.* across IE, Firefox and Chrome, on a Win 7 machine.
I'm not sure what development environment you're using, and if its Flash Pro CS* then I'm not sure how you upgrade the player version, but it should be straightforward with FlashBuilder or FlashDevelop. And I'm sure you know already that you can use flash.system.Capabilities.version to double-check what player version you are testing in. I was surprised to find CS6 still using 11.2 when the .swf file association in my system is normally with the 11.4 debugger.

Related

AIR iOS app hangs when clicking button inside imported swf

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)?

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 debugger behaving differently from the player with AS3 and Events

Why this works on flash professional's debugger, but brings null on the compiled SWF?
var firstParameter:SomeObject = new SomeObject();
someLoader = new Loader();
someLoader.contentLoaderInfo.addEventListener(
Event.COMPLETE
, function(evt) {
onLoaded(evt, firstParameter);
}
, false
);
function onLoaded (evt:Event, param:SomeObject):void {
mcOnSceneForTracing.text = param; // this is used for SWF debugging
}
For the record:
To make it work without any issues this can be "solved" by creating a separate scope. However, here I'm wondering why, then, this example even works on the debugger at least.
And, please, if you have a better way other than using two anonymous functions to pass parameters, variables, values, whatever through an Event, do tell! I'm not willing to extend the Event, tho. Too 2005.
mcOnSceneForTracing is what I'm using to "trace" outside the debugger. Suggestions are also accepted here for better (and simpler) ways to do it! I've heard Vizzy is good, but haven't tried it yet.
My guess would be: When loading your resource from the debugger player, the operation finishes instantly, and thus firstParameter is available when your anonymous listener function is called, but when running the swf elsewhere, the load operation takes longer, and then the reference to firstParameter is lost, since it is a local variable.

AS3: Enable features according to Flash Player Version

I'd like to know if it is possible to enable/disable some piece of code according to Flash Player version in ActionScript 3.
Let's say; I have a custom class customClass that uses flash.media.Microphone. The Microphone class has a property isSupported which is available for Flash Player version 10.1 and above (as stated in the documentation). I implement this property in my customClass... so:
I need something like this (by checking with the built-in Capabilities.version):
if (version >= 10.1) {
trace(_mic.isSupported); //this will throw an error if the debug version is not 10.1 or later
} else {
doSmthElse();
}
is there a way to do this?
This is the only way I know:
if (version >= 10.1) {
trace(_mic["isSupported"]); //this will throw an error if the debug version is not 10.1 or later
} else {
doSmthElse();
}
With the bracket access syntaxt the verifier won't try to check whether the method or property is defined in advance (at load time, I think). So your code will only be evaluated at runtime, if it actually runs.

Flash Player 10.1 for Flash Professional CS4 playerglobal.swc?

Adobe released projector, debugger and plugin for Flash 10.1 yesterday. on my Mac i've installed the standalone player and debugger in Adobe Flash CS4/Players/ and Adobe Flash CS4/Players/Debug respectively.
however, i think i need to download the globalplayer.swc for 10.1 so that Flash CS4 IDE is directed to use the new players.
i've searched but i could only find the globalplayer.swc that was released during the 10.1 betas, and i'm not sure if that's the .swc i should use for the final 10.1 release.
Adobe's site doesn't mention anything about replacing the .swc to use 10.1 in CS4, so i'm not sure if it's necessary.
i've tried creating actionscripts to include flash.ui.Multitouch and flashx.textLayout and neither can be found. i have no idea how to make Flash Professional CS4 use the new APIs available in Flash Player 10.1
suggestions?
FRAME SCRIPT:
import flash.ui.Multitouch;
var myTextField:TextField = new TextField();
myTextField.width = 200;
addEventListener(Event.ENTER_FRAME, enterhandler);
function enterhandler(e:Event):void
{
var support:Boolean = Multitouch.supportsTouchEvents;
switch (support)
{
case true: myTextField.text = "Touch events supported";
break;
case false: myTextField.text = "Touch events not supported";
break;
default: myTextField.text = "unknown";
}
addChild(myTextField);
}
ERROR: (continuous enter frame event error)
ReferenceError: Error #1065: Variable flash.ui::Multitouch is not defined.
at multitouchtest_fla::MainTimeline/enterhandler()
ReferenceError: Error #1065: Variable flash.ui::Multitouch is not defined.
at multitouchtest_fla::MainTimeline/enterhandler()
ReferenceError: Error #1065: Variable flash.ui::Multitouch is not defined.
at multitouchtest_fla::MainTimeline/enterhandler()
You can get the official playerglobal.swc for Flash Player 10.1 from the Flex 4.1 SDK:
http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4
It's in the frameworks/libs/player/10.1 directory.
Also you can check if the device supports gestures and touch using these statics:
Multitouch.supportsGestureEvents
Multitouch.supportsTouchEvents
Not sure whether it's up to date but it's at least for 10.1 beta:
http://labs.adobe.com/downloads/flashplayer10.html
I had similar issues with my Flash CS4, recently i have found one important link for that check out
http://swfhead.com/blog/?p=709
http://swfhead.com/blog/?p=133
hope it helps... :)