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 6385287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:52:50+00:00 2026-05-25T02:52:50+00:00

I need to have a spark list that switches between VerticalLayout and TileLayout depending

  • 0

I need to have a spark list that switches between VerticalLayout and TileLayout depending on the user choice. The most obvious way is create two lists with separate layouts and then use States and the “includeIn” attribute. However, this is not a very good solution because I would like to keep the same items in the view when switching (if user scrolled to item 100 in the VerticalLayout and then switches to Tile, I would like item 100 to be visible immediately in the new layout, instead of starting at the first item).

So I tried using 2 layouts on the same list and using the “includeIn” solution. However, I get this error:

“In initializer for ‘layout’, multiple initializer values for target
type spark.layouts.supportClasses.LayoutBase.”

Here’s the source code that generates this error, can anyone suggest a better way to do this?

<?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:mx="library://ns.adobe.com/flex/mx"
    >

    <fx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;

            [Bindable]
            public var myAC:ArrayCollection = new ArrayCollection([
                "01","02","03","04","05","06","07","08","09","10",
                "11","12","13","14","15","16","17","18","19","20",
                "21","22","23","24","25","26","27","28","29","30",
                "31","32","33","34","35","36","37","38","39","40",
                "41","42","43","44","45","46","47","48","49","50"
            ]);

            public function toggleListTileState():void
            {
                if(currentState=="ListState") currentState = "TileState"
                else currentState = "ListState";
            }
        ]]>    
    </fx:Script>

    <s:actionContent>
        <s:Button label="tile" label.TileState="list" click="toggleListTileState()"/>
    </s:actionContent>  

    <s:states> 
        <s:State name="ListState" /> 
        <s:State name="TileState" /> 
    </s:states>

    <s:List
        id="list"
        width="100%"
        height="100%"
        dataProvider="{myAC}"
        >
        <s:layout>
            <s:VerticalLayout
                includeIn="ListState"
                horizontalAlign="justify"
                useVirtualLayout="true"
                />

            <s:TileLayout
                includeIn="TileState"
                rowHeight="300"
                useVirtualLayout="true"
                />
        </s:layout>
    </s:List>

</s:View>

Thank you

  • 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-25T02:52:50+00:00Added an answer on May 25, 2026 at 2:52 am

    You were almost there. You can do exactly what you were attempting, you just have to write it slightly differently. Something like this:

    <s:List id="list" width="100%" height="100%" dataProvider="{myAC}">
        <s:layout.ListState>
            <s:VerticalLayout horizontalAlign="justify" useVirtualLayout="true" />
        </s:layout.ListState>
        <s:layout.TileState>
            <s:TileLayout rowHeight="300" useVirtualLayout="true" />
        </s:layout.TileState>
    </s:List>
    

    When you think about it, this is this exact same way of writing state dependent properties as this example:

    <s:List id="list" width.ListState="100" width.TileState="200" />
    

    The only difference is that the property is written as an (M)XML tag rather than as an (M)XML attribute.

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

Sidebar

Related Questions

I have need for a function pointer that takes two arguments and returns a
I need to have ha validity test to see if input from a user
I need to have a thread signal another if the user wishes to interrupt
I think I just need someone to show me the obvious. I have a
I have a spark borderContainer that contains a spark TextInput. I have an mouse_down
I have a BorderContainer with some instances of spark Line. I need to select
I have an issue with Spark Lists whereby I am trying to ensure that
I have a Flex Spark List which can be populated with any number of
I have a TextInput inside a spark Item Renderer. I need to undo some
I have created an ItemRenderer for the Spark List component with the following code.

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.