How to interrupt CCScrollView 's setContentOffsetInDuration()? - cocos2d-x

In order to slide and show contents of my CCScrollView, I called
ScrollView::setContentOffsetInDuration(Vec2 offset, float dt)
and according to the code, it scheduled a MoveTo action.
But in some context I need to interrupt and cancel the action, can anyone tells me how to do it?
Thanks.

Well I found a solution. Use
ScrollView::getContainer()->stopAllActions()
works well for me :)

Related

DataVizExtention: issue with clearing viewables while a sprite is selected

In my code, I have this workflow:
When user wants to see some things, add Sprites using 'DataVizCore.addViewables()'
Use 'viewer.addEventListener(DataVizCore.MOUSE_CLICK, onDotClick)' to show info bubble
When user wants to show other things, call 'DataVizCore.removeAllViewables()' to clear Sprites
Repeat from step 1
This sequence works OK except in one situation.
If a sprite was selected (by clicking on it) before removeAllViewables() is called, I don't get MOUSE_CLICK event for newly added Sprites. In browser console, I see following error is thrown.
CustomViewables.js:318 Uncaught TypeError: Cannot read property 'style' of undefined at ViewableData.getViewableUV (developer.api.autodesk.com/modelderivative/v2/viewers/7.*/extensions/DataVisualization/DataVisualization.js:454)
As a workaround, I added 'event.hasStopped = true' to click event handler to prevent Sprite getting selected internally. That seems to work.
This seems like a bug in DataVizExtension to me. Or, my workflow is wrong?
Thanks
Bandu
Bandu. Thanks for the detailed steps to reproduce this issue. I tried with v7.46.0 version of the DataVisualization.js (latest as of my message) but was not seeing the same issue. I'd be curious if you are using this same version of the Forge Viewer (you can figure that out by looking at the viewer3D.js fetched under the Network tab of Chrome DevTools).
Setting event.hasStopped = true works because it internally avoided the code path calls into getViewableUV that threw the exception, but the flag is meant for other use cases (e.g. overriding default sprite selection behavior).
In any case, I've just tweaked our internal code to make use-cases like yours more robust. The changes will be released with the upcoming v7.47.0. Thank you for your feedback 🙂

Button that only works once in flash actionscript 3.0

I have this collecting item game which u have to collect enough "stars" in order to acess a button. After I clicked the "star" button, it suppose to disappear and never appear again. However, when using this script, although the button disappear once I clicked it, when I returned to the frame after going to another frame, it appeared again! pls help!
star1.addEventListener(MouseEvent.CLICK,gotstar);
function gotstar(event:MouseEvent){
stars++;
star1.x = -500;
}
Are you coding on the frames themselves? If so every time you enter a frame it will run every piece of contained code, even if it has already ran once. A solution to this would be to use a document class to track the progress of the game.
you need to remove it from the stage if I understand.
try this instead of star1.x = -500;
stage.removeChild(star1);
star1.removeEventListener(MouseEvent.CLICK,gotstar);
star1.parent.removeChild(star1); in the click handler code (gotstar) should help
however posting your .fla file might be useful for better understanding

Force immediate layout and paint in Swing

I cannot seem to force a layout in Swing. I have a JComponent added to a JLayeredPane and I set a border on the JComponent. Then, I want to immediately re-draw everything - not in the sense of "please do this asap" like invalidate(), but synchronously and immediately. Any help? I cannot seem to find the right method of doing this, and all my reading about invalidate(), validate(), repaint(), doLayout(), etc is just confusing me more!
According to this (see the section titled "Synchronous Painting") the paintImmediately() method should work.
The most reliable way to get Swing to update a display is to use SwingUtilities.invokeLater. In your case, it would look something like
SwingUtilities.invokeLater(new Runnable {
public void run() {
somecomponent.repaint();
}
});
I realize the 'invokelater' does not exactly sound like it does anything immediate, but in practice, events posted in this way tend execute pretty quickly compared to just calling e.g. somecomponent.repaint() directly. If you absolutely must make your control code wait for the GUI to update, then there is also invokeAndWait, but my experience is that this is rarely necessary.
See also: document on event dispatch in Swing.
This is super old, but I found a simple solution, which I'll show with a JPasswordField:
var pw = new JPasswordField();
...
pw.paint(pw.getGraphics()); // paints immediately

as3 MouseEvent localX acting weird

I encountered this really weird situation, I have this bar and I addEventListener to it, so when
the bar's clicked, trace localX
private function _barClicked($e:MouseEvent):void {
trace($e.localX)
}
The weird thing is that, when clicking at the same spot, sometimes it jump to a wrong number
which I can't figure out why, I traced the width of the bar, and it's the right value, the localX is
just giving me random numbers. Has anyone ever ran into this problem? Thanks!
Hmmm, strange
I've tried a simple scenario where I have a rectangle named 'bar' and pasted your listener for the CLICK event, then tried the MOUSE_DOWN event. Both worked fine.
I didn't get random values.
My guess is your bar clip contains other objects inside and you might get values from children of bar, not bar itself. Not sure though, it's just a guess.
You could try to make sure that your values come from $e.currentTarget as $e.target might change depending on: your clip and how many children it holds, position of the click and event phase.
Try
private function _barClicked($e:MouseEvent):void {
trace($e.currentTarget.mouseX);
}
Hope it helps!
I was having the same problem, and Kevin Condon solution from the comment above helped my problem. I am just posting it here, because I almost missed it in the comment.
private function _barClicked($e:MouseEvent):void {
var coord:Point = $e.currentTarget.globalToLocal(new Point($e.stageX, $e.stageY));
trace(coord.x);
}
Thanks Kevin.
Just wanted to note a variation on this problem for those for whom the above is not working.
I was having the same issue - localX showing odd values. Mine weren't random, just far lower than what I expected. I.e., click on the far right of the sprite and get only 17.2, event though the width was reporting as 160.
What I found was that my instance was a scaled version of a symbol who's native width was much less.
Once I set it up so that the symbol and the instance had the same width, I started getting the right values.
Hope this helps someone.
If found that as long as I use the solution that Kevin Condon proposed differences in scaling between different symbols are taken into account and everything works out fine.

Open info window if user hovers longer than x milliseconds

What I'm trying to do is very simple:
open the marker's info window only if the user has hovered on the marker for longer than x millisecond.
I can't find how to do this anywhere. I would appreciate a little code snippet to show me how to set this up!
The jQuery HoverIntent plugin might be able to help you
http://cherne.net/brian/resources/jquery.hoverIntent.html
hoverIntent is a plug-in that attempts to determine the user's intent... like a crystal ball, only with mouse movement! It works like (and was derived from) jQuery's built-in hover. However, instead of immediately calling the onMouseOver function, it waits until the user's mouse slows down enough before making the call.
Actually I finally found the solution to it on the Google Maps Group here: http://groups.google.com/group/google-maps-api/browse_thread/thread/73cf193d42a0bbfe/fa531a39b353d198?lnk=gst&q=open+hover#fa531a39b353d198
Best of luck to all the late night coders out there :)