Online Book Reader

Home Category

Developing Android Applications with Adobe AIR [98]

By Root 2497 0
time

if (session.time > timeKeeper) {

timeKeeper = session.time;

ypos += 15;

// TimeBar is a movieclip

var bar:TimeBar = new TimeBar();

bar.y = ypos;

bar.timeInfo.text = timeKeeper;

container.addChild(bar);

ypos += 60;

}

// load the individual session

// it returns its height to position the next element below it

var newPos = loadSession(session, ypos);

ypos =+ (newPos + 10);

}

addChild(container);

}

private loadSession(session:Session, ypos:int):int {

// SessionSmall is a movieclip

var mc:SessionSmall = new SessionSmall();

mc.y = ypos;

mc.id = session.id;

mc.what.autoSize = TextFieldAutoSize.LEFT;

mc.what.text = "+ " + session.title;

mc.back.height = mc.what.height;

mc.addEventListener(MouseEvent.CLICK, clickAway, false, 0, true);

container.addChild(mc);

// return the session movie clip height

return mc.what.height;

}

When the user chooses a session, its ID is passed along with the destination view:

public function clickAway(event:MouseEvent):void {

dispatchEvent(new ClickEvent(ClickEvent.NAV_EVENT,

{view:"session", id:event.currentTarget.id}));

}

In the onHide method, all the children of the Sprite container are removed as well as their listeners if they have one. Then the container itself is removed. Figure 16-3 shows the sessions broken down by day and time:

public function onHide():void {

while (container.numChildren > 0) {

var child:MovieClip = container.getChildAt(0) as MovieClip;

if (child.id != null) {

child.removeEventListener(MouseEvent.CLICK, clickAway);

}

container.removeChild(child);

}

removeChild(container);

container = null;

}

Figure 16-3. The sessions broken down by day and time

Here is the SessionView code. The method displays all the data related to a session. This includes the session title, a description, the speakers involved, and the room, category, and rank:

package view {

import events.ClickEvent;

import flash.events.MouseEvent;

import model.Sessions;

import model.Speakers; // static class that holds Speakers data

final public class SessionView extends BaseView implements IView() {

public function SessionView(){}

public function onShow():void {

// search Sessions by id

var data:Object = Sessions.getItemByID(id);

container = new Sprite();

addChild(container);

// display title and description

// SessionMovie is a movieclip

var session:SessionMovie = new SessionMovie();

session.title.autoSize = TextFieldAutoSize.LEFT;

session.title.text = data.title;

session.body.text = data.description;

container.addChild(session);

// display list of speakers

for (var i:int; i < data.speakers.length; i++) {

var bio:Bio = new Bio();

bio.id = data.speakers[i];

// search list of speakers by id

var bioData:Object = Speakers.getItemByID(bio.id);

bio.speaker.text = bioData.first + " " + bioData.last;

bio.addEventListener(MouseEvent.CLICK,

clickAway, false, 0, true);

}

// display category, level, rank and room number

// Border is a movieClip

var border:Border = new Border();

// categories is a movieclip with frame labels matching category

border.categories.gotoAndStop(data.tag);

// rank is a movieclip with a text field

border.rank.text = String(data.type);

// room is a movieclip with a text field

border.room.text = String(data.room);

container.addChild(border);

}

Clicking on one of the speakers takes the user to a new speaker destination view defined by an ID:

public function clickAway(event:MouseEvent):void {

dispatchEvent(new ClickEvent(ClickEvent.NAV_EVENT,

{view:"speaker", id:event.currentTarget.id}));

}

}

In the onHide method, all the children of the Sprite container are removed as well as their listeners if they have one. Then the container itself is removed:

public function onHide():void {

while(container.numChildren > 0) {

var child:container.getChildAt(0);

if (child.id != null) {

child removeEventListener(MouseEvent.CLICK, clickAway);

}

container.removeChild(child);

}

removeChild(container);

container = null;

}

Figure 16-4 shows a subset of information for a session.

Figure 16-4.

Return Main Page Previous Page Next Page

®Online Book Reader