I want to create a custom component library. the components are customize-able during creation time. means like Accordion or TabNavigator, when we drag and drop the Accordion in flash builder it
<mx:Accordion x="38" y="167" width="200" height="200">
<s:NavigatorContent width="100%" height="100%" label="Accordion Pane 1">
</s:NavigatorContent>
</mx:Accordion>
look there is two tags came at a time mx:Accordion and s:NavigatorContent how it happens. how can i create a component like this.
I want to create a component of container with three buttons. after i drag component into flash builder it should editable mean its tag must look like this
<local:container x="38" y="167" width="200" height="200">
<s:button width="10" height="10" />
<s:button width="10" height="10" />
<s:button width="10" height="10" />
</local:container>
In order to add additional tags when the user drags your custom component into Flash Builder you'll have to write an extension for your component and configure it within a design.xml file.
Here are a few links to get you started:
Flash Builder Design View extension FAQ
Extending Flex Builder
Design View Extensibility Kit for Flex 4.5
First You want to understand one thing, that is creation of custom components is to simplify the tags. Though the flash builder also won't supports such kind of thing. The custom components child can be created internally by overriding some methods in it, which depends upon the base class you inherit.
Creation of Custom component will lead only to
<local:container x="38" y="167" width="200" height="200">
</local:container>
Though you can add child in it by manually or internally.
Related
I have been given the unenviable task of displaying a logo on a flex 3.2 form on our website. I'm learning flex as I go, and I can embed a logo now.
The problem is, I need to display a different logo, depending on which client the user works for. And I need to have it working by end of day, Friday, August 30th. As in, this Friday.
This is the code I have for embedding the logo:
<mx:GridRow width="100%" height="100%">
<mx:GridItem width="100%" height="100%" colSpan="6">
<mx:Image width="180" source="#Embed('/assets/images/logo.JPG')"/>
</mx:GridItem>
</mx:GridRow>
So, what I need to know is, is there any way to get Flex 3.2 to display a different logo for each client? The above code obviously isn't going to do it.
As a further bit of info, we do have the logos as blobs in the Oracle database.
Thanks for any help.
You need not embed, you can give path to the images on the server. like
<mx:Image width="180" source="http://somedomain.com/images/logo.JPG"
id='image'/>
OR, using the id of the image component, you can assign the logo dynamically, like the following
private function onCreationcomplete(e:FlexEvent):void
{
if(client ='xxyy'){
image.source = 'http://somedomain.com/images/xxyy.JPG ';
}
}
If you are familiar with BlazeDS, then you could try this approach: BLOB from Java to Flex via BlazeDS.
For the approach from #Zeus I would recommend to write an image servlet which delivers the client logo at request from your database blob.
I tried to insert a FileSystemTree in Flex .
Flash Builder doesn't recognise that and produces the error:
1046: Type was not found or was not a compile-time constant: FileSystemTree
Here's the code . It's a very basic one ....
<mx:HDividedBox width="100%" height="725" paddingLeft="10" paddingRight="10" paddingBottom="10" paddingTop="10" y="41">
<mx:VBox width="200" height="100%">
<mx:FileSystemTree id="fileSystemTree" width="100%" height="100%" change="onChange(event)" />
</mx:VBox>
<mx:Canvas width="100%" height="100%" id="content" ></mx:Canvas>
</mx:HDividedBox>
I'm using Flex 4 , Flash Builder 4. What am i doing wrong ? Is FileSystemTree supported in Flex 4 ?
That component is only available within Adobe AIR applications, not browser-based Flex applications, since browsing the local file system would violate the browser sandbox.
EDIT: Now that I understand your intention, yes, you can upload files from a flex application without having to use AIR. Instead of using the FileSystemTree component (which is AIR only), you use FileReference.browse() to allow the user to select a file from the local filesystem to upload. This page from the documentation will give you all the info you need: Working with file upload and download
Hope that helps.
I'm planning to break my Flex applications into different modules and need some advice regarding the loading of modules.
Currently, on load of the application, I need to add 5 modules as children to HGroups under a viewstack.
I'm using a ModuleManager to perform this and listens to the ModuleEvent to add the elements as IVisualElement under the HGroup.
Is there a way to add several modules without creating several IModuleInfo objects and multiple event listeners?
Please provide your inputs.
Here is the simplest way:
<mx:TabNavigator width="300" height="300">
<mx:ModuleLoader url="com/sample/Module1.swf"/>
<mx:ModuleLoader url="com/sample/Module2.swf"/>
<mx:ModuleLoader url="com/sample/Module3.swf"/>
</mx:TabNavigator>
Code of Module1, all others are the same:
<mx:Module xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<s:Label text="Module 1"/>
</mx:Module>
I'm writing an Adobe AIR application using a ViewStack for the different application states. Is there a way to make sure that each view component is created/destroyed each time it is shown/hidden?
For instance, if I have a TextInput in a view, I want it to reset to its initial state each time I change to that view, rather than having previously entered text. Or, if I have a Timer, I want it to be destroyed when I leave the view so that it doesn't keep running when I'm in an unrelated part of the application. I know that I can manually initialize/destroy everything on the show() and hide() events, but is there an easier way?
AFAIK there is no built-in way to do this, so you'll have to do it manually by handling the show and hide events as you mention.
ViewStack does however have two methods "saveState" and "loadState" which could perhaps help you out with this. The history manager uses these methods to enable back/forward navigation. The docs don't seem to have any examples though.
ViewStacks can be the work of the devil when it comes to creation/deletion policies and managing state. We had all sorts of problems when we developed fiat ecoDrive and by about 3/4 of the way though we we're all very anti ViewStacks for the management of view state within our application.
However... a good bet would be to first set the creationPolicy to ContainerCreationPolicy.NONE. That way it's in your control as to when to create any of the panels in your ViewStack. Then i would think you would need to have some sort of logic so that as the ViewStack changes a panel it deletes or resets the one you were on.
Another viable alternative would be to use view states instead. Have a base state which acts as the main container and then a simple state for each of your sections. That way when you switch to a new state, the old state gets removed in reverse order to the way it was created. You do have to be disciplined with states though as they can end up getting really complex and messy when they start becoming nested. If you keep it simple it may work as you require.
In MXML 2009, you can use itemDestructionPolicy="auto" to destroy a component after use it. If you use this property in the first view component with two states (init, logged), you can destroy and reinitialize all child view components. Example :
<s:states>
<s:State name="init" />
<s:State name="logged" />
</s:states>
<s:SkinnableContainer id="skincon" width="100%" height="100%" backgroundAlpha="0"
backgroundColor="#FFFFFF">
<s:VGroup id="MainContainer" width="100%" height="100%" paddingTop="0"
paddingLeft="20" paddingRight="20" gap="0">
<views:_HeaderView id="header" />
<mx:ViewStack id="viewStack" width="100%" height="100%">
<s:NavigatorContent includeIn="init" itemDestructionPolicy="auto">
<s:layout>
<s:VerticalLayout horizontalAlign="center" verticalAlign="middle" />
</s:layout>
<views:LoginView title="Login" id="loginView" />
</s:NavigatorContent>
<s:NavigatorContent includeIn="logged" itemDestructionPolicy="auto">
<s:layout>
<s:VerticalLayout horizontalAlign="center" verticalAlign="top" />
</s:layout>
<views:_CentralView id="userView" />
</s:NavigatorContent>
</mx:ViewStack>
<views:_FooterView id="footer" />
</s:VGroup>
</s:SkinnableContainer>
Both answers are correct -- there doesn't seem to be any built-in way to do it. I solved the problem by creating a "wrapper" component for my view component. It creates a new view component each time the view is shown. This isn't ideal, but fits my requirements nicely, and required few changes to my application structure.
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" show="init()" hide="cleanup()">
<mx:Script>
<![CDATA[
private var myComponent:MyComponent;
private function init():void
{
myComponent = new MyComponent();
componentContainer.addChild(myComponent);
}
private function cleanup():void
{
componentContainer.removeAllChildren();
}
]]>
</mx:Script>
<mx:Canvas width="100%" height="100%" id="componentContainer" />
</mx:Canvas>
Build your "views" as separate Modules, and then use the ViewStack to switch between them. You could then write a function to destroy the unused module(s) (check each module against the selectedChild property) when the ViewStack's "change" event is fired.
2ยข
I am using different states for my different views. On each state change i add and remove components.
This causes the add and remove events of UIComponent fire which allows me to initialize and cleanup my components each time they are added.
This is the idea...
<mx:states>
<mx:State name="state1">
<mx:AddChild>
<mx:SomeUIComponent id="myComp" add="myComp.initialize()" remove="myComp.cleanup()"/>
</mx:AddChild>
</mx:State>
</mx:states>
For simplicity lets say I have two flex mxml pages.
form.mxml
button.mxml
If the form.mxml page had the following code, it should work fine:
<custom:SelectView dSource="{_thedata}" id="form" visible="false">
</custom:SelectView>
<mx:LinkButton label="Show" id="lbShow" click="form.visible=true;>
<mx:LinkButton label="Show" id="lbHide" click="form.visible=false;>
But if the code was like:
form.mxml
<custom:SelectView dSource="{_thedata}" id="form" visible="false">
</custom:SelectView>
button.mxml
<mx:LinkButton label="Show" id="lbShow" click="form.visible=true;>
<mx:LinkButton label="Show" id="lbHide" click="form.visible=false;>
how can I make a call from button.mxml to change form.mxml
---- a bit more details ---
My page actually looks like this: where query:AdvancedSearchFields is basically including a flex form into the page, and I want it to show/hide the custom view below after the search is complete.
<query:AdvancedSearchFields searchType="projects" searchCategory="advanced" visible="true" id="AdvancedSearch" />
<custom:SelectView dSource="{_searchResults}" id="sv" visible="false">
You could write a custom method that handles the button click events and raises a custom event. Then in form.mxml you can handle that event.
Splitting it up like this is a bit cleaner, as it makes the button.mxml file work on its own. Having Button.mxml have a direct reference to your form causes a tight-coupling between the two, and generally you should avoid tight-coupling.
EDIT: I just had another thought that also avoids tight-coupling and is a bit simpler:
form.mxml
<custom:SelectView dSource="{_thedata}" id="form" visible="{buttons.showForm}">
</custom:SelectView>
<!-- include your buttons.mxml component using an ID of "buttons" -->
buttons.mxml
<mx:Script>
<![CDATA[
[Bindable] public var showForm:Boolean = true;
]]>
</mx:Script>
<mx:LinkButton label="Show" id="lbShow" click="this.showForm=true;">
<mx:LinkButton label="Hide" id="lbHide" click="this.showForm=false;">
This essentially emulates using a custom event by using variable binding. Any time the showForm variable in buttons changes the visible property of the SelectView will be updated via the bindings. This is lighter-weight than creating a custom event (though I think custom events are a bit better of a design for it).
Your button.mxml class must have a reference to the instance of the 'form' class which will be affected. Then it can operate on it directly:
Button.mxml:
<mx:Script>
<![CDATA[
[Bindable] public var myForm:MyFormClass;
]]>
</mx:Script>
<mx:LinkButton label="Show" id="lbShow" click="myForm.form.visible=true;">
<mx:LinkButton label="Show" id="lbHide" click="myForm.form.visible=false;">
Generally, the most logical place to set this variable is in the parent of your Button class.
If you need to deal with this problem more often, I'd suggest using an MVC framework like PureMVC. It's set up so that you have a Mediator object that listens for events from MXML components, then sends a notification which can be picked up by any other mediator. Then that mediator can manipulate its own visual component based on the notification and its associated data.
In the context of what you're doing (the simple version), you're okay with the basic solution. But once you're dealing with four or five or more components with lots of logic, you will not be happy at all.