how do you tell a single mouse click from a double click? my single
click listener seems to be trapping all the double clicks as well:
tz locator
it's a known issue for the flash/flex API but the js workaround doesn't seem to handle both either: code.google.com
Might need a bit of clarification, but make sure you are using the Google Map's MapMouseEvent, not the Flash API's click events (please assume this code in inside a Map subclass):
public class GoogleMap extends Map
{
import com.google.maps.LatLng;
import com.google.maps.Map;
import com.google.maps.MapEvent;
import com.google.maps.MapMouseEvent;
public function GoogleMap():void
{
super();
this.key = "YOUR_API_KEY";
addEventListener(MapEvent.MAP_READY, _onMapReady);
addEventListener(MapMouseEvent.CLICK, _onMapClick);
addEventListener(MapMouseEvent.DOUBLE_CLICK, _onMapDoubleClick);
}
protected function _onMapClick(event:MapMouseEvent):void
{
trace("single!");
var mousePoint:Point = new Point(mouseX, mouseY);
var mousePointLocal:Point = globalToLocal(mousePoint);
var mouseLatLng:LatLng = this.fromViewportToLatLng(mousePointLocal);
}
protected function _onMapDoubleClick(event:MapMouseEvent):void
{
trace("double!");
}
protected function _onMapReady(event:MapEvent):void
{
trace("ready!")
}
}
Related
im a newbie in flex. Im have a question :)
I have
[Bindable]
private var model:AlgorithmModel = new AlgorithmModel();
private var serviceProxy:Algorithm = new Algorithm( model );
In MXML
private function Show():void
{
// now model.Solve_SendResult = null
while(i<model.Solve_SendResult.length) //
{
Draw(); //draw cube
}
}
private function Solve_Click():void
{
//request is a array
Request[0] = 2;
Request[1] = 2;
Request[2] = 3;
serviceProxy.Solve_Send(request);
Show();
}
<s:Button x="386" y="477" label="Solve" click="Solve_Click();"/>
And when i call serviceProxy.Solve_Send(request); with request is array and i want use model.Solve_SendResult in my code flex to draw many cubes use papervison3d but in the first time i received model.Solve_SendResult = null . But when I click again then everything OK.
Anyone help me? Thanks?
The model.Solve_SendResult object contains a result of the executed serviceProxy.Solve_Send(request) method. The Solve_Send will be executed asynchronously and as a result, at the moment when you fire the show method the Solve_SendResult object may be still null.
As a solution, you can use the following:
Create a custom event
package foo
{
import flash.events.Event;
public class DrawEvent extends Event
{
public static const DATA_CHANGED:String = "dataChanged";
public function DrawEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false)
{
super(type, bubbles, cancelable);
}
}
}
In your Algorithm class define the following:
[Event(name=DrawEvent.DATA_CHANGED, type="foo.DrawEvent")]
public class Algorithm extends EventDispatcher{
//your code
In the Solve_SendHandler method of the Algorithm class add the following
public virtual function Solve_SendHandler(event:ResultEvent):void
{
dispatchEvent(new DrawEvent(DrawEvent.DATA_CHANGED));
//your code
}
In your MXML class create onLoad method and add an event listener to an instance of the Algorithm class as it shown below:
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="onLoad()">
public function onLoad():void
{
serviceProxy.addEventListener(DrawEvent.DATA_CHANGED, onDataChanged);
}
private function onDataChanged(event:DrawEvent):void{
while(i<model.Solve_SendResult.length) //
{
Draw(); //draw cube
}
}
make the following changes in the Solve_Click() method:
private function Solve_Click():void
{
//request is a array
Request[0] = 2;
Request[1] = 2;
Request[2] = 3;
serviceProxy.Solve_Send(request);
}
That is it! So, basically the code above do the following: you added a listener to your service (algorithm class), and the listener is listening for the DrawEvent.DATA_CHANGED event. The DrawEvent.DATA_CHANGED will be dispatched when your client receive a result of the Solve_Send invocation. Thus, the onDataChanged will draw your cube or do whatever you want :)
The approach above is basic and you have to know how events work in flex and how you can deal with it. Additional information is available here:
http://livedocs.adobe.com/flex/3/html/help.html?content=createevents_3.html
http://livedocs.adobe.com/flex/3/html/help.html?content=events_07.html
Regards,
Cyril
Is there any workaround to create submenu in a flex context menu other than stopping right click from javascript.
Regards,
Hi Frank,
Yes, I want to create submenus in a context menu. Can you help me here.
Regards,
Hi Frank,
I need the context menu for the application not for datagrid.
In my initial question the phrase "other than stopping right click from javascript" means
"catch the right click in html, call a javascript function and over js call a as function."
The project that you have specified does the above procedure. I don't want to use this
procedure. Is there any other way for achieving submenus in a flex context menu. Could you
please tell me if so..
Regards,
Arvind
Yes, there is.
I don't know, what you exactly mean with this:
other than stopping right click from
javascript.
But, if you want to create a entry in submenu, do this:
//Instance of my own class
private var myContext:myContextMenu = new myContextMenu();
application.contextMenu = myContext.myContextMenu;
//Here is the Class:
package com.my.components
{
/* ////////////////////////////////////////////
///// My Context MenĂ¼ /////////////////////
///////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
//to use: //
// private var myContext:MyContextMenu = new MyContextMenu(); //
// init() in creationComplete //
// application.contextMenu = myContext.myContextMenu; //
////////////////////////////////////////////////////////////////////////////// */
import flash.display.Sprite;
import flash.events.ContextMenuEvent;
import flash.net.URLRequest;
import flash.net.navigateToURL;
import flash.text.TextField;
import flash.ui.ContextMenu;
import flash.ui.ContextMenuBuiltInItems;
import flash.ui.ContextMenuItem;
public class MyContextMenu extends Sprite
{
public var myContextMenu:ContextMenu;
private var menuLabel:String = String.fromCharCode(169)+" My Company GmbH";
public function MyContextMenu()
{
myContextMenu = new ContextMenu;
removeDefaultItems();
addCustomItems();
myContextMenu.addEventListener(ContextMenuEvent.MENU_SELECT, menuSelectHandler);
super();
}
private function removeDefaultItems():void
{
myContextMenu.hideBuiltInItems();
var defaultItems:ContextMenuBuiltInItems = myContextMenu.builtInItems;
defaultItems.print = true;
}
private function addCustomItems():void
{
var item:ContextMenuItem = new ContextMenuItem(menuLabel);
myContextMenu.customItems.push(item);
item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,menuItemSelectHandler);
}
private function menuSelectHandler(event:ContextMenuEvent):void
{
}
private function menuItemSelectHandler(event:ContextMenuEvent):void
{
navigateToURL(new URLRequest('http://www.my-company.de'));
}
private function createLabel():TextField
{
var txtField:TextField = new TextField();
//txtField.text = textLabel;
txtField.text = "RightClickHere";
return txtField;
}
}
}
Have fun
EDIT:
There is an interesting project here. They catch the right click in html, call a javascript function and over js call a as function.
Unfortunately, the limitation of FP or NativeMenu APi allowed just on level contextmenu. Read here
Frank
Is there a way to do it in Flex to say:
if mouseClick x<300&y<200 currentState='';
Thanks,
Many objects dispatch a click event; and in that click event properties you can access the x and y position using stageX and stageY properties.
http://livedocs.adobe.com/flex/3/langref/flash/events/MouseEvent.html
However, I do not think it is possible to listen for a click event at a specific location without their being a UI Element at that spot.
I also question whether hard coding the x and y position for such a state change is a good idea; as different machines and different screen sizes and resolutions may size your content differently.
You can add a listener to the stage to capture all clicks:
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
[SWF(width='500', height='300', backgroundColor='#ffffff', frameRate='30')]
public class ClickTest extends Sprite
{
public function ClickTest()
{
addEventListener(Event.ADDED_TO_STAGE, addedToStage);
}
private function addedToStage(event:Event):void
{
stage.addEventListener(MouseEvent.CLICK, handleClick);
}
private function handleClick(event:MouseEvent):void
{
if((stage.mouseX < 300) && (stage.mouseY < 200)
{
trace("CLICKED WHERE I WANT");
}
}
}
}
This seems to work even when Sprites are placed on top of the interface.
I would like to track the customer experience in downloading and initializing my flex app.
(a) Is there a way to pass data from preloader to the application? I would like to pass the time it takes to download and the time it takes to initialize.
(b)Alternatively:
Is there an event at the application level that corresponds to the preloader events:
1. Download complete
2. Initialization complete (same as Application creationComplete)
The "Showing the download progress of an application" article in the livedocs should help.
Based on that documentation, I would do something like this:
create a simple subclass of the DownloadProgressBar,
override the event listeners to track the amount of time that has elapsed during download/initialisation,
store the time values as static properties so you can access them from your Application once it's completed initialisation.
Here is an example of what I'm thinking (I've not compiled this code, it's more to give an idea of what I'm talking about).
package
{
public class TimedProgressBar extends mx.preloaders.DownloadProgressBar
{
public static var startTime:Number = 0;
public static var downloadCompleteTime:Number = 0;
public static var RSLCompleteTime:Number = 0;
public function TimedProgressBar()
{
super();
startTime = getTimer();
}
override protected function completeHandler(event:Event):void
{
super();
downloadCompleteTime = getTimer();
}
override protected function rslCompleteHandler(event:RSLEvent):void
{
super();
RSLCompleteTime = getTimer();
}
}
}
Set that as your preloader in your Application.mxml and listen for the APPLICATION_COMPLETE event:
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
preloader="TimedProgressBar"
applicationComplete="applicationCompleteHandler(event)">
private function applicationCompleteHandler(event:FlexEvent):void
{
var completeTime:Number = getTimer();
var downloadTime:Number = TimedProgressBar.downloadCompleteTime - TimedProgressBar.startTime;
var rslDownloadTime:Number = TimedProgressBar.RSLCompleteTime - TimedProgressBar.downloadCompleteTime;
var totalInitTime:Number = completeTime - TimedProgressBar.startTime;
// Do whatever logging you want with this information.
}
I want to add a simple piece of text to the stage and add a listener to do something when the user clicks it.
Here's my TextLink class:
package some.package
{
import flash.display.Sprite;
import flash.external.ExternalInterface;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
public class TextLink extends Sprite
{
public var tf:TextField = new TextField();
public var bspr:Sprite = new Sprite();
public function TextLink(tx:int, ty:int, tft:String):void
{
tf.text = tft;
tf.x = tx;
tf.y = ty;
tf.autoSize = TextFieldAutoSize.LEFT;
bspr.addChild(tf);
this.addChild(tf);
}
}
}
And here is the way I am calling it, along with the listener:
public function test_array_of_objects():void
{
var tmp:TextLink = new TextLink(30, 30, "some text");
tmp.addEventListener(MouseEvent.CLICK, roverNotify);
addChild(tmp);
}
protected function roverNotify(e:Event):void
{
ExternalInterface.call("console.log", "got a click");
}
...But I don't get a message for some reason.
I've imported everything successfully. Any thoughts on what else I can try?
Is your TextLink class an event dispatcher? You're trying to add a listener to the TextLink object, but the click listener needs to be attached to the text field that you're using inside TextLink. TextLink needs to be a DisplayObject of some kind to inherit the dispatching capabilities.
Also, constructors should not specify a return type (since they're just returning themselves) -- the :void should not be there where your TextLink constructor is.
Does function TextLink require something like this at the beginning:
var tf:Text = new Text();
Is the problem with clicking the Sprite or getting the event to fire? If it's the former you could try adding the code below.
tmp.mouseChildren = false;
tmp.buttonMode = true;
ExternalInterface.call("console.log", "got a click");
You have a JavaScript function defined like this??:
function console.log(inputString) {
//do something
}
Edit: Nevermind the above, forgot about Firebug.
Also, TextLink doesn't need to be an event dispatcher, though you may want to have TextLink set its mouseChildren property to false (unless you need to be able to select that text), so that you don't inadvertently trigger events on the TextField, and buttonMode to true.
Edit: Also, what's the point of?:
var bspr:Sprite = new Sprite();
bspr.addChild(tf);
Final edit
How about this? http://code.google.com/p/fbug/issues/detail?id=1494
Yes, you are correct, in FF3 the console is injected only when the page has
javascript and uses window.console.
If you put any js that accesses the console before the Flash loads it should work, eg
<script>
var triggerFirebugConsole = window.console;
</script>
Let us know if this works. It's unlikely that we can fix this soon.