Background Image in Flex - apache-flex

I'm using Flash Builder 4 to create an application. I need to set an background image for the app. I've pulled through the data from XML.
I am using an <mx:Image> for the background-image. But I need elements to then be added inside it. How do I achieve this? I considered using Layers, but dont know how you achieve this.
Any help appreciated.
Cheers

One approach: in our flex application, we have a canvas behind our primary container as in
<mx:Canvas id="bgImg" width="1280" height="800"
backgroundImage="assets/background.jpg" />
<containers:FlashContainer id="mainContainer">
<!-- HBoxs, VBoxes and loads of other components -->
</containers:FlashContainer>
So, the other elements you're looking to add would exist within the internal container with a stationary Canvas "behind" it, which holds your image.
To get this to work in Flex 4 you need to compile with the Halo theme (instead of Spark). We use flex builder and set the following flag under the project compiler preferences.
-theme=${flexlib}/themes/Halo/halo.swc
As in the following image:

In the Flex 3 Model, you can set a backgroundImage on the Application tag, which should, effectively, give your whole application a background image.
In the Flex 4 Model, you need to create a custom skin class for your Application tag. Set the skin using the skinClass style. Since s:Application extends SkinnableContainer, you should be able to use the default SkinnableContainer style as a guide for adding a background image. The default background, I believe, is just a Rect w/ a solid fill.

i m still working in flex3, so i would have used backgroundImage on the application tag, and also do set backgroundSize to 100%, these 2 properties r on the application tag,
may be some help 2 u
tc

Related

Wrapping a Flex MXML (or Spark ?) component on a Flash/AS3 Sprite?

When using an mx:Canvas from the Flex api inside a Sprite, I'm getting a TypeError: Error #1009 and following stack:
> StyleManager/getStyleManager
> StyleProtoChain/getStyleManager
> StyleProtoChain/initProtoChain
> UIComponent/initProtoChain
> UIComponent/regenerateStyleCache
> Container/regenerateStyleCache
I guess this is because it require extra initialisation that is usually operated by or from Application / parent contaienr.
Has anybody successfully experienced such wrapping, or, is there any alternative to mx:Canvas in Flash/AS3 ?
If it is not possible, I'll go for a specific actionscript class, or for a stylished Mx application.
You cannot use Flex UI components inside pure Flash application. You cannot put Flex component inside Sprite: read about its lifecycles, there's many things that Convas wants to see in it's parent.
The only solution I see is to have Flex application with mixed content (Flash and Flex), with condition that Flex components are not situated inside Sprites.
The alternative to Canvas in Flash is Sprite (ta-da!). The biggest difference is in its size calculation and external setting (e.g. How to calculate the size of a sprite?).

Animating a sequence of images in the background using Flex 3/Actionscript?

I would like to animate a sequence of background images within a uicomponent but also dynamically add and remove components to this component.
My first question would be:
1.) What's the best way to animate a sequence of images using Flex 3?
2.) What's the best way to handle adding and removing components on top of the background dynamically?
Any help/information would greatly be appreciated!
Thank you!
In the mxml for your ui component declare an mx:Image and give it an id. Set up a timer loop that changes the "source" attribute (id.source = ) on your mx:Image at an interval you like. To add and remove components dynamically just use addChild/removeChild or addElement/removeElement depending on the type of display object you're working with. The mx:Image should always be behind the dynamically added components as it was created and added before them.

change Preloader background color

I have a custom preloader that I designed in flash. When I load it in flex, it loads with a white background. When I try to change the background to black in my flash file & load it in Flex, the background color remains white. I've also tried to update the compiler settings in Flex, adding "-default-background-color #000000" but I still get a white preloader background. I am using Flex 4. Here is my Pre.as file:
`
`
thx!
I encountered the same problem.
solved it using opaqueBackground :
loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.INIT, init);
private function init(e:Event):void{
loader.opaqueBackground = 0x000000;
}
Worked great for me.
This man solved it by adding background sprite and filling it with custom color you want.
And here http://iamjosh.wordpress.com/2007/12/18/flex-custom-preloader/ author also told that he added the compiler option like this:
Finally, let’s change the background
color of the application to match our
logo a little better. Just add the
following Flex compiler argument:
-default-background-color #FFFFFF
So, you might added this option to another one application you need instead.
UPDATE 1
Also look at this
http://cookbooks.adobe.com/post_Change_Background_Color_of_the_Preloader_Phase-1421.html
And please, explain once again your goals, are you want to set color or something another, from preloader or parent application or whatever you want, just let me know.
UPDATE 2
And listen, if you really want some cool bg, you might do next thing.
1)Forget about preloader mechanism.
2)Write Your BG application
3)Add swfLoader overlay to your bg application
4)Draw progressbar for this container
5)Enjoy with 2 application architecture instead of standard way.
Questions!?

Adding components to Flex 4 app makes screen go blank?

I've been adding some components to a Flex 4 app (it was originally Flex 3 but has been ported). Some of these components make the app go blank when it loads. I'm not even able to see the loading progress bar. Just white.
For example, adding
<s:controlBarContent>
<s:Button label="Admin" />
</s:controlBarContent>
To the root tag causes this. I also was able to make it happen when I tried setting a custom components skin from my style sheet instead of from the skinClass property.
Has anyone else run across this behavior?
Setting the creationPolicy for the navigation container to auto or all fixed it...

How to add Scroller in Main application/Windows of Flex?

I am new to Flex. I am trying to add a scroller in my main application/windows.
Is that possible?
I found out it is possible to add scoller bars in DataGrid, like horizontalScrollPolicy="on".
How to implement it in containers like Group,Panel and etc?
Thanks
The answer differs between flex 4 (spark) components and flex 3 (halo) container components. For spark components such as Groups, you need to wrap your group in a Scroller component to get scrollbars to appear when all of the group's content cannot be viewed. Halo container components, such as Canvas, have built in support for scrollbars, meaning they should show up automatically when all of the canvas's content cannot be viewed. Hope that helps.
The Application tag also has horizontalScrollPolicy and verticalScrollPolicy properties.
http://livedocs.adobe.com/flex/3/langref/mx/core/Container.html#horizontalScrollPolicy
http://livedocs.adobe.com/flex/3/langref/mx/core/Container.html#verticalScrollPolicy
In the Spark architecture, you want to look at the Scroller class. This is a good tutorial:
http://www.adobe.com/devnet/flex/articles/flex4_viewport_scrolling.html

Resources