< Jewel Components list

Jewel View

Reference

Available since version 0.9.4.

Class Extends Implements
org.apache.royale.jewel.View ViewBase IMXMLDocument

Note: This component is currently only available for JavaScript.

Overview

The View class is used as the initialView in a Royale Jewel Application. It is generally used as the root tag of MXML documents and UI controls and containers are added to it.

For responsive applications you can use ResponsiveView instead.

Example of use

In MXML declare a View like this:

<j:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
	xmlns:j="library://ns.apache.org/royale/jewel"
	width="100%" height="100%">

    <!-- View code goes here -->
</j:View>

or directly in the application mxml file inside the initialView:

<j:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
	xmlns:j="library://ns.apache.org/royale/jewel">
	...
	<j:initialView>
		<j:View width="100%" height="100%">
			<!-- View code goes here -->
		</j:View>
	</j:initialView>
</j:Application>

In ActionScript we can do the same in the following way:

// instantiate the view
var view:View = new View();
// add content to the view and and add to application's initialView
application.initialView = view;

where application is the Jewel Application.

Relevant Properties and Methods

Check the Reference of org.apache.royale.jewel.View for a more detailed list of properties and methods.

Properties

PROPERTY Type Description
applicationModel Object A reference to the Application’s model.
currentState String The name of the current state.
numElements int The number of element children that can be laid out.
mxmlContent Array The array of childs for this view. Is the DefaultProperty.
popUpParent IPopUpHostParent A view can be the parent of a popup that will be part of the layout.
popUpHost IPopUpHost A view can host popups that will be part of the layout.
states Array The array of view states. These should be instances of org.apache.royale.states.State

Methods

Method Parameters Description
addElement c(IChild), dispatchEvent(Boolean=true) Add a component to the parent.
addElementAt c(IChild), index(int), dispatchEvent(Boolean=true) Add a component to the parent at the specified index.
getElementIndex c(IChild) Gets the index of this subcomponent.
getElementAt index(int) Get a component from the parent at specified index.
removeElement c(IChild), dispatchEvent(Boolean=true) Remove a component from the parent.

Relevant Events

The most important event is initComplete, which indicates that the initialization of the view is complete.

It is needed when some action coded in a callback function needs to be triggered when the view is ready to use after initialization.

You can attach callback listeners to the initComplete event in MXML as follows:

<j:View initComplete="initCompleteHandler(event)"/>

the initComplete event will use the initCompleteHandler callback function you provide in ActionScript:

<fx:Script>
    <![CDATA[      
        private function initCompleteHandler(event:Event):void {
            trace("View is ready!");
        }
    ]]>
</fx:Script>

When the view is initialized the message “View is ready!” appears in the console log.

In ActionScript we can add an event handler this way:

var v:View = new View();
v.addEventListener('initComplete', initCompleteHandler);

Relevant Beads

Bead Type Implementation Description
GroupView org.apache.royale.core.IBeadView This is the default view bead.
ViewLayout org.apache.royale.core.IBeadLayout This is the default layout bead.

Optional Beads

Bead Type Implementation Description
ViewDataBinding org.apache.royale.binding.DataBindingBase Provide binding capabilities to the view.

Common Beads

Jewel View can use any of the layout beads available in the Jewel library. You can also check Related controls to see some preconfigured views with specific layouts.

More examples

Other useful Jewel view components are: