load image from filesystem in flex - apache-flex

i have the following:
<s:Image source="{path}/imageName"/>
how can i determine that path to load the image from filesystem lets say from
C:\Users\sstauross\Desktop ??

Edit : If you want to select a specific path, the user will have to confirm the path himself first using the FileSystemList
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
private var userPath:String;
protected function button_clickHandler(event:MouseEvent):void
{
userPath = fsList.selectedPath;
}
]]>
</fx:Script>
<s:layout>
<s:VerticalLayout/>
</s:layout>
<mx:FileSystemList id="fsList"/>
<s:Label text="{fsList.selectedPath}"/>
<s:Button label="Confirm folder selection" click="button_clickHandler(event)"/>
</s:WindowedApplication>
Here's one way to do it
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" creationComplete="creationCompleteHandler(event)">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
[Bindable]
private var desktopPath:String;
protected function creationCompleteHandler(event:FlexEvent):void
{
desktopPath = File.desktopDirectory.nativePath.toString();
}
]]>
</fx:Script>
<mx:Image source="{desktopPath}/myFile.jpg"/>
</s:WindowedApplication>

The answer to what i was looking was very simple because i put
<s:Image source="C:\Users\sstauross\Desktop\imageName"/>
instead of
<s:Image source="C:/Users/sstauross/Desktop/imageName"/>
notice the "\" instead of "/"...
Thanks a lot for your answers!

Related

How to create draggable panel without title in Flex?

I want to drag my panel without title when I drag any part of it. I already know how to remove title from panel and I know how to drag it with title bar. But i don't know how to drag without title.. Please help.
Here is my example
//Application
<?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="init(event)">
<fx:Script>
<![CDATA[
import com.dragpanel.MyPanel;
import mx.events.FlexEvent;
protected function init(event:FlexEvent):void
{
var panel:MyPanel = new MyPanel();
panel.width = 300;
panel.height = 200;
panel.title = "Hello";
this.addElement(panel);
}
]]>
</fx:Script>
</s:Application>
//MyPanel.mxml
<?xml version="1.0" encoding="utf-8"?>
<s:Panel xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
width="150" height="80" title="Hello"
mouseDown="onMouseDown(event)" mouseUp="onMouseUp(event)"
skinClass="com.dragpanel.PanelNoTitleBar">
<fx:Script>
<![CDATA[
protected function onMouseDown(event:MouseEvent):void
{
this.startDrag();
}
protected function onMouseUp(event:MouseEvent):void
{
this.stopDrag();
}
]]>
</fx:Script>
<s:HGroup verticalAlign="bottom" x="10" y="10">
<s:Label text="Name:"/>
<s:TextInput width="60"/>
</s:HGroup>
</s:Panel>
How are you starting the drag using the title bar? Do you have a mouseDown listener on the titlebar section of the Panel? You can just move the mouseDown listener to the Panel itself.

Setting up Dataprovider

I have a php service like this.
<stockproductservice:StockproductService id="stockproductService"
fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)"
showBusyCursor="true"/>
and it use a php serivce.
how should I set up the dataprovider in the itemRedenerer?
<s:DataService source="{stockproductService.getAllStockproduct1()}"/>
and
<s:WebService source="{stockproductService.getAllStockproduct1()}"/>
are not working.
If your question is how to set up a WebService to populate a dataProvider in the simplest form it could be this:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" creationComplete="creationCompleteHandler(event)"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<s:List dataProvider="{restaurants}" labelField="name" />
<fx:Declarations>
<s:WebService id="RestaurantWS" wsdl="http://examples.adobe.com/flex3app/restaurant_ws/RestaurantWS.xml?wsdl" />
<s:CallResponder id="getRestaurantsResult"
result="restaurants = getRestaurantsResult.lastResult as ArrayCollection"/>
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.events.FlexEvent;
[Bindable]
public var restaurants:ArrayCollection;
protected function creationCompleteHandler(event:FlexEvent):void
{
getRestaurantsResult.token = RestaurantWS.getRestaurants();
}
]]>
</fx:Script>
</s:Application>

Close a Callout inside a View in Flex

I have this ViewNavigator inside a callout and the callout displays a view inside it using firstView="views.ListMenusHomeView" . Now how can I close the callout from ListMenusHomeView? Hope someone can help.
Here is my code for the callout:
<?xml version="1.0" encoding="utf-8"?>
<s:Callout xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
contentBackgroundAppearance="none"
height="300" width="300">
<fx:Declarations>
<fx:XML id="menu" source="xmldata/menu2.xml" />
</fx:Declarations>
<fx:Script>
<![CDATA[
import spark.events.PopUpEvent;
protected function back(event:MouseEvent):void {
if(viewNav.length>1)
viewNav.popView();
}
]]>
</fx:Script>
<s:ViewNavigator id="viewNav" width="100%" height="100%" firstView="views.ListMenusHomeView">
<s:navigationContent>
<s:Button label="Back" click="back(event)"/>
</s:navigationContent>
<s:actionContent>
<s:Button label="Cancel" click="close(false)" emphasized="true"/>
</s:actionContent>
</s:ViewNavigator>
</s:Callout>
You see that there is a ViewNavigator which holds the ListMenusHomeView. This is the code for the ListMenusHomeView.
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" title="Main Menu" creationComplete="onCreationComplete()">
<fx:Declarations>
<fx:XML id="menu" source="xmldata/menu2.xml" />
</fx:Declarations>
<fx:Script>
<![CDATA[
import com.adobe.serializers.xml.XMLDecoder;
import mx.collections.ArrayCollection;
import spark.events.IndexChangeEvent;
[Bindable]
private var dataArray:ArrayCollection = new ArrayCollection();
private var object:DataArray = new DataArray();
private function onCreationComplete() : void{
var decoder:XMLDecoder = new XMLDecoder();
var resultObj:Object = decoder.decode(menu);
dataArray = object.onCreationComplete(menu, menu.menuitem, resultObj, resultObj.menuitem);
}
protected function list1_changeHandler(event:IndexChangeEvent):void
{
}
]]>
</fx:Script>
<s:List id="tileLayout"
width="100%" height="100%"
verticalScrollPolicy="off" horizontalScrollPolicy="on"
pageScrollingEnabled="true" dataProvider="{dataArray}"
itemRenderer="renderers.iconList2" change="list1_changeHandler(event)">
<s:layout>
<s:TileLayout orientation="columns" requestedRowCount="3"
verticalGap="20" horizontalGap="20"/>
</s:layout>
</s:List>
Now I want to close MyCallout whenever I click an icon inside ListMenusHomeView. The function list1_changeHandler(event:IndexChangeEvent) is responsible for that one.
What should I do?
The Callout class has a close() method, so you basically just need to access the ListMenusHomeViews parentDocument (which would be your "viewNav" ViewNavigator) and its parentDocument, which should be your ListMenusHomeView.
I haven't tested it but you might fiddle around with the parentDocument, parent and owner properties to access the correct object. Try them with a simple trace and you'll be up and running in no time.

Flex - HTTPRequest to output html source in TextArea

I have a TextArea and I'm trying to use HTTPRequest to fetch a website and output the html source
in the TextArea but nothing is happening.
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:ns1="*"
actionBarVisible="true" currentState="landscape" tabBarVisible="false"
overlayControls.landscape="false"
tabBarVisible.landscape="false"
actionBarVisible.portrait="true" viewActivate="view1_viewActivateHandler(event)">
<fx:Declarations>
<s:HTTPService id="service" resultFormat="e4x"/>
</fx:Declarations>
<s:TextArea id="mainTextField" text="{service.lastResult}"/>
<fx:Script>
<![CDATA[
import spark.events.ViewNavigatorEvent;
protected function view1_viewActivateHandler(event:ViewNavigatorEvent):void
{
service.url = "http://www.google.com";
}
]]>
</fx:Script>
<s:actionContent>
</s:actionContent>
<s:titleContent>
</s:titleContent>
</s:View>
You should call service.send() to send request.

Flex 4: Event Listener created, but not being called?

I'm trying to call an event I've created in another component. I've added trace() into my methods so I can see what's being called. Everything except for the event listener (myEvent) is being called. Can anyone tell me why this is please?
Any help would be greatly appreciated. Thanks in advance.
// TestApp.mxml (application)
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication 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:com="com.*"
creationComplete="initApp()">
<fx:Script>
<![CDATA[
import com.MyPopUp;
import mx.managers.PopUpManager;
protected function initApp():void
{
var popUp:MyPopUp = new MyPopUp();
PopUpManager.addPopUp(popUp, this);
}
]]>
</fx:Script>
<com:MyComp/>
</s:WindowedApplication>
// MyComp.mxml (component)
<?xml version="1.0" encoding="utf-8"?>
<s:VGroup xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
width="100%" height="100%"
creationComplete="initComp()">
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.DynamicEvent;
protected function initComp():void
{
trace('init MyComp()');
this.addEventListener('myEvent', myEvent);
}
private function myEvent(event:DynamicEvent):void
{
trace('myEvent()');
Alert.show('Event Called!', 'Success');
}
]]>
</fx:Script>
</s:VGroup>
// MyPopUp.mxml (component)
<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" width="100" height="100">
<fx:Script>
<![CDATA[
import mx.events.DynamicEvent;
import mx.managers.PopUpManager;
private function call(event:MouseEvent):void
{
trace('call()');
PopUpManager.removePopUp(this);
var evt:DynamicEvent = new DynamicEvent('myEvent');
evt.value1 = '1234';
dispatchEvent(evt);
}
]]>
</fx:Script>
<s:Button click="call(event)" label="Call Event"/>
</s:Group>
MyComp and MyPopup aren't in the same display list hierarchy, so the bubbling event isn't being seen.
If you are wanting to send messages across components in this way consider using some sort of global event dispatcher, using using a shared model between the two components in order to see data changes.

Resources