Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6883135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:20:37+00:00 2026-05-27T05:20:37+00:00

For my flex project I am making, I’m trying to change the background of

  • 0

For my flex project I am making, I’m trying to change the background of my website change to the image I have clicked on. The background in my main page I have set like this:

<s:BorderContainer id="backgroundContainer" width="100%" height="100%" backgroundImage="@Embed('assets/background.png')" borderAlpha="0">

        <s:layout>
            <s:VerticalLayout horizontalAlign="center"/>
        </s:layout>


    <mx:LinkBar styleName="mainnav" width="600" dataProvider="content" horizontalCenter="0" paddingLeft="20" paddingTop="125"/>

    <s:Image top="5" bottom="5" horizontalCenter="50" source="assets/nav.png"/>

    <mx:ViewStack id="content">

        <mx:HBox id="home"
                 label="Home">
            <component:home/>
        </mx:HBox>

        <mx:HBox id="bio"
                 label="Bio">
            <component:bio/>
        </mx:HBox>

        <mx:HBox id="portfolio"
                 label="Portfolio">
            <component:portfolio/>
        </mx:HBox>

        <mx:HBox id="contact"
                 label="Contact">
            <component:contact/>
        </mx:HBox>

    </mx:ViewStack>     

    </s:BorderContainer>

Now from inside my component, I am trying to set the the background of the image you click on.

<fx:Script>
    <![CDATA[               
        import mx.core.Application;


    public function changeBackground(event:MouseEvent):void
    {
        Application.application.backgroundContainer.setStyle('backgroundImage', img1.source);
    }
    ]]>

</fx:Script>

I call this function when you click on an image.

<mx:Image id="img1" source="assets/placeholder.jpg" click="changeBackground(event)"/>

But it doesn’t work.
So I was wondering how this should be done?

Thank you,
Thomas

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T05:20:38+00:00Added an answer on May 27, 2026 at 5:20 am

    you can use BitmapFill and declare all your backgrounds first. Also, be sure your changeBackground function is public in your main application since it will be called from a component.

    <?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:component="component.*">
    
        <fx:Script>
            <![CDATA[
    
                public function changeBackground(bitmapFillObj:BitmapFill):void
                {
                    backgroundContainer.backgroundFill = bitmapFillObj;
                }
    
            ]]>
        </fx:Script>
    
        <fx:Declarations>
            <s:BitmapFill id="_bg1" source="@Embed('assets/bg1.jpg')"/>
            <s:BitmapFill id="_bg2" source="@Embed('assets/bg2.jpg')"/>
        </fx:Declarations>
    
        <s:BorderContainer id="backgroundContainer" width="100%" height="100%" backgroundImage="@Embed('assets/bg1.jpg')" borderAlpha="0">
    
            <component:home/>
    
        </s:BorderContainer>
    
    </s:WindowedApplication>
    

    And now your component

    <fx:Script>
        <![CDATA[
            import mx.core.FlexGlobals;
        ]]>
    </fx:Script>
    
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    
    <s:layout>
        <s:HorizontalLayout/>
    </s:layout>
    
    <s:Button label="click to show bg 1" click="FlexGlobals.topLevelApplication.changeBackground(FlexGlobals.topLevelApplication._bg1)"/>
    
    <s:Button label="click to show bg 2" click="FlexGlobals.topLevelApplication.changeBackground(FlexGlobals.topLevelApplication._bg2)"/>
    

    Your just have to adapt the code to your project, clicking on your images instead of buttons. Good luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a change to a set of code for a Flex project that
We have a Flex 4.0 project in our product and we're trying to set
I have a list of webservices from a Flex project. I am trying to
I'm working on a flex project, and have a datagrid that I'd like the
I've got a reasonably large Flex project and I'm trying to generate ASDoc documentation
I'm looking to have a couple of plugins in a Flex project I'm working
So, I have Flex project that loads a Module using the ModuleManager - not
I have some interesting problem for an hour.. In my flex project, all width
I have written a Flex Library project - a .swc file - which is
I'm trying to compile existing Flex 4 project but having an error: Call to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.