Enable rightMouseUp event for Flex Spark Application container - actionscript-3

The spark Application container in Flex purportedly listens to the rightMouseUp and other right mouse button events. However, if press and release the right mouse button in the Flash player I only get the context menu.
How can I disable the context menu and make the application listen to right mouse button events instead?
Minimal example:
<?xml version="1.0"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
mouseUp="onMouseUp(event)"
rightMouseUp="onRightMouseUp(event)"
>
<fx:Script>
<![CDATA[
import mx.controls.Alert;
private function onMouseUp(e:MouseEvent):void {
Alert.show('left mouse up');
}
private function onRightMouseUp(e:MouseEvent):void {
Alert.show('right mouse up');
}
]]>
</fx:Script>
</s:Application>

You should add higher vesrion of swf. like: -swf-version=20 in flex compiler in additional compiler arguments.
Here is the list of swf version with flash player version.
SWF Version
Hope it helps.

Related

Sorting List without propagating event for resetting scrollbar

I have a spark List and using ArrayCollection as dataprovider for list. Initially when the list is populated sorting is done , but i need to add items to list quite frequently as they update on server. After i add item i have to re-sort the list. After applying sort and calling refresh() scrollbar resets itself to top.
I am looking for a way so that i can add items to list and keep sorting the list without resetting the scrollbar to top position.
I have read similar question earlier but in that question most users have said to store the VerticalScrollPostion in a variable and apply that VerticalScrollPosition back after the sorting is done. The problem with this is there is a jerk in scrollbar , as it goes to top after refresh and then scrolls back to position as applied. So this solution is not possible as items are added very frequently as it will make the scrollbar going up and down very frequently and annoying the users. Also does't look nice n professional
I need a way so that scrollbar stays in it place even after sorting is done.
Also i want to keep using useVirtualLayout=true for the List.
I was also trying to extent ArrayCollection but could't find a way to solve my problem.
Below is simple example(extracted from my main application) to illustrate the problem. Just Scroll to bottom of list and then press the Sort button(which will sort the list) and the scrollbar will jump to top position. I want scrollbar to stay at its position even after pressing Sort button:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="application1_creationCompleteHandler(event)">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.collections.SortField;
import spark.collections.Sort;
[Bindable] protected var ar_c:ArrayCollection;
protected var dgArray:Array=new Array();
protected function application1_creationCompleteHandler(event:FlexEvent):void
{
for(var i:int=0;i<20;i++)
dgArray.splice(-1,0,{label:"h"+i});
ar_c= new ArrayCollection(dgArray);
}
protected function sort_list():void{
var sort:spark.collections.Sort=new Sort();
sort.fields=[new SortField("label",false,true)];
ar_c.sort=sort;
ar_c.refresh();
}
]]>
</fx:Script>
<s:List x="42" y="41" id="mylist" width="199" height="253" dataProvider="{ar_c}" useVirtualLayout="true"></s:List>
<s:Button x="295" y="40" label="Sort" click="sort_list();"/>
</s:Application>
I think a sort is applied once and then everything added to the ArrayCollection later on is sorted on. You only have to add the sort once, and then call refresh once to apply the sort.

Flex Vertically Aligned Text Mac vs Windows

I am looking into an issue in a Flex application where on OS X text is shifted up a couple pixels compared to windows. Every text field is not vertically aligned to the middle it is more towards the top.
Found a thread here but no real solution http://forums.adobe.com/message/2189821
Anyone know how to solve this problem in a way that applies to both systems.
My approach would be to conditionally adjust component positioning when OS X is detected.
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
preinitialize="onPreinitialize()"
>
<fx:Script>
<![CDATA[
import mx.controls.Alert;
private function onPreinitialize():void
{
Alert.show((-1 != Capabilities.os.search(new RegExp('mac', 'i'))) ? 'Replace this Alert with code which adjusts text positioning in order for it to appear the same as when it runs on Windows.' : 'No need to adjust text', Capabilities.os);
}
]]>
</fx:Script>
</s:Application>

Flex 3 - Calling a function within a popup component every time it is opened

This will be a really easy one for someone i'm sure. I just need to know the event that will allow me to call a funciton every time the pop up window is opened.
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" width="400"
height="120" title="Change Offer/Event Name" showCloseButton="true" close="PopUpManager.removePopUp(this)"
horizontalScrollPolicy="off" verticalScrollPolicy="off" creationComplete="init()">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.CloseEvent;
import mx.managers.PopUpManager;
private function init():void{
txtNewName.text = parentApplication.cmbOfferName.selectedItem.TEMPLATENAME;
}
]]>
</mx:Script>
<mx:Canvas width="374" height="74" horizontalScrollPolicy="off" verticalScrollPolicy="off">
<mx:TextInput id="txtNewName" x="72" y="16" width="240"/>
<mx:Label x="6" y="18" text="New Name"/>
<mx:Button x="317" y="16" label="Ok" width="47" click="checkName()"/>
</mx:Canvas>
I have the init() function called in creationComplete which will bring in the value the first time the window is opened but I need it to call the function every time the popup is opened. I have tried, activate, creationComplete, addedToStage, which all dont work.
Oh just to note as well, I cant just set the text input's text property to be bindable to the combobox as I will potentially be selecting from multiple comboboxes depending on what canvas i am viewing.
Thanks in Advance
I managed to solve it myself. I did in fact use 'addedToStage' in the TitleWindow Component. The only problem with using addedToStage is that I was trying to populate a textinput in the popup window so this had not been rendered yet. To get round this I simply added a bindable variable which I added the selected combobox value to and added the variable as the dataprovider for the text field on the textInput.

AmChart component is not rendering (AIR app)

Our AIR app consists from multiple modules. Each module extends MovieClip class. But when I am adding AmChart component to one of these modules, it is not rendering. Here the sample (PieChart.mxml):
<?xml version="1.0" encoding="utf-8"?>
<s:SkinnableContainer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:amcharts="http://www.amcharts.com/com_internal"
width="100%" height="100%">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
private var chartData:ArrayCollection = new ArrayCollection([
{country:"Czech Republic",litres:156.90},
{country:"Ireland",litres:131.10},
{country:"Germany",litres:115.80},
{country:"Australia",litres:109.90},
{country:"Austria",litres:108.30},
{country:"UK",litres:99.00},
{country:"Belgium",litres:93.00}]);
]]>
</fx:Script>
<amcharts:AmPieChart width="100%" height="100%" dataProvider="{chartData}" titleField="country" valueField="litres"/>
</s:SkinnableContainer>
And this is a sample usage:
var chart:PieChart = new PieChart();
cContainer.addChild(chart);
cContainer - is instance of MovieClip.
Can you suggest why this is not rendering? Maybe this seems a silly question, but I am a quite newbie to Flex. Please, help.
You may want to try using the dataset syntax used here http://blog.amcharts.com/2010/11/amstock-flex-tutorial-part-1-basics.html, and also try using a number for width and height until you get it working, rather than a percentage. If neither of those works, you may want to try asking the people who wrote this.
HTH;
Amy

A quick way to know the source of scroll bar?

Whenever I use a lot of nesting inside mxml components(including many states) with quite a few Vboxs and Other containers, I always get confused when I see a scrollbar appearing on screen, especially with datagrid inside it(I always want to show scroll bar in datagrid and not on the parent container, for which I usually set the height and width of datagrid smaller than its parent container at run time).
My question is, how could I possibly know (QUICKLY), using debugger, that which component is the source of scroll bar that I see on screen (if there are more than one, then some propoerty of compnent must change when I scroll it up or down).
Thanks.
I realise that this answer isn't using the debugger directly. I mean it as an idea for a simple tool really.
I had a quick go at putting together a simple app that's function is to report what display object is dispatching a mouse wheel event. It does not matter to the app if there is a scrollbar or not, but I guess you could adjust it to your needs. Its a quick start really, here's the code...
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" minWidth="955" minHeight="600"
creationComplete="init()">
<mx:HBox id="HBoxWithScrollbar" width="600" height="500">
<mx:HBox width="800" height="800">
</mx:HBox>
</mx:HBox>
<mx:TextArea id="record" height="300" width="600"/>
<mx:Script>
<![CDATA[
private function init():void{
record.text = 'Scroll Record\n';
this.addEventListener(MouseEvent.MOUSE_WHEEL, recordObject);
for each (var obj:DisplayObject in this.getChildren()){
obj.addEventListener(MouseEvent.MOUSE_WHEEL, recordObject);
}
}
protected function recordObject(event:MouseEvent):void{
record.text += (event.target as DisplayObject).toString() + '\n';
}
]]>
</mx:Script>
</mx:Application>
The important thing here really is to see that you can pick up the mouse wheel event at the top level, because it bubbles by default, and isn't cancelable.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/InteractiveObject.html#event:mouseWheel
Once you've got hold of that event, you've got options.
This was built using version 3.6 of the Flex SDK, but it wouldn't take much to build a 4.x version. I am simply displaying "toString()" value of the target display object, but that could be any attribute you want. You'll probably want to put in some error handling for the loop adding events, and also in the event handler. As I said, its just a start, and I hope it helps.