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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:32:28+00:00 2026-06-06T01:32:28+00:00

I’m trying to create a simple two labeled list by creating two label label

  • 0

I’m trying to create a simple two labeled list by creating two label label fields using a class called TwoLabelCell which extends AlternatingCellRenderer and looks like this:

package views
{
    import flash.text.TextFormat;

    import qnx.fuse.ui.listClasses.AlternatingCellRenderer;
    import qnx.fuse.ui.text.Label;

    public class TwoLabelCell extends AlternatingCellRenderer {
        private var description:Label;
        private var labelFormat:TextFormat;
        private var text:String;

        public function TwoLabelCell(labelText:String) {
            this.text = labelText;
        }

        override protected function init():void {
            super.init();

            labelFormat = new TextFormat();
            labelFormat.color = 0x777777;
            labelFormat.size = 17;

            description = new Label();
            description.x = 17;
            description.y = 33;
            description.format = labelFormat;
            description.text = text;

            this.addChild(description);
        }
    }
}

Remember that this one is just a test at the time, so I’m working with only one label (after I figure out this question I’ll add the other and use the same logic). The main idea here is that when I call this it will set the text variable which will be used to change the text of the label on the list when it’s being created. Now, here the main application file:

package {
    import flash.display.Sprite;

    import qnx.fuse.ui.events.ListEvent;
    import qnx.fuse.ui.listClasses.List;
    import qnx.fuse.ui.listClasses.ListSelectionMode;
    import qnx.fuse.ui.listClasses.ScrollDirection;
    import qnx.ui.data.DataProvider;

    import views.TwoLabelCell;

    [SWF(height="600", width="1024", frameRate="30", backgroundColor="#FFFFFF")]
    public class PackTrack extends Sprite {
        private var packList:List;

        public function PackTrack() {
            super();

            initializeUI();
        }

        private function initializeUI():void {
            packList = new List();
            packList.setPosition(0, 0);
            packList.width = 310;
            packList.height = 400;
            packList.rowHeight = 50;
            packList.selectionMode = ListSelectionMode.SINGLE;
            packList.scrollDirection = ScrollDirection.VERTICAL;

            var arrMonth:Array=[];
            arrMonth.push({label: "January"});
            arrMonth.push({label: "February"});
            arrMonth.push({label: "March"});
            arrMonth.push({label: "April"});
            arrMonth.push({label: "May"});
            arrMonth.push({label: "June"});
            arrMonth.push({label: "July"});
            arrMonth.push({label: "August"});
            arrMonth.push({label: "September"});
            arrMonth.push({label: "October"});
            arrMonth.push({label: "November"});
            arrMonth.push({label: "December"});

            packList.dataProvider = new DataProvider(arrMonth);
            packList.cellRenderer = TwoLabelCell("Testing Label");

            packList.addEventListener(ListEvent.ITEM_CLICKED, onListClick);

            this.addChild(packList);
        }

        private function onListClick(event:ListEvent):void {
            trace("Item clicked: " + event.data.label);
            trace("Index clicked: " + event.index);
        }
    }
}

When I try to run that I get this error:

TypeError: Error #1034: Type Coercion failed: cannot convert "Testing Label" to views.TwoLabelCell.
    at PackTrack/initializeUI()[/Users/Nathan/Documents/Adobe Flash Builder 4.6/AIRTest/src/PackTrack.as:46]
    at PackTrack()[/Users/Nathan/Documents/Adobe Flash Builder 4.6/AIRTest/src/PackTrack.as:19]

Any idea on how to solve this?

PS: I’m learning Flex (coming from Java)

  • 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-06-06T01:32:30+00:00Added an answer on June 6, 2026 at 1:32 am

    To answer your question directly: you’re getting a classcast error because you’re trying to cast a String to a TwoLabelCell at packList.cellRenderer = TwoLabelCell("Testing Label"). So I guess you just forgot the new keyword.

    I can tell you come from a Java background: that code looks very Swingy 😉
    So I thought I’d show you how I would do this the Flex way. I don’t know these Blackberry classes you use, so I’ll have to stick to plain old Flex to demonstrate it.

    Create a model class with bindable properties:

    public class Pack {     
        [Bindable] public var label:String;
        [Bindable] public var description:String;       
    }
    

    Now create an ItemRenderer class to render the data in a List, let’s call it PackRenderer.mxml:

    <s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
                    xmlns:s="library://ns.adobe.com/flex/spark" 
                    autoDrawBackground="true"
                    height="50">
    
        <s:layout>
            <s:HorizontalLayout verticalAlign="middle" />
        </s:layout>
    
        <s:Label id="labelDisplay" />
        <s:Label text="{data.description}" color="0x777777" fontSize="17" />
    
    </s:ItemRenderer>
    

    Notice I set the height to 50 which will have the same effect as the rowHeight you used. The data property of an ItemRenderer is the Pack model instance it will represent.
    The Label with id labelDisplay will automatically get the value of data.label assigned to its text property by the Flex framework. For the other Label I use data binding (the {}) to bind the model description property to the Label’s text property.

    Create the List with this itemrenderer:

    <fx:Script>
        <![CDATA[
            protected function handleItemSelected():void {
                trace("Item selected: " + list.selectedItem.label);
                trace("Index selected: " + list.selectedIndex);
            }
        ]]>
    </fx:Script>
    
    <fx:Declarations>
        <s:ArrayCollection id="dp">
            <so:Pack label="Item A" description="description A" />
            <so:Pack label="Item B" description="description B" />
            <so:Pack label="Item C" description="description C" />
        </s:ArrayCollection>
    </fx:Declarations>
    
    <s:List id="list" dataProvider="{dp}" width="310" height="400"
            itemRenderer="net.riastar.PackItemRenderer"
            change="handleItemSelected()" />
    

    I created the data inline here, but of course this ArrayCollection could just as well come from a server.
    The layout of a List is VerticalLayout by default, so I don’t define it.
    The Spark List doesn’t have an itemClick event handler, so I use the change handler, which is executed whenever the List’s selected index/item changes.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
I am doing a simple coin flipping experiment for class that involves flipping a
I'm trying to create an if statement in PHP that prevents a single post
I'm making a simple page using Google Maps API 3. My first. One marker
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I used javascript for loading a picture on my website depending on which small

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.