I am trying to check when the right button of the mouse is up. I have tried to create an EventListener for RIGHT_MOUSE_UP, but it returns an error (1119: Access of possibly undefined property RIGHT_MOUSE_UP through a reference with static type Class.), while MOUSE_UP doesn't work. How I can do this?
EDIT:
public function mouseOverHandler( evt:MouseEvent )
{
if( evt.buttonDown == true )
{
this.addEventListener( MouseEvent.MOUSE_UP, onMouseRelease);
curState_ = 2;
if( animated_ == true )
{
// Stuff
}
else
{
// Stuff
}
}
else
{
// Stuff
}
dispatchEvent(new CustomButtonEvent(CustomButtonEvent.OVER));
}
check this tip http://www.leebrimelow.com/?p=3253
he said you need FP 11.2 beta for using 'MouseEvent.RIGHT_CLICK' event.
Related
According to a prior SO answer, you can implement getPriority for a forge viewer Tool. And according to another SO answer extending the ToolInterface does not work. Hence, me not extending the ToolInterface implementing my Tool like so:
class MyCustomExtension extends Autodesk.Viewing.Extension {
constructor(viewer, options) {
super(viewer, options);
this.theiaUtil = new TheiaUtil(this);
}
getPriority() {
console.log("Theia#getPriority called! ", (this.getPriority && this.getPriority() || 0));
return 100000;
}
...
}
My tool's priority is returned as 0 in the ToolController, although it shouldn't:
function getPriority(tool)
{
return tool.getPriority instanceof Function && tool.getPriority() || 0;
}
I don't know why this function returns 0 as tool.getPriority instanceof Function returns true if I call MyCustomExtension.getPriority myself.
Note that ToolInterface is implemented like so:
function ToolInterface()
{
this.names = [ "unnamed" ];
this.getNames = function() { return this.names; };
this.getName = function() { return this.names[0]; };
this.getPriority = function() { return 0; };
this.register = function() {};
this.deregister = function() {};
this.activate = function(name, viewerApi) {};
this.deactivate = function(name) {};
this.update = function(highResTimestamp) { return false; };
this.handleSingleClick = function( event, button ) { return false; };
this.handleDoubleClick = function( event, button ) { return false; };
this.handleSingleTap = function( event ) { return false; };
this.handleDoubleTap = function( event ) { return false; };
// ...
}
Because of that, simply extending the ToolInterface class won't work because all these properties and functions added to the instance in the constructor will take precedence over your actual class methods. This is also likely the reason why you're seeing the priority value returned as zero - when you call myTool.getPriority(), you are not actually calling your getPriority method, but rather the default function which was assigned to this.getPriority in ToolInterface's constructor.
To work around this issue I would recommend explicitly deleting the corresponding fields in your class' constructor (something I explain in my blog post on implementing custom Forge Viewer tools):
class DrawTool extends Autodesk.Viewing.ToolInterface {
constructor() {
super();
this.names = ['box-drawing-tool', 'sphere-drawing-tool'];
// Hack: delete functions defined *on the instance* of the tool.
// We want the tool controller to call our class methods instead.
delete this.register;
delete this.deregister;
delete this.activate;
delete this.deactivate;
delete this.getPriority;
delete this.handleMouseMove;
delete this.handleButtonDown;
delete this.handleButtonUp;
delete this.handleSingleClick;
}
register() {
console.log('DrawTool registered.');
}
deregister() {
console.log('DrawTool unregistered.');
}
activate(name, viewer) {
console.log('DrawTool activated.');
}
deactivate(name) {
console.log('DrawTool deactivated.');
}
getPriority() {
return 42; // Or feel free to use any number higher than 0 (which is the priority of all the default viewer tools)
}
// ...
}
TL;DR: Activate the tool in button click event from a toolbar button instead of the extension's load method.
class MyExtension extends Autodesk.Viewing.Extension {
...
onToolbarCreated(toolbar) {
const MyToolName = 'My.Tool.Name'
let button = new Autodesk.Viewing.UI.Button('my-tool-button');
button.onClick = (e) => {
const controller = this.viewer.toolController;
if (controller.isToolActivated(MyToolName)) {
controller.deactivateTool(MyToolName);
button.setState(Autodesk.Viewing.UI.Button.State.INACTIVE);
} else {
controller.activateTool(MyToolName);
button.setState(Autodesk.Viewing.UI.Button.State.ACTIVE);
}
};
}
...
}
I activated the tool instantly after registering it in the Extension's load method. Petr Broz's github repo from his blog post loads the tool from a button in the toolbar. So I moved the activation of the tool to a button click in the toolbar which worked for me.
In my code i use both swipe gesture and click event at the same time. How to avoid click event or touch event while swipe gesture is in action?
stage.addEventListener (TransformGestureEvent.GESTURE_SWIPE, fl_SwipeHandler);
wall.tile[0].addEventListener(MouseEvent.CLICK, showBook());
wall.tile[1].addEventListener(MouseEvent.CLICK, showBook());
public function fl_SwipeHandler(event:TransformGestureEvent):void
{
switch(event.offsetY)
{
// swiped down
case 1:
{
if (swipe!=0){
Tweener.addTween(wall, {y: wall.y + 650, time:.5, transition:"easeOutSine" } );
swipe--;
}
// End your custom code
break;
}
// swiped up
case -1:
{
if (swipe<=(total/5)){
Tweener.addTween(wall, { y: wall.y - 650, time:.5, transition:"easeOutSine" } );
swipe++;
}
// End your custom code
break;
}
}
}
I usually have some boolean variable set to true when swipe is being activated, and onComplete function of tweener sets it back to false. And that boolean is one condition in my onClick functions (as false obviously):
public var swipeOn:Boolean;
public function fl_SwipeHandler(event:TransformGestureEvent):void{
switch(event.offsetY){
case 1:{
if (swipe!=0){
swipeOn = true;
Tweener.addTween(wall, {y: wall.y + 650, time:.5, transition:"easeOutSine", onComplete:doneSwipe } );
swipe--;
}
break;
}
case -1:{
if(swipe<=(total/5)){
swipeOn = true;
Tweener.addTween(wall, { y: wall.y - 650, time:.5, transition:"easeOutSine", onComplete:doneSwipe } );
swipe++;
}
break;
}
}
}
public function doneSwipe():void{
swipeOn = false;
}
public function showBook(Event:MouseEvent):void{
if(!swipeOn){
//....handle your clicks etc
}
}
I have a class file that has some netstreams and connections and I'm trying to remove the class completely. Here's my code:
function onTestProcessed(e:CustomEvent2):void {
// Remove
rtmp_test.removeEventListener(CustomEvent2.PASS_PARAMS, onTestProcessed);
e.currentTarget.parent.removeChild(e.currentTarget);
// Validation comparison
if (e.boo == false) {
trace("event.boo = ", e.boo);
} else {
trace("event.boo = ", e.boo);
}
}
This code removes the display of video but not its sound. Do I have to find each variable in the class and remove them one by one?
Seems like this solved the problem:
function onTestProcessed(e:CustomEvent2):void {
// Remove
rtmp_test.removeEventListener(CustomEvent2.PASS_PARAMS, onTestProcessed);
rtmp_test.netStreamObj.close();
// rtmp_test.netStreamObj = null;
rtmp_test.vid.clear();
e.currentTarget.parent.removeChild(e.currentTarget);
// Validation comparison
if (e.boo == false) {
trace("event.boo = ", e.boo);
} else {
trace("event.boo = ", e.boo);
}
}
as3 - How to stop video and detach NetStream
Its usual to use Mouse Event Listener like this :
MyButton.addEventListener(MouseEvent.MOUSE_UP, MyFunction);
function MyFunction(event:MouseEvent):void
{
// my function codes
//...
//...
}
but I want use a variable in my function , something like this:
//var Tx:Number = any Formula;
MyButton.addEventListener(MouseEvent.MOUSE_UP, MyFunction(Tx));
function MyFunction(event:MouseEvent,T:Number):void
{
if ( T == 1 ) { ... }
if ( T == 2 ) { ... }
if ( T == 3 ) { ... }
}
How can I do it ?
i'd imagine you will attach the listener to different button/movieclips. then, access the event.currentTarget and change the value of your variable.
button1.addEventListener(MouseEvent.MOUSE_UP, doSomething);
button2.addEventListener(MouseEvent.MOUSE_UP, doSomething);
function doSomething(event:MouseEvent):void {
var str:String;
if (event.currentTarget.name == 'button1')
str = 'one';
else
str = 'two';
}
or something like that.
It seems to me you want to create a closure
function process(t:Number)
{
return function(event:MouseEvent) {
if ( t == 1 ) { ... }
if ( t == 2 ) { ... }
if ( t == 3 ) { ... }
}
}
MyButton.addEventListener(MouseEvent.MOUSE_UP, process(1));
This will return a function from "process" that will act a the event listener and that encloses the parameter T.
ps: Even thou ActionScript allows hoisted functions (that is functions that are called before they are defined) I would regard that as bad style. Also use lowercases as Parameter names. Uppercase names are usually a hint that this is a Type.
I got this function (in the document class)
public function kyz(event:KeyboardEvent):void{
trace(event.keyCode);
switch (event.keyCode){
case 65:{
if (ppm.currentFrame<200 || ppm.currentFrame>300) {
ppm.gotoAndStop(301);
ssm.gotoAndStop(302);
llm.gotoAndStop(302);
mmm.gotoAndStop(302);
myTimer.stop();
pd.play();
}else {
pd.play();
ppm.gotoAndPlay(10);
tlrnc-=10;
}
break;
}
case 68:{
if (ssm.currentFrame<200 || ssm.currentFrame>300) {
ssm.gotoAndStop(301);
ppm.gotoAndStop(302);
llm.gotoAndStop(302);
mmm.gotoAndStop(302);
myTimer.stop();
mTimer.stop();
sd.play();
}else {
sd.play();
ssm.gotoAndPlay(10);
tlrnc-=10;
}
break;
}
case 74:{
if (llm.currentFrame<200 || llm.currentFrame>300) {
llm.gotoAndStop(301);
ppm.gotoAndStop(302);
ssm.gotoAndStop(302);
mmm.gotoAndStop(302);
myTimer.stop();
mTimer.stop();
ld.play();
}else {
ld.play();
llm.gotoAndPlay(10);
tlrnc-=10;
}
break;
}
case 76:{
if (mmm.currentFrame<200 || mmm.currentFrame>300) {
mmm.gotoAndStop(301);
ppm.gotoAndStop(302);
ssm.gotoAndStop(302);
llm.gotoAndStop(302);
myTimer.stop();
mTimer.stop();
md.play();
}else {
md.play();
mmm.gotoAndPlay(10);
tlrnc-=10;
}
break;
}
}
}
that receives key event's and do stuff. now I'm trying to pass they keyCode from another function (to avoid changing the whole code for adding click functionality) got any suggestions?
you could dispatch a KeyboardEvent
stage.dispatchEvent(
new KeyboardEvent(KeyboardEvent.KEY_DOWN, true, false, myCharCode, myKeyCode));
just add the needed keyCode as a parameter
You cannot send any Keyboard or Mouse event without interactivity with user. You can handle this in another private function:
private function keyDownHandler(event : KeyboardEvent) : void {
this.handleEvent(event.keyCode);
}
private function handleEvent(keyCode : uint) : void {
//some actions
}
And when you need to make specific actions, you can just call handleEvent function without user side interactivity.