Enabling component error 1009 - apache-flex

I want to enable a linkbar component. When I run the application and try to look for data into the linkbar I get error 1009: impossible to acess property or method of a null object reference. How can I enable a component in flex so that to avoid error 1009? Any help would be appreciated...
<mx:LinkBar dataProvider="myViewStack" enabled="true" activate="true"/>
<mx:ViewStack id = "myViewStack" width="624" height="212" enabled="true">
<mx:Canvas id="canvas3" label="Financement" enabled="true" >
<mx:Label x="38" y="10" text="Code Fin."/>
<mx:Label x="19" y="36" text="Fond propre" enabled="true"/>
</mx:Canvas>
</mx:ViewStack>

Check if "myViewStack" is initialized or not

<mx:LinkBar dataProvider="{myViewStack}" enabled="true"/>

Related

error 1009: cannot access method of a null object reference

I am doing a flex blazedDS project via spring and hibernate. I have error 1009 "cannot access property or method of a null object reference" when I switch between canvases of a view stack.
How can I avoid this error any help would be appreciated.
<mx:VBox height="244.55" y="219.45" width="624.01514" x="10">
<mx:LinkBar dataProvider="{myViewStack}" enabled="true" activate="true"/>
<mx:ViewStack id = "myViewStack" width="624" height="212" enabled="true">
<mx:Canvas id="canvas3" label="Financement" enabled="true" enterState="true" >
<mx:Label x="38" y="10" text="Code Fin."/>
<mx:Label x="19" y="36" text="Fond propre" enabled="true"/>
<mx:TextInput x="119" y="34" id="fondprofin"/>
<mx:TextInput x="119" y="8" id="codefin"/>
<mx:Label x="100" y="10" text="*" width="11" color="#E0391E"/>
</mx:Canvas>
<mx:Canvas id="canvas1" label="Investissement" enabled="true" enterState="true" >
</canvas>

Enable drag and drop between itemrenderers

I have two tilelists in my mxml application. The items (image and a label) get rendered by an itemrenderer. The functionality I want to achieve: drag image from tilelist #1 and drop it on tilelist #2 (and then a httpservice with sql query will be launched).
How would I tackle this problem? (high level info would suffice).
The main issue I have is that I don't know how to call methods from the main to my itemrenderer. I would like to code the d&d functionality within the renderer but I have no clue how to access watchlist #2 from within the renderer.
Relevant code in main.mxml:
<s:Panel id="panel" width="100%" height="100%" title="Watchlist">
<s:layout>
<s:VerticalLayout paddingBottom="5" paddingLeft="20"
paddingRight="20" paddingTop="5"/>
</s:layout>
<s:Label width="20%" fontSize="17" fontWeight="bold" text="Your watched movies"/>
<mx:TileList id="myWatchedList_tile" height="360" borderVisible="false" width="80%"
columnCount="5" columnWidth="200"
itemRenderer="components.TileListItemRenderer" rowCount="1" rowHeight="360"/>
<s:Label width="20%" fontSize="17" fontWeight="bold" text="Your to watch movies"/>
<mx:TileList id="myToWatchList_tile" height="360" borderVisible="false" width="80%"
columnCount="5" columnWidth="200"
itemRenderer="components.TileListItemRenderer" rowCount="1" rowHeight="360" />
</s:Panel>
The itemrenderer:
<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
borderVisible="false" horizontalAlign="center" verticalAlign="middle"
xmlns:components="components.*">
<mx:Image source="{data.poster_url}" />
<mx:Label text="{data.movie_title}" height="20" />
</mx:VBox>
You can access methods outside of your item renderer using the outerDocument object. Make sure they are (scope)public methods.
http://www.adobe.com/devnet/flex/articles/itemrenderers_pt1.edu.html
Alternative solution might be to use spark lists instead (with a TileLayout) - then you can easily use drag+drop between lists: http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-7cfd.html
..and launch service in response to 'drop' event (event will have reference to dropped image)

Flex: Backgroundimage not showing in list

I have a custom component that has an background image.
But when you generate this component by an ItemRenderer in a List, the background image is gone.
What am I doing wrong?
Here is an image. The first element is not generated in a list and has a background image. The other three are part of a List and have no background image.
Here is the code of the MXML of the List
<mx:VBox>
<solutionItems:displaySolutionItem /> <!-- This element shows the background image -->
<mx:List selectable="false"
useRollOver="false"
id="listControllers"
backgroundAlpha="1"
dataProvider="{controllers}" >
<mx:itemRenderer>
<fx:Component>
<solutionItems:displaySolutionItem /> <!-- These elements have nog background image -->
</fx:Component>
</mx:itemRenderer>
</mx:List>
</mx:VBox>
And here is the code of <solutionItems:displaySolutionItem />
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas
xmlns:mx="http://www.adobe.com/2006/mxml"
backgroundImage="{itemBackGround}"
backgroundSize="100%">
<mx:Script>
<![CDATA[
[Bindable]
[Embed(source="assets/Components/ContainerBackgrounds/BoxBg.png", scaleGridLeft="5", scaleGridRight="50", scaleGridTop="5", scaleGridBottom="50")]
private var itemBackGround:Class;
]]>
</mx:Script>
<mx:VBox
paddingBottom="10"
paddingLeft="10"
paddingRight="10"
paddingTop="10">
<mx:CheckBox id="chbControllerItem" label="NSL-4601" styleName="titleRed" />
<mx:HBox>
<mx:Image width="67" height="50" id="loader1" source="#Embed(source='assets/Components/ContainerBackgrounds/BoxBg.png')"/>
<mx:HBox>
<mx:VBox>
<mx:Label text="Cube size" styleName="formLabel" height="12" />
<mx:Label text="Cube config" styleName="formLabel" height="12" />
<mx:Label text="Display res" styleName="formLabel" height="12" />
<mx:Label text="DPI" styleName="formLabel" height="12" />
<mx:Label text="Price" styleName="formLabel" height="12" />
</mx:VBox>
<mx:Box>
<mx:Label text="50''" height="12" />
<mx:Text text="2x3 (1224mm x 3264mm)" height="12" />
<mx:Label text="WXGA (1360x768)" height="12" />
<mx:Label text="72 dpi" height="12" />
<mx:Label text="€ 101.000,00" height="12" />
</mx:Box>
</mx:HBox>
</mx:HBox>
</mx:VBox>
</mx:Canvas>
It is probably something small, but I can not find it.
The following will get around the problem:
Remove the backgroundImage="{itemBackGround}" from the Canvas element of the itemRenderer
Add the following before the VBox in the itemRenderer class. I tested it out and it works fine:
<mx:Canvas width="100%" height="100%" backgroundImage="{itemBackGround}" backgroundSize="100%"/>
If your find a better way, sure update your question to let us know,
Brian
Have you tried setting the alpha, or backgroundAlpha properties on your List or perhaps in the itemRenderer?
I'm guessing that the List is either drawing something on top of the background, or preventing the background from being drawn. You'd have to step through code to know for sure, though.
I didn't try this, but look like
component is not creating multiple instance/copies of image for each renderer
possible solution may be is, load image in any Singleton/Constant Class like in Model and NOT in component/list and use Model's attribute reference in component/list i.e. one copy for all renderer.
Hopes this works

ComboBox in Flex

I have a combobox with multi selection. when i click on add button, which ever data is selected in the Combobox, those data has to be displayed in the another comboBox.
Please check the code and Can anyone of you please help me on this.
<mx:HBox>
<mx:Label width="140" text="{resourceManager.getString ('resources', 'settings_configuration_database_select_object_instance')}"/>
<mx:List id="obj_instance" enabled="true" allowMultipleSelection="true" width="164" height="70"/>
<mx:Spacer width="20"/>
<mx:Button label=">>"/>
<mx:List id="selected_instance" enabled="true" allowMultipleSelection="true" width="164" height="70"/>
</mx:HBox>
Thanks,
Ravi
What about:
<ov:HPButton label=">>">
<ov:click><![CDATA[
for each (var item:* in obj_instance.selectedItems)
selected_instance.dataProvider.addItem(item);
]]></ov:click>
</ov:HPButton>
Of course, you'll have to make sure that the dataProvider of instance is something reasonable (like an ArrayCollection)…

Binding effect properties inside effect tags not working?

We're trying to do this:
<rollOverEffect>
<AnimateProperty property="scaleX" toValue="{originalWidth + scaleFactor}" />
</rollOverEffect>
However, it seems as though the effects toValue is always NaN. If I set the value to a constant the effect works. Isn't it possible to use databinding for effects like this?
Addendum:
Both originalWidth and scaleFactor is bindable. I managed to get this working by moving the effect out of the rollOverEffect-tag, giving it and id and then binding to it like so:
<AnimateProperty id="scaleEffect" property="scaleX" toValue="{originalWidth + scaleFactor}" />
<MyComponent rollOverEffect="{scaleEffect}" />
Any idea why this works and the former code doesn't? The latter snippet creates a second, uneccessary binding and isn't as readable, but at least it works.
Addendum:
The following code highlights the problem. No matter what the slider is set to, the value of the angleTo property of the effects will always be set to whatever the sliders initial value is set to.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:VBox horizontalCenter="0" verticalCenter="0">
<mx:Label text="Rotation (mouse over on canvas triggers effect):" />
<mx:HSlider id="slider" width="200" minimum="0" maximum="360" value="90" />
<mx:Spacer height="50" />
<mx:Canvas borderStyle="solid" borderThickness="1" borderColor="#ff0000" backgroundColor="#0000ff" width="200" height="200">
<mx:rollOverEffect>
<mx:Rotate angleTo="{slider.value}" duration="500" />
</mx:rollOverEffect>
<mx:rollOutEffect>
<mx:Rotate angleTo="{-slider.value}" duration="500" />
</mx:rollOutEffect>
</mx:Canvas>
</mx:VBox>
</mx:Application>
Compare the with the following code which actually produces the expected result:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Rotate id="rollOver" angleTo="{slider.value}" duration="500" />
<mx:Rotate id="rollOut" angleTo="{-slider.value}" duration="500" />
<mx:VBox horizontalCenter="0" verticalCenter="0">
<mx:Label text="Rotation (mouse over on canvas triggers effect):" />
<mx:HSlider id="slider" width="200" minimum="0" maximum="360" value="90" />
<mx:Spacer height="50" />
<mx:Canvas rollOverEffect="{rollOver}" rollOutEffect="{rollOut}" borderStyle="solid" borderThickness="1" borderColor="#ff0000" backgroundColor="#0000ff" width="200" height="200" />
</mx:VBox>
</mx:Application>
So essentially what the question is, why doesn't the binding work in the first example? There are no errors or warnings to tell you this and neither can I find anything in the documentation about this, could it be a bug?
You need to show us more code. Can you give the following code a shot? Does this work?
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<!-- Simple exemplo to demonstrate the AnimateProperty effect. -->
<mx:Sequence id="animateScaleXUpDown" >
<mx:AnimateProperty property="scaleX" fromValue="{ns.value}" toValue="{ns.minimum}" duration="1000" />
<mx:AnimateProperty property="scaleX" fromValue="1.5" toValue="1" duration="1000" />
</mx:Sequence>
<mx:Panel title="AnimateProperty Effect Example" width="75%" height="75%"
paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10">
<mx:Text width="100%" color="blue"
text="Click on the image to use the AnimateProperty effect with the scaleX property."/>
<mx:Image id="flex" source="http://stackoverflow.com/content/img/stackoverflow-logo.png"
mouseDownEffect="{animateScaleXUpDown}"/>
<mx:NumericStepper id="ns" width="62" value=".5" minimum="1" maximum="3" stepSize="0.5" enabled="true"/>
</mx:Panel>
</mx:Application>

Resources