views:

342

answers:

1

Hi,

I want to insert a bezier spline into my Canvas by this code

<mx:Canvas 
id="graphCanvas" 
width="100%" 
height="100%" 
preinitialize="preInit()"
/>
<BezierSpline id="mySpline" graphicsTarget="{[graphCanvas]}"  data="points"

verticalCenter="0" horizontalCenter="0" >

points is a string I initialize in the preInit() method

[Bindable]public var points : String;
private function preInit() : void {
  points = "200,100 200,300 100,300 300,500 500,300 400,300 400,100";
 }

But when I now build the project no spline is drawn on my canvas whereas directly integrating the data in the mxml works

<BezierSpline id="mySpline" graphicsTarget="{[graphCanvas]}"  data="200,100 200,300 100,300 300,500 500,300 400,300 400,100"

verticalCenter="0" horizontalCenter="0" >

Can someone help me? I need to dynamically change the data of the spline. Also answers that handle it programmatically are welcome as I do not really know how to redraw the spline on my canvas by code (don't know how to use the draw() method of the spline).

Thanks in advance

Sebastian

+1  A: 

This code works for me:

[Bindable]
private var points:String;
private function preinit ():void
{
    points = "200,100 200,300 100,300 300,500 500,300 400,300 400,100";
}

<degrafa:BezierSpline id="mySpline" graphicsTarget="{[graphCanvas]}" data="{points}">
    <degrafa:stroke>
        <degrafa:SolidStroke weight="2" color="#0000FF"/>
    </degrafa:stroke>
</degrafa:BezierSpline>
Hrundik
hmm ok but as I did that change, still nothing happens when I set the points string in my init method, no spline is drawn on my canvas. The points variable is bindable and setting the points variable in the preinitialize process also doesn't has an effect. More ideas? Can I programmatically evoke a repaint of the spline?
Xelluloid
I've included the whole example in my answer. It works OK for me. Actually, I'm sure degrafa should start redrawing automatically, you can try using `draw(graphics:Graphics, rc:Rectangle)` method to repaint programmatically.
Hrundik
ah ok you are right, it works finde, but now when i change the value of points to "200,200 100,100 300,300" for example error 1009 occurs Cannot access a property or method of a null object referenceat com.degrafa.geometry.splines::BezierSpline/_assignControlPoints()[C:\Inetpub\wwwroot\Degrafa_Google_Dev\com\degrafa\geometry\splines\BezierSpline.as:586] at com.degrafa.geometry.splines::BezierSpline/preDraw()[C:\Inetpub\wwwroot\Degrafa_Google_Dev\com\degrafa\geometry\splines\BezierSpline.as:401] at com.degrafa.geometry.splines::BezierSpline/draw() and so on, you know what to do here?
Xelluloid
Actually, I'm not that familiar with Degrafa. I would suggest using .points property of BezierSpline object instead of .data. It may help, or may not help.As a last resort, you may try removing the old spline from display list and creating the new one each time you need to do redrawing
Hrundik
do you have any idea how I use the draw method? what Graphics object is meant and what Rectangle? Or how I insert points ... There are a lot of point classes.
Xelluloid
ok I just made a workaround and implemented a custom component with the spline, this works fine for now but I hope I will find a better solution later, nevertheless I will mark this post answered and thanks for your help.
Xelluloid