Close title window from its child component flex - apache-flex

I am implementing a title window, which is calling from the main appication like this
protected function sampleButton_clickHandler(event:MouseEvent):void
{
var ttlWndw:SampleTitleWindow = PopUpManager.createPopUp(FlexGlobals.topLevelApplication as DisplayObject, SampleTitleWindow, true) as SampleTitleWindow;
PopUpManager.centerPopUp(ttlWndw);
}
the title window will be this
<?xml version="1.0" encoding="utf-8"?>
<s:TitleWindow 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:local="*"
width="288" height="230">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<local:SampleVBox id="sampleVBox" x="108" y="83"/>
</s:TitleWindow>
in the title window i had another child component called sample vbox and this component looks like this
<?xml version="1.0" encoding="utf-8"?>
<mx:VBox 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[
protected function closeBtn_clickHandler(event:MouseEvent):void
{
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:Button id="closeBtn" label="Close" click="closeBtn_clickHandler(event)"/>
</mx:VBox>
My question is, I want to close the title window using the button in the sampleVBox component. please someone help me in this.
Thanks in advance!

One solution is to dispatch an event from the SampleVBox component that the parent TitleWindow will listen to. To do this, add some metadata to your SampleVBox class that indicates the class dispatches such an event:
<?xml version="1.0" encoding="utf-8"?>
<mx:VBox 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:Metadata>
[Event(name="close", type="flash.events.Event")]
</fx:Metadata>
<fx:Script>
<![CDATA[
protected function closeBtn_clickHandler(event:MouseEvent):void
{
dispatchEvent(new Event(Event.CLOSE));
}
]]>
</fx:Script>
<s:Button id="closeBtn" label="Close" click="closeBtn_clickHandler(event)"/>
</mx:VBox>
Now, that the SampleVBox declares that it dispatches a "close" event, you can listen for it in the TitleWindow:
<s:TitleWindow 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:local="*"
width="288" height="230">
<fx:Script>
<![CDATA[
protected function onSampleBoxClose():void
{
PopUpManager.removePopUp(this);
}
]]>
</fx:Script>
<local:SampleVBox id="sampleVBox" x="108" y="83" close="onSampleBoxClose()"/>
</s:TitleWindow>

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.

Set text in a label

This should be super simple but I can't for the life of me seem to get it to just set the text of a label at run time. It throws "1120: Access of undefined property lbl_param"
<?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"
width="398" height="85" minWidth="398" minHeight="85">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:Label id="lbl_param" x="19" y="10" width="105" height="29" text="Paramaters: "/>
<fx:Script>
<![CDATA[
lbl_param.text = "test113";
]]>
</fx:Script>
</s:Application>
Your code to set the lbl_param.text should be in a method: The only code in a script block you can run outside of a method is a class import or a variable definition. This sample puts the code in a initialize event hander:
<?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"
width="398" height="85" minWidth="398" minHeight="85" initialize="init()">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:Label id="lbl_param" x="19" y="10" width="105" height="29" text="Paramaters: "/>
<fx:Script>
<![CDATA[
public function init():void{
lbl_param.text = "test113";
}
]]>
</fx:Script></s:Application>
Disclaimer: I wrote this code in the browser and it may not be "compiler" perfect.

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.

load image from filesystem in 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!

Moving TitleWindow application in Air

I have problem. I'd like to make dragable am Air TitleWindow application only by titlebar/header. I have this code, but its dragable everywhere. Could you help in this?
<?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.CloseEvent;
private function mainWindow_closeHandler(event:CloseEvent):void
{
stage.nativeWindow.close();
}
protected function OnDrag(event:MouseEvent):void
{
stage.nativeWindow.startMove();
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:TitleWindow id="mainWindow" width="100%" height="100%"
title="Title Window Header"
mouseDown="OnDrag(event)"
close="mainWindow_closeHandler(event)">
</s:TitleWindow>
</s:WindowedApplication>
In the appliacation xml the settings are:
<systemChrome>none</systemChrome>
<transparent>false</transparent>
This is a kind of solution:
<?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:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:TitleBar height="24" width="100%" x="0" y="0" title="Title"/>
</s:WindowedApplication>

Resources