Action script 3.0 onSwipe{ gotoAndPlay(x); { - actionscript-3

Action script 3.0
swipe left/down/right/up gotoAndStop/play (x)?? Someone got a skeleton code of this? I know how to make it in Air for ios/android, but not on regular 3.0. Thanks.

Since you're asking in general - you're not showing specific code:
Use MouseEvents in place of TouchEvents - mousedown in place of a touchBegin for example. mouseX for the position, mouseMove event for swipe code, etc.
Unless you're handling gestures, it should be pretty easy to swap.

Related

How does Haxe/OpenFL handle canvas click events?

I am adding a canvas on top of a Haxe HTML5 Game. But once I do, the buttons in the Haxe game no longer register the click events. Does anyone know in the Haxe/openFL compiled code where the click events are being handled?
My best guess is that they are looking at the top most canvas, which is now mine and therefore not seeing the hits.
EDIT:
Found this code where the mouse events were being added to the canvas:
while(_g2 < mouseEvents.length) {
var type2 = mouseEvents[_g2];
++_g2;
element1.addEventListener(type2,$bind(this,this.element_onMouse), true);
}
Where element1 = the canvas.
I can't seem to send $(canvas).click() events to that canvas. Anyone have further suggestions?
My conclusion is, I was using JQuery to send calls to event listeners that were added through plain JavaScript.
document.getElemntById("canvas").addEventListener("mousedown", func...);
Apparently the JQuery calls can not call non JQuery events.
$(canvas).mousedown(); // does not work
Using
document.getElemntById("canvas").dispatchEvent(event) r
and sending MouseEvents to the Haxe canvas worked fine.

Animating from within classes in Actionscript 3 (Not on the timeline), what's the best way?

I've found some stuff online about how to animate in actionscript 3 from within a class, but haven't been able to find a really good tutorial. I want to control the animations from a class because at some point I intend to move from the flash IDE to using flash develop, where I won't have access to the Flash IDE's timeline.
I have to be able to control an initial animation (opening a bag) which joins onto an animation loop (searching through a bag).
The only way I have been able to do this so far is to add an event listener to listen for the initial animation's final frame. Then when initialAnimation.currentFrameLabel = "Last" then I gotoAndStop("animationLoop").
This has been working fine, if a bit time-consuming. I'm just wondering if there's a better, easier way to do it? Can anyone tell me or point me towards a tutorial that does it better? Thanks very much!
Romano
I recommend instead of using an event listener, you use the method addFrameScript. Essentially you can fire a method when a specific frame number is reached.
Read the following question for more information.
actionscript3 whats the point of addFrameScript
It depends on what it is you want to do:
Usually if you are working together with an artist or want to do animations that are non-code driven, the "best way" is usually to listen for something to happen, and then start animations and on last frame of animation (or when you want to return control to code) you create an event, or use a callback or something else to let code notify that animation is complete or reached a certain point.
If you want to do something from code, the easiest way is to use an external animation library.
Tweener (https://code.google.com/p/tweener/)
TweenLite (http://www.greensock.com/tweenlite/)
Using those libraries, you would write something similar to:
function fadeOut():void {
mc.alpha = 1;
Tweener.addTween(mc, {alpha:0, time:0.275, delay:1, onComplete:onDone});
}
function onDone():void {
trace("Animation finished");
}

ActionScript 3 scrolling issues

I'm trying to make a google maps style interface for a design project. I've got the drag/drop and zoom functions working, but I also want to make it react to gestures on a trackpad (macbook). I assumed 'listening' to the event.delta of a MouseEvent would do the trick, but somehow it's not working. So what's wrong with my code?
stage.addEventListener(MouseEvent.MOUSE_WHEEL, onMouseWheelEvent);
function onMouseWheelEvent(event:MouseEvent):void {
tafelOrigineel_mc.y += event.delta;
}
I have loaded the flash MouseEvents earlier in the document, so that shouldn't be the problem. After I got this working, I will try to use it on the x-axis too. Is that possible with the MOUSE_WHEEL eventlistener?
Thx in advance
It is a long time problem regarding flash player on MacOS.
MOUSE_WHEEL event won't dispatch on MacOS. Though there are some workarounds involving the use of JavaScript to detect the use of the wheel (over the entire flash content), if it isn't a issue, try checking one of those.
There is a list in this blog post:
http://www.impossibilities.com/v4/2009/03/06/flash-mousewheel-implementations-for-mac-os-x/

mouseX/mouseY Actionscript function equivalent in Cocos2D

This might be irritating simple. I am trying to convert some code from actionscript to cocos2d. I am quite new to actionscript and would like to know if there is a cocos2d function for mouseX/mouseY. If not, what would be the equivalent. Can someone please help me.
In Kobold2D (which is based on cocos2d-iphone) you can use the mouseLocation:
CGPoint mousePos = [KKInput sharedInput].mouseLocation;
KKInput captures the mouse location every time it receives an event. If mouse moved events are enabled, mouse location gives the accurate location of the mouse.
The alternative is to use the NSWindow method mouseLocationOutsideOfEventStream.

Flash & external form fields

Does anybody know if this is possible?
I am trying to create a flash movie that will show / preview what I am typing into a field in a normal HTML form. The call to update the flash movie would most likely be attached to an onKeyUp event.
Any advice or tutorials would be great
cheers!
Decbrad
Assuming you're using actionscript 3....
Check this out
You can also check this link out (its for Flex 3 though... AS3 should be similar for flash I believe)... I've used ExternalInterface in my Flex projects before.
As far as I'm aware, Flashplayer only listens to key events when it has focus (which it wouldn't have if you're typing into an HTML form. I'm not aware of any way to inject events into Flash with javascript.
Is there a particular reason why you can't use a text area in the actual flash movie itself?
My advise would be to grab your favorite event utility for JavaScript and then pair it with ExternalInterface. That way, you can add a callback to the EI in Flash which would mean that you could do something like this:
ExternalInterface.addCallback( "keyboardClicked", dispatcherFunc );
function dispatcherFunc():void
{
dispatchEvent( new Event( "javaScriptKeyClick" ) );
}
document.getElementById( "mySwf" ).keyboadClicked();
Hey guys, thanks for pointing me in the right direction! I haven't touched flash since version 4 so to say that i'm rusty... is an understatement!
The reason I haven't built the text area in the actual flash movie is because the system is 95% complete now and there's a lot of smarts on the server side. The flash preview is more or less the icing, as they say! Bit surprised there's not more of a hook into Flash.
Thanks again!
Dec