Flex PlotChart zoom error in findDataPoints() - apache-flex

I came across this great tutorial on how to zoom into a chart by drawing a rectangle in a LineChart to zoom into it (http://blog.ninjacaptain.com/2010/03/flex-chart-zoom-window/) but i'm trying to apply it to a PlotChart instead and i'm having issues trying to get the DataTips showing with the following error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at mx.charts.series::PlotSeries/findDataPoints()[E:\dev\4.5.1\frameworks\projects\charts\src\mx\charts\series\PlotSeries.as:961]
at mx.charts.chartClasses::ChartBase/findDataPoints()[E:\dev\4.5.1\frameworks\projects\charts\src\mx\charts\chartClasses\ChartBase.as:2069]
at mx.charts.chartClasses::ChartBase/mouseClickHandler()[E:\dev\4.5.1\frameworks\projects\charts\src\mx\charts\chartClasses\ChartBase.as:4823]
The link mentioned about extending the LineChartSeries and override the findDataPoints() function, but after trying to doing the same for extending PlotSeries.as, sortOnXField seems to be undefined and I don't have access to the PlotSeries.as since it is in a swc.
Has anyone tried applying the following to a PlotChart instead and got the DataTips to show? What was the override function in the findDataPoints()?
Thanks

Some days ago I had the same problem with PieSeries.
I have not found yet why '_renderData.filteredCache' is null in 'filterDataPoints' function, but meanwhile I have resolved the problem extending PieSeries Class this way:
package com.eque.report.model {
import mx.charts.series.PieSeries;
public class MyPieSeries extends PieSeries {
public function MyPieSeries () {
super();
}
/**
* 'findDataPoints' function has been overriden in order to prevent
* '_renderData.filteredCache' is null.
*/
override public function findDataPoints(x:Number, y:Number, sensitivity:Number):Array {
if (renderData.filteredCache == null) {
renderData.filteredCache = [];
}
return super.findDataPoints(x, y, sensitivity);
}
}
}
I hope it could help you

If you're asking about how to solve the "filterDataPoints" issue in accessing chart points, you just have to create you own Series class, copy-paste the code from PlotSeries in it and change whatever fails on runtime. What kind of error do you get ?

Related

JavaFX - Extends Stage, but inherited method is undefined

I'm working with JavaFX using Java 8 and I have a class where Stage is extended. I got this code from another student and it works fine for everyone else, but for me I get an error on setAlwaysOnTop. It says the method is undefined, but it is inherited from Stage. It seems to be only that method which is giving this error.
It would be easier with an image, but I can't post images yet so I had to just copy-paste the relevant code:
public class NotificationWindow extends Stage {
public void showNotification(){
Rectangle2D screenBounds=Screen.getPrimary().getVisualBounds();
this.setAlwaysOnTop(true); //Error here
this.setX(screenBounds.getMaxX()-scene.getWidth());
this.setY(screenBounds.getMaxY()-scene.getHeight());
this.show();
}
}
The alwaysOnTop property was introduced in JavaFX 8 update 20. So you are probably using an earlier version. Update to the latest JavaFX version and it should recognize the method.

Flex List Scroll Speed With Mouse Wheel

I have a custom class that extends List which I am using as a container. However, the scroll speed is too fast on the mouse wheel, as in it scrolls loads even if you only move the wheel a tiny bit. I tried adding an event listener to my list for MouseEvent.MOUSE_WHEEL and setting the value of event.delta but this has had no effect. Does anyone know how I can make it slower?
My custom class is nothing special, I just created it so I could have a different itemRenders for different item types. It looks like:
public class MultipleRenderersList extends List
{
override public function createItemRenderer(data:Object):IListItemRenderer
{
if (data is IRenderable)
{
return data.getDiaryRenderer();
}
else if (data is Array)
{
if (data.length > 0)
{
if (data[0] is IRenderable)
{
return data[0].getDiaryRenderer(data);
}
}
}
return null;
}
}
The List class has a mouseWheelHandler function that you can override. Just override the function, update the delta property of the mouseevent, and call super. This example will quarter the delta, reducing the speed substantially:
package
{
import flash.events.Event;
import flash.events.MouseEvent;
import mx.controls.Alert;
import mx.controls.List;
public class MyList extends List
{
override protected function mouseWheelHandler(event:MouseEvent):void {
event.delta = event.delta/4;
super.mouseWheelHandler(event);
}
}
}
However, in many cases the scroll speed / delta will be driven off of a system preference, so doing this may cause unexpected behavior for some users. The reason that adding the handler and updating the delta failed to work is that by that point mouseWheelHandler had already been called.
A very simple way to modify this is to change the verticalLineScrollSize property. This is a property of all containers and it defaults to 5. (for flex 3)
Actually, what HandOfCode said isn't relevant here. Because he made the same mistake as i did, which is to think that a List component or TileList component are containers. They aren't. So, they don't have verticalLineScrollSize property.
Sean solution is the only one that worked for my case. I would add that event.delta may have a positive or negative value depending of the direction of the wheel action. So you better do something like this if you plan to scroll, for example one line at a time :
override protected function mouseWheelHandler(event:MouseEvent):void
{
event.delta = (event.delta > 0) ? 1:-1;
super.mouseWheelHandler(event);
}

Make File.nativePath bindable? or how to extend flash.filesystem.file

I would ultimately like to make .nativePath bindable or fire an event when it changes in Adobe Air. I figured I'd just extend the File class and be good.
But I cant find its source anywhere (so I know how to extend it). I've dug through http://opensource.adobe.com/svn/opensource/flex/sdk/ quite a bit and didnt see anything.
Is there a way to make .nativePath bindable or extend File?
alxx, your code was definitely close. Thank you - it gave me an idea on how to extend it. Working code:
public class FileEx extends File
{
public function FileEx(path:String=null)
{
super(path);
}
[Bindable("nativePathChanged")]
override public function get nativePath():String
{
return super.nativePath;
}
override public function set nativePath(value:String):void
{
super.nativePath=value;
dispatchEvent(new Event("nativePathChanged"));
}
}
The File Class is part of the Flash package, so it is not open source and you won't be able to get your hands on the code (unless you're deep in the inner circle of Adobe developers).
In theory you can extend the class, as it is not marked as final, and make the nativePath Bindable that way, but I'm not sure of the benefit. You'd have to expand on your use case to evaluate that.
You don't need source to subclass something. As long as it's not final, just extend it and override something you need:
public class BindableFile extends File {
[Bindable(event="nativePathChanged")]
override public function get nativePath():String {
return super.nativePath;
}
override public function set nativePath(value:String):void {
super.nativePath = value;
dispatchEvent("nativePathChanged");
}
}
Not tested, but looks realistic :)

Can't apply filter to Sprite

I have this simple class:
import spark.effects.GlowFilter;
public class Letter extends Sprite {
private var glowFilter:GlowFilter = new GlowFilter();
public function Letter() {
filters = [glowFilter];
}
}
And in gaves "Error #2005: Parameter 0 - incorrect type. Should be type Filter" in runtime. If I change parent class to UIComponent everything works great. But I do not need all UIComponent functionality, I need just that damn filter works. =)
So, the question is what is the problem? Why it is not working with "Sprite" as parent class?
Using Flex 4.1.
You are trying to apply a flex specific filter to a non flex based object.
Try changing the import to
import flash.filters.GlowFilter;
This will use the standard flash filter instead.

Modules and Panels issue

I have the following problem.
In my application I have several modules and each of them have components CollapsableTitleWindow (extends Panel). After opening the window it is added to the container which is in the main application (CollapsableTitleWindowContainer). In these windows you can open another window (and so on).
Now, what is the problem.
When I change (reload) any module and I want to open a new window (sub window) with the already loaded window I get this error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at mx.containers::Panel/layoutChrome()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\containers\Panel.as:1405]
at com::CollapsableTitleWindow/layoutChrome()[D:\Flex 3 Workspace\WesobCrm\src\com\CollapsableTitleWindow.as:216]
at mx.core::Container/updateDisplayList()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\Container.as:2867] (...)
Indicates that the main applications have object Panel
Please help.
P.S. I found a similar problem on http://www.nabble.com/Flex-Module-issue-with-Panel-td20168053.html
ADDED:
I extendes the Panel class and do something like that:
override protected function layoutChrome(unscaledWidth:Number, unscaledHeight:Number):void
{
use namespace mx_internal;
if(!(mx_internal::titleBarBackground is TitleBackground)) {
mx_internal::titleBarBackground = new TitleBackground();
}
super.layoutChrome(unscaledWidth, unscaledHeight);
}
But now i had something like that:
Before
(source: ak.bx.pl)
After
(source: ak.bx.pl)
You can see that it loos style declaration.
I found a solution but it is bad pratice:
I add in my main application
public function getProductWindow():ProductWindow {
return new ProductWindow();
}
And change in the module:
From
var productWindow:ProductWindow = new ProductWindow();
To
var productWindow:ProductWindow = Application.application.getProductWindow();
If anyone have a better solution ?

Resources