Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
hungcotac
Posts: 77
Registered: ‎01-05-2013
My Device: BB10
My Carrier: Viettel

Is imageSource attribute a String??

My code simply do the work that change image whenever click button. but it doesn't work.

Any one help me. 

 

Page {
    Container {
        layout: StackLayout {
        }
        Container {
            layout: DockLayout {

            }
            topPadding: 30
            leftPadding: 30
            rightPadding: 30

            preferredHeight: 500
            preferredWidth: 500
            background: Color.LightGray
            horizontalAlignment: HorizontalAlignment.Center
            ImageView {
                id: mImage
                imageSource: "images/Tulips.jpg" //I already have Tulips.jpg and Koala.jpg in assets/images
                onTouch: {

                }
            }

        }

        Button {
            id: mButton
            horizontalAlignment: HorizontalAlignment.Center
            text: "Change"
            onClicked: {
                if (mImage.imageSource == "images/Tulips.jpg") {
                    mImage.imageSource = "images/Koala.jpg"
                } else {
                    mImage.imageSource = "images/Tulips.jpg"
                }

            }
        }
    }
}

 

Please use plain text.
Developer
strobejb
Posts: 267
Registered: ‎10-15-2012
My Device: bb10 developer
My Carrier: Orange

Re: Is imageSource attribute a String??

You need to use the asset:// prefix, or the file:// prefix to specify images. In the case of the file:// prefix, you must specify the full path to the file (not the relative path as you are using currently)
Please use plain text.