View Full Version : Event handler for a line in flex 2??
arun vallappan
08-02-2007, 10:27 PM
hello,
can anyone tell me how to set an event handler for a line?
like.. on mousemove event for this line, i need to show a tooltip,
someone help plss...
regards,
arun vallappan
drkstr
08-03-2007, 01:48 AM
What do you mean by a line? Do you mean a line of text, or a line as in:
f(x) = 3
If the later is the case, just check the coords on mouseMoved and display your tool tip if it's on the line.
Regards,
...aaron
*edit*
Or if you line is an actualy display object, you can grab a mouseOver or mouseOut event on it.
arun vallappan
08-03-2007, 10:02 AM
sorry for the ambiguity,
by line i meant the graphics line,
the line which i draw is embedded in the drawing surface.
in the following code i draw a line from (fromX,fromY) to (toX,toY).
now when i move the mouse over this line,i want the tooltip to be shown.
mydrawingSurface.graphics.moveTo(fromX, fromY);
mydrawingSurface.graphics.lineTo(toX, toY);
u see a way?
regards,
arun vallappan
dr_zeus
08-03-2007, 06:59 PM
You need to add the event handler to "mydrawingSurface". If that won't work because you have drawn additional graphics in "mydrawingSurface", then you will need to put each line in its own display object (flash.display.Shape is probably a good one).
arun vallappan
08-04-2007, 09:59 PM
hi Josh ,
Thnx a lot for giving me some hope.
i used shape object.but am not able to set a event listener(mouse over or click)
for that.is it possible to do that?
or i read about sprite object.
i donno how to use it.
if u r free.can u send a small example?
just a graphic with a event..plssss..
regards
arun vallappan
arun vallappan
08-05-2007, 10:02 PM
Hi josh,
i tried to execute this one,
var mySprite:Sprite = new Sprite();
mySprite.graphics.beginFill(0xFFCC00);
mySprite.graphics.drawCircle(30, 30, 30);
var label:TextField = new TextField();
label.text = "hello";
label.x = 20;
label.y = 20;
mySprite.addChild(label);
this.addChild(mySprite);
it shows an error saying that,
it cant attach sprite object to a UI Component.
to which container do we attach a sprite object?
can u help me?
Arun vallappan
kifah
08-06-2007, 09:08 AM
Even in flex 2 if you write in actionscript you can use
stage.addChild(mySprite);
that's flex 2 use UIComponent Superclass for Application
in time actionscript 3.0 use Sprit Superclass for stage
arun vallappan
08-06-2007, 10:31 AM
i tried to use the following code(in flex 2)
var mystage:Stage=Stage(Application.application);
var mySprite:Sprite = new Sprite();
mySprite.graphics.beginFill(0xFFCC00);
mySprite.graphics.drawCircle(30, 30, 30);
mystage.addChild(mySprite);
but it shows an error saying, "Cannot access a property or method of a null object reference".
if am missing something silly here,please help me out.
Thanks..
Arun vallappan
kifah
08-06-2007, 01:00 PM
try this
//var mystage:Stage=Stage(Application.application);
var mySprite:Sprite = new Sprite();
mySprite.graphics.beginFill(0xFFCC00);
mySprite.graphics.drawCircle(30, 30, 30);
stage.addChild(mySprite);
then tell me if that's ok
arun vallappan
08-06-2007, 02:40 PM
nope .
"Cannot access a property or method of a null object reference".
ny other way?
kifah
08-06-2007, 03:48 PM
Dear arun vallappan
I suggest to attach your whole project to discover where is the problem is
because I test the code I posted before and it works clearly ..
regard
drkstr
08-06-2007, 06:43 PM
What do you mean by you tried the code in Flex 2? When most people say this, it means they put the code in the wrong place. What function did you put that code in, and as the result of which event? Are you drawing on a canvas? Why are you using sprites in a Flex app (is there a specific reason, or can you do it with a canvas easier)?
Anserwing these questions should get us a bit closer to the problem.
Regards,
...aaron
arun vallappan
08-06-2007, 08:07 PM
This is the code which i tried to execute..
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
creationComplete="init()">
<mx:Script>
<![CDATA[
import mx.core.UIComponent;
import mx.containers.Canvas;
import mx.controls.Alert;
import flash.display.*;
public function init():void {
var mySprite:Sprite = new Sprite();
mySprite.graphics.beginFill(0xFFCC00);
mySprite.graphics.drawCircle(30, 30, 30);
stage.addChild(mySprite);
}
]]>
</mx:Script>
</mx:Application>
am new to display object programming.so,the error might be silly.
and basically what i want is a line or a curve with mouse event listener property.
am working on a network visualization graph(using springgraph),
in which i need to show nodes and edges connecting them.
similar to the network shown in this link
http://der-mo.net/relationBrowser/
the edges in this network has a tooltip property.apart from that,i also want to change
the intensity of an edge or delete an edge by clicking on it.
thanx,
Arun vallappan
dr_zeus
08-06-2007, 09:08 PM
You probably shouldn't be placing your Sprites directly on the stage. Things should go into the Application object itself or any of its descendants. However, it's important to note that the Flex Application class is a subclass of Container. Container can only contain UIComponents (no Sprites!). You should create a custom UIComponent, called something like DrawingArea, and you can draw your Sprites inside that.
kifah
08-07-2007, 05:00 PM
Dear arun vallappan:
As I said before in Flex 2.0 there are two main projects:
1-Actionscript 3.0 project which you can use Sprite objects into.
2-Flex project project which you must use UIComponent instead of Sprite.
here is the right code for flex project ..
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
<mx:Script>
<![CDATA[
import mx.core.UIComponent;
import flash.display.*;
public function init():void
{
var display:UIComponent=new UIComponent();
display.graphics.beginFill(0xFFCC00);
display.graphics.drawCircle(30,30,30);
addChild(display);
}
]]>
</mx:Script>
</mx:Application>
best regards ..
arun vallappan
08-08-2007, 11:22 AM
:) its working ..
thanx a bunch.
have u worked in springgraph component(by mark shepherd)??
http://mark-shepherd.com/blog/springgraph-flex-component/
bcoz,am tryin to extend it and got stuck at a point.
regards,
Arun vallappan
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.