Titanium : Disabling a tab within a TabGroup - tabs

Im trying to get the first and last tab of the TabGroup to be disable so I can give them custom functionality instead of switching the view. I have tried touchEnabled = false and a handfull of other stuff and I'm cant seem to get anything to work ... any ideas?
function TabView() {
var viewOne = require('ui/common/...');
var viewTwo = require('ui/common/...');
var viewTree = require('ui/common/...');
var self = Ti.UI.createTabGroup();
var tab1 = Titanium.UI.createTab({
title : 'Tab 1'
});
var firstView = viewOne();
var tab2 = Ti.UI.createTab({
title: L('firstView'),
icon: '/images/...',
window: firstView,
active:true
});
firstView.containingTab = tab2;
var secondView = viewTwo();
var tab3 = Ti.UI.createTab({
title: L('secondView'),
icon: '/images/...',
window: secondView
});
secondView.containingTab = tab3;
var thirdView = viewTree();
var tab4 = Ti.UI.createTab({
title: L('Map'),
icon: '/images/....',
window: thirdView
});
thirdView.containingTab = tab4;
var tab5 = Titanium.UI.createTab({
title : 'Tab 5'
});
var tabArray = [tab1, tab2, tab3, tab4, tab5];
for ( i = 0; i < tabArray.length; i++) {
self.addTab(tabArray[i]);
}
return self;
}
module.exports = TabView;

You can have a look at this post to disable a Tab within TabGroup.

Related

Tabulator - Dependent Select with Custom Editor

I need to show the list in the select box based on the another input.
On click on the SubCategory column, its showing the selected value in the dropdown. But its not showing in the table.
You can see the table in the below image. First image its not showing the data in the display, in the second image its showing the value selected
Anything missed. Any help please..
Attached the working code.
var comboEditor = function (cell, onRendered, success, cancel, editorParams) {
//Getting the other select value, based on the value this select need to show the list
let otherCellValue = cell.getData().ForumCourt;
cboData = []; //Store last values based on another cell value
var currentlyAdded = [];
var editor = document.createElement("select");
arrayOfValues2 = caselocationData.filter(function(r){return true;});
var filteredArrayOfValues = arrayOfValues2.filter(function(r){ return r[0]=== otherCellValue});
// addUniqueOptionsToDropdownList(select2_Sub, filteredArrayOfValues,1);
filteredArrayOfValues.forEach(function(r){
if(currentlyAdded.indexOf(r[0]) === -1) {
currentlyAdded.push(r[1]);
var item = {};
item.key = r;
item.name = r[1];
cboData.push(item);
}
});
for (var i = 0; i < cboData.length; i++) {
var opt = document.createElement('option');
opt.value = cboData[i].key;
opt.innerHTML = cboData[i].name;
editor.appendChild(opt);
}
editor.style.padding = "0px";
editor.style.width = "100%";
editor.style.boxSizing = "border-box";
editor.value = cell.getValue();
onRendered(function () {
editor.focus();
editor.style.css = "100%";
});
function successFunc() {
success(editor.value);
}
editor.addEventListener("change", successFunc);
editor.addEventListener("blur", successFunc);
return editor;
};

Set attributes object (text), with ID and NAME itself search. - KineticJS

I have a stage with a layer inside it and a group inside the layer.
If my object (var complexText = new Kinetic.Text()) has name: 'name1' and id: 'id5',
is it possible to change the fill and text with setFill() and setText() only by using the id?
My code is not working:
var stage = new Kinetic.Stage({ ... });
var layer = new Kinetic.Layer();
var group1 = new Kinetic.Group({ draggable: false });
layer.add(group1);
stage.add(layer);
var menuTab = new Kinetic.Rect({... , id: 'id1', name: 'name1'});
var complexText = new Kinetic.Text({... , id: 'id5', name: 'name1'});
group1.add(menuTab);
group1.add(complexText);
menuTab.on('click', function() {
var textChange = stage.get('#id5'); // didn't work
// and .... var textChange = layer.get('#id5');
// and .... var textChange = group1.get('#id5'); //didn't work
textChange.setFill('#BB9999');
textChange.setText('f3');
alert( textChange.getText() );
//this.setText('3');
layer.draw();
});
You have to use
var textChange = stage.get('#id5')[0];
// or .... var textChange = layer.get('#id5')[0];
// or .... var textChange = group1.get('#id5')[0];
textChange.setFill('#BB9999');
textChange.setText('f3');

How to move a popup window from a client handler?

I have a code that simulates a popup window (thanks to Waqar Ahmad) that is triggered by a client handler.
I would like to get this popup appear near the button that triggered it but with the script I have I see no way to move the window.
The code is below and the app is viewable here, if ever someone has an idea about how I should re-organise or change the script so that the popup window shows up near the button that fired the process ?
var choice = ['-','Choice 1','Choice 2','Choice 3','Choice 4']; // var definition
function doGet(){
var app = UiApp.createApplication().setStyleAttribute("background", "beige");
app.add(createMaskPanel_());//this is used to make popup panel modal
var mainPanel = app.createVerticalPanel().setStyleAttributes({'padding' : '15'});
app.add(mainPanel);
// idx holds the index value of the button that is pressed
var idx = app.createTextBox().setId('idx').setName('idx').setVisible(false);
mainPanel.add(idx);
//Make a panel for popup and add your popup elements
var popup = app.createVerticalPanel().setId('popup').setVisible(false)
.setStyleAttributes(
{'position': 'fixed',
'border' : '1px solid brown',
'padding' : '15',
'background' : 'beige',
'top' : '150PX',
'left' : '300PX',
'width' : '200',
'height':'120',
'zIndex' : '2'});
popup.add(app.createLabel('Select your choice').setId('label'));
var list = app.createListBox().setId('ppValue').setName('ppValue').setWidth('200')
.addItem(choice[0], '0').addItem(choice[1], '1').addItem(choice[2], '2').addItem(choice[3], '3').addItem(choice[4], '4');
popup.add(list);
var valHandler = app.createServerHandler('showVal').addCallbackElement(mainPanel).addCallbackElement(popup);;
popup.add(app.createButton('✖ Close / confirm').addClickHandler(valHandler));
app.add(popup);
var mask = app.getElementById('mask')
var ppHandler = app.createClientHandler().forTargets([popup,mask]).setVisible(true)
var flex = app.createFlexTable()
for(nn=1;nn<11;++nn){
flex.setText(nn,0,'Item nr '+nn)
var text = app.createTextBox().setHeight('26').setWidth('150').setId('val'+nn).setName('val'+nn)
flex.setWidget(nn,1,text);
var handler = app.createClientHandler().forTargets(idx).setText(nn).forTargets(text).setText('suggestion = ?');
flex.setWidget(nn,2,app.createButton('✐').setHeight('26').setId('btn'+nn).addClickHandler(handler).addClickHandler(ppHandler))
}
mainPanel.add(flex);
return app;
}
function createMaskPanel_(){ //Called when UI loads, initially it will be invisble. it needs to be made visible
var app = UiApp.getActiveApplication();
var mask = app.createVerticalPanel().setId('mask').setSize('100%', '100%') //maskPanel to mask the ui
.setStyleAttributes({
'backgroundColor' : '#F0F0F0',
'position' : 'fixed',
'top' : '0',
'left' : '0',
'zIndex' : '1',
'opacity' : '0.4'}).setVisible(false);
mask.add(app.createLabel('POPUP')
.setStyleAttribute('color', '#F0F0F0')
.setStyleAttribute('opacity', '0.6'));
return mask;
}
function showVal(e){
var app = UiApp.getActiveApplication();
var source = e.parameter.idx
var value = app.getElementById('val'+source)
value.setText('choice value = '+choice[e.parameter.ppValue])
var popup = app.getElementById('popup')
var mask = app.getElementById('mask')
popup.setVisible(false)
mask.setVisible(false)
return app
}
EDIT : Since the server handler seems to be the only way I gave it a try, the app is viewable here and the (final ?) code is below for info.
var choice = ['-','Choice 1','Choice 2','Choice 3','Choice 4','Choice 5','Choice 6','Last choice !'];//var definition
function doGet(){
var app = UiApp.createApplication().setStyleAttribute("background", "beige");
app.add(createMaskPanel_());//this is used to make popup panel modal
var top = '100PX'
var left = '265PX'
var mainPanel = app.createVerticalPanel().setStyleAttributes({'padding' : '15'});
app.add(mainPanel);
// item definitions
var idx = app.createTextBox().setId('idx').setName('idx').setVisible(false);
mainPanel.add(idx);
//Make a panel for popup and add your popup elements
var popup = app.createVerticalPanel().setId('popup').setVisible(false)
.setStyleAttributes(
{'position': 'fixed',
'border' : '1px solid brown',
'padding' : '10',
'background' : 'beige',
'top' : top,
'left' : left,
'width' : '200',
'height':'110',
'zIndex' : '2'});
popup.add(app.createLabel('Select your choice').setId('label'));
var list = app.createListBox().setId('ppValue').setName('ppValue').setWidth('160')
for(c in choice){list.addItem(choice[c], c)}
popup.add(list);
var valHandler = app.createServerHandler('showVal').addCallbackElement(mainPanel).addCallbackElement(popup);;
popup.add(app.createButton('✖ Close / confirm').addClickHandler(valHandler));
app.add(popup);
var idxHandler = app.createServerHandler('setidx').addCallbackElement(mainPanel)
var flex = app.createFlexTable()
for(nn=1;nn<11;++nn){
flex.setText(nn,0,'Item nr '+nn)
flex.setWidget(nn,1,app.createTextBox().setPixelSize(180,26).setId('val'+nn).setName('val'+nn));
flex.setWidget(nn,2,app.createButton('✐').setHeight('26').setId('btn'+nn).addClickHandler(idxHandler))
}
mainPanel.add(flex);
return app;
}
function setidx(e){
var app = UiApp.getActiveApplication();
var idx = app.getElementById('idx')
var idxval = Number(e.parameter.source.replace(/[a-z]/g,''))
idx.setValue(idxval);
var top = -30+38*idxval+'PX'
var left = '265PX'
var popup = app.getElementById('popup')
var mask = app.getElementById('mask')
var label = app.getElementById('label').setText('Select your choice (item '+idxval+')')
var value = app.getElementById('val'+idxval)
value.setText('suggestion = ?')
popup.setVisible(true)
mask.setVisible(true)
popup.setStyleAttributes(
{'top' : top,
'left' : left});
return app
}
function createMaskPanel_(){ //Called when UI loads, initially it will be invisble. it needs to be made visible
var app = UiApp.getActiveApplication();
var mask = app.createVerticalPanel().setId('mask').setSize('100%', '100%') //maskPanel to mask the ui
.setStyleAttributes({
'backgroundColor' : '#F0F0F0',
'position' : 'fixed',
'top' : '0',
'left' : '0',
'zIndex' : '1',
'opacity' : '0.6'}).setVisible(false);
mask.add(app.createLabel('POPUP')
.setStyleAttribute('color', '#F0F0F0')
.setStyleAttribute('opacity', '0.6'));
return mask;
}
function showVal(e){
var app = UiApp.getActiveApplication();
var source = e.parameter.idx
var value = app.getElementById('val'+source)
value.setText('choice value = '+e.parameter.ppValue+' ('+choice[Number(e.parameter.ppValue)]+')')
var popup = app.getElementById('popup')
var mask = app.getElementById('mask')
popup.setVisible(false)
mask.setVisible(false)
return app
}
Serge I did something simular using a dialogbox to get this kind of functionality.
In the proper function that shows the dialogbox I decide the position of the dialogbox.
I used it to enlarge a image so I just put the (entire) code I used for the dialogbox.
function showimg(e){
var app = UiApp.getActiveApplication();
//
// Style
//
var _showimg =
{
"position":"fixed",
"width":"200px", // here you can change size
"top":"100px", // and horizontal position maybe you can use your
"left":"100px", // your setidx function .
"opacity":"0.95",
"border":"none",
}
var _container =
{
"width":"90%",
"border":"none",
}
var _img= {
"background-color":"none",
"width":"90%",
"border":"4px solid f2f2f2",
}
var _btn= {
"background-color":"none",
"background":"none",
"width":"80px",
"height":"24px",
"border":"None",
"font-family":"hobo std",
"font-size":"0.9em",
"color":"3f3f3f",
"opacity":"1",
}
//
// aplication
//
var f = DocsList.find("YOURSPREADSHEET");
var id = f[0].getId();
var ss = SpreadsheetApp.openById(id);
var sheet = ss.getSheetByName("YOURSHEET");
var rows= sheet.getLastRow();
var cols = sheet.getLastColumn();
var dialogBox = app.createDialogBox(true, true).setId("dialogBox");
applyCSS(dialogBox, _showimg);
var cont = app.createAbsolutePanel().setId("cont").setVisible(true);
applyCSS(cont, _container);
var source = e.parameter.source;
for (var i = 1; i < rows ; i++) {
for (var j = 1; j <6 ; j++) {
if (source == "imgb"+[j]+[i]) {
if (j == 1) {
var img = app.createImage().setId('img').setUrl(sheet.getRange(i+1,[5]).getValue()).setVisible(true);
dialogBox.setText(sheet.getRange(i+1,[6]).getValue());
}
if (j == 2) {
var img = app.createImage().setId('img').setUrl(sheet.getRange(i+1,[7]).getValue()).setVisible(true);
dialogBox.setText(sheet.getRange(i+1,[8]).getValue());
}
}
app.getElementById( "imgb"+[j]+[i]).setEnabled(false);
//}
}
}
applyCSS(img,_img)
app.createImage().setId('img').setUrl("https://lh6.googleusercontent.com/-PTl6c-pfHoc/TzFvp1dteaI/AAAAAAAACTI/Mmx-7RU4i8g/s640/xxxxxxx.jpg").setVisible(true);
// applyCSS(img,_img)
var closeb = app.createButton("Close").setId("closeb").setTitle("close");
applyCSS(closeb,_btn);
var closeH = app.createServerClickHandler("closediag");
closeb.addClickHandler(closeH);
closeH.addCallbackElement(cont);
cont.add(img);
cont.add(closeb);
dialogBox.add(cont);
app.add(dialogBox);
return app;
}
The applyCss from James
function applyCSS(element, style){
for (var key in style){
element.setStyleAttribute(key, style[key]);
}
}
From what I've discovered so far using what I see in these replies, this methodology is positioning my widgets accordingly, but not the actual form itself. Unless, of course, I'm missing something, which is entirely possible. Thanks for the replies so far.

Flash CS6 ActionScript 3 Error #2025

I'm working on a webpage for a class and am trying to work the navigation using ActionScript 3. My understanding of how it should work is that when you click the links at the top, it removes whatever is currently displayed, using removeChild, and adds the new page's content using addChild.
It works fine when going from the initial page to one of the links. But whenever I go from a page that is not the home page to another page I get:
ArgumentError: Error #2025: The supplied DisplayObject must be a child
of the caller. at flash.display::DisplayObjectContainer/removeChild()
at nutshellMathReCoded4_fla::MainTimeline/hideOtherPages() at
nutshellMathReCoded4_fla::MainTimeline/runSubtraction()
Here is the code:
stop();
// Flash Imports
import flash.events.MouseEvent;
import flash.events.Event;
import flash.media.SoundMixer;
//Page Components //
// Home //
// Links
// Create Header & Nav //
// Logo Link
var headerLogo:logoMainPage = new logoMainPage();
headerLogo.x = 252.85;
headerLogo.y = 18.00;
//Addition Link
var additionLink:addPageLink = new addPageLink();
additionLink.x = 142.35;
additionLink.y = 96.00;
//Subtraction Link
var subtractionLink:subPageLink = new subPageLink();
subtractionLink.x = 208.60;
subtractionLink.y = 144.60;
// Multiplication Link
var multiplicationLink:mulPageLink = new mulPageLink();
multiplicationLink.x = 397.80;
multiplicationLink.y = 100.00;
// Division Link
var divisionLink:divPageLink = new divPageLink();
divisionLink.x = 597.95;
divisionLink.y = 144.60;
//Animation
var animation:mainAnimation = new mainAnimation();
animation.x = 99.90;
animation.y = 244.00;
//Addition //
var addSimpleX:additionSimpleX = new additionSimpleX();
addSimpleX.x = 41;
addSimpleX.y = 395.95;
var addSimpleY:additionSimpleY = new additionSimpleY();
addSimpleY.x = 364;
addSimpleY.y = 395.95;
var addSimpleAnswer:additionSimpleAnswer = new additionSimpleAnswer();
addSimpleAnswer.x = 701;
addSimpleAnswer.y = 395.95;
var additionAddSign:additionSign = new additionSign();
additionAddSign.x = 276.55;
additionAddSign.y = 360.20;
var additionEqualsSign:equalsSign = new equalsSign();
additionEqualsSign.x = 613.95;
additionEqualsSign.y = 360.20;
var addSum:additionSummary = new additionSummary();
addSum.x = 178.25;
addSum.y = 202;
var addTryOut:tryItOut = new tryItOut();
addTryOut.x = 205.70;
addTryOut.y = 475.65;
var addDDLink:digDeeperLink = new digDeeperLink();
addDDLink.x = 274.95;
addDDLink.y = 696;
var addTQLink:quizLink = new quizLink();
addTQLink.x = 465;
addTQLink.y = 696.50;
//Addition Deeper
var addLong:additionExtended = new additionExtended();
addLong.x = 193.00;
addLong.y = 323.00;
var addDDSum:additionDDSummary = new additionDDSummary();
addDDSum.x = 222.40;
addDDSum.y = 201.20;
var addDDB2B:backToBasicsLink = new backToBasicsLink();
addDDB2B.x = 271.95;
addDDB2B.y = 696;
var addDDTQ:quizLink = new quizLink();
addDDTQ.x = 468;
addDDTQ.y = 696;
//Subtraction
var subSimpleX:subtractionSimpleX = new subtractionSimpleX();
subSimpleX.x = 44;
subSimpleX.y = 408.50;
var subSimpleY:subtractionSimpleY = new subtractionSimpleY();
subSimpleY.x = 367;
subSimpleY.y = 408.50;
var subSimpleAnswer:subtractionSimpleAnswer = new subtractionSimpleAnswer();
subSimpleAnswer.x = 692.95;
subSimpleAnswer.y = 408.50;
var subtractionEqualsSign:equalsSign = new equalsSign();
subtractionEqualsSign.x = 612.80;
subtractionEqualsSign.y = 372.95
var subtractionSubSign:subtractionSign = new subtractionSign();
subtractionSubSign.x = 280.85;
subtractionSubSign.y = 371.95;
var subTryOut:tryItOut = new tryItOut();
subTryOut.x = 221.8;
subTryOut.y = 477.95;
var subDDLink:digDeeperLink = new digDeeperLink();
subDDLink.x = 274.95;
subDDLink.y = 696;
var subTQLink:quizLink = new quizLink();
subTQLink.x = 465;
subTQLink.y = 696.50;
var subSum:subtractionSummary = new subtractionSummary();
subSum.x = 147.30;
subSum.y = 210.05;
// Subtraction Dig Deeper
var subBudget:budget = new budget();
subBudget.x = 367.95;
subBudget.y = 400.90;
var subExpenses:expenses = new expenses();
subExpenses.x = 204.00;
subExpenses.y = 513.40;
var subDDT1:subtractionDD1 = new subtractionDD1();
subDDT1.x = 264.05;
subDDT1.y = 211;
var subDDT2:subtractionDD2 = new subtractionDD2();
subDDT2.x = 206.65;
subDDT2.y = 351;
var subDDT3:subtractionDD3 = new subtractionDD3();
subDDT3.x = 131.80;
subDDT3.y = 474.95;
var subDDT4:subtractionDD4 = new subtractionDD4();
subDDT4.x = 291.00;
subDDT4.y = 463;
var subCheckBudgetLink:checkBudgetLink = new checkBudgetLink();
subCheckBudgetLink.x = 437;
subCheckBudgetLink.y = 609.5;
var subB2BLink:backToBasicsLink = new backToBasicsLink();
subB2BLink.x = 271.95;
subB2BLink.y = 696;
var subDDTQLink:quizLink = new quizLink();
subDDTQLink.x = 468;
subDDTQLink.y = 696;
//Multiplication
var mulSimpleX:multiplicationSimpleX = new multiplicationSimpleX();
mulSimpleX.x = 30.85;
mulSimpleX.y = 395.35;
var mulSimpleY:multiplicationSimpleY = new multiplicationSimpleY();
mulSimpleY.x = 370.85;
mulSimpleY.y = 395.35;
var mulSimpleAnswer:multiplicationSimpleAnswer = new multiplicationSimpleAnswer();
mulSimpleAnswer.x = 691.90;
mulSimpleAnswer.y = 395.35;
var multiplicationMulSign:multiplicationSign = new multiplicationSign();
multiplicationMulSign.x = 284.60;
multiplicationMulSign.y = 365.95;
var mulEqualsSign:equalsSign = new equalsSign();
mulEqualsSign.x = 609.80;
mulEqualsSign.y = 356.95;
var mulSummary:multiplicationSummary = new multiplicationSummary();
mulSummary.x = 145.30;
mulSummary.y = 202.40;
var mulTryOut:tryItOut = new tryItOut();
mulTryOut.x = 218.80;
mulTryOut.y = 461.95;
var mulDDLink:digDeeperLink = new digDeeperLink();
mulDDLink.x = 274.95;
mulDDLink.y = 696;
var mulTQLink:quizLink = new quizLink();
mulTQLink.x = 465.00;
mulTQLink.y = 696;
// Multiplication Deeper
var mulDD1:multiplicationDD1 = new multiplicationDD1();
mulDD1.x = 241.15;
mulDD1.y = 209;
var mulDD2:multiplicationDD2 = new multiplicationDD2();
mulDD2.x = 297.05;
mulDD2.y = 350.40;
var mulDD3:multiplicationDD3 = new multiplicationDD3();
mulDD3.x = 316.75;
mulDD3.y = 393.65;
var mulDD4:multiplicationDD4 = new multiplicationDD4();
mulDD4.x = 297.55;
mulDD4.y = 436.90;
var mulB2BLink:backToBasicsLink = new backToBasicsLink();
mulB2BLink.x = 271.95;
mulB2BLink.y = 696;
var mulDDTQL:quizLink = new quizLink();
mulDDTQL.x = 468;
mulDDTQL.y = 696;
// Division
var divSimpleX:divisionSimpleX = new divisionSimpleX();
divSimpleX.x = 42;
divSimpleX.y = 397.5;
var divSimpleY:divisionSimpleY = new divisionSimpleY();
divSimpleY.x = 366.95;
divSimpleY.y = 397.50;
var divSimpleAnswer:divisionSimpleAnswer = new divisionSimpleAnswer();
divSimpleAnswer.x = 698.95;
divSimpleAnswer.y = 397.50;
var divisionDivSign:divisionSign = new divisionSign();
divisionDivSign.x = 277.80;
divisionDivSign.y = 360.95;
var divEqualsSign:equalsSign = new equalsSign();
divEqualsSign.x = 609.80;
divEqualsSign.y = 361.95;
var divSummary:divisionSummary = new divisionSummary();
divSummary.x = 112.50;
divSummary.y = 202.20;
var divTryOut:tryItOut = new tryItOut();
divTryOut.x = 218.80;
divTryOut.y = 466.95;
var divDDLink:digDeeperLink = new digDeeperLink();
divDDLink.x = 274.95;
divDDLink.y = 696;
var divTQLink:quizLink = new quizLink();
divTQLink.x = 274.95;
divTQLink.y = 696;
// Division Deeper
var divDD1:divisionDD1 = new divisionDD1();
divDD1.x = 239.60;
divDD1.y = 215.00;
var divDD2:divisionDD2 = new divisionDD2();
divDD2.x = 328.65;
divDD2.y = 336.70;
var divDD3:divisionDD3 = new divisionDD3();
divDD3.x = 308.95;
divDD3.y = 381.20;
var divB2BLink:backToBasicsLink = new backToBasicsLink();
divB2BLink.x = 271.95;
divB2BLink.y = 696;
var divDDTQLink:quizLink = new quizLink();
divDDTQLink.x = 468;
divDDTQLink.y = 696;
// Quiz
//Title
var titleQuiz:quizTitle = new quizTitle();
titleQuiz.x = 419.40;
titleQuiz.y = 192;
// Random Number Backgrounds
var quizBG1:shortTextBG = new shortTextBG();
quizBG1.x = 44.9;
quizBG1.y = 283;
var quizBG2:shortTextBG = new shortTextBG();
quizBG2.x = 368.95;
quizBG2.y = 283;
var quizBG3:shortTextBG = new shortTextBG();
quizBG3.x = 44.9;
quizBG3.y = 360.25;
var quizBG4:shortTextBG = new shortTextBG();
quizBG4.x = 368.95;
quizBG4.y = 360.25;
var quizBG5:shortTextBG = new shortTextBG();
quizBG5.x = 44.90;
quizBG5.y = 440.20;
var quizBG6:shortTextBG = new shortTextBG();
quizBG6.x = 368.95;
quizBG6.y = 440.20;
var quizBG7:shortTextBG = new shortTextBG();
quizBG7.x = 44.90;
quizBG7.y = 518.80;
var quizBG8:shortTextBG = new shortTextBG();
quizBG8.x = 368.95;
quizBG8.y = 518.80
// Signs
var quizAddSign:additionSign = new additionSign();
quizAddSign.x = 280.05;
quizAddSign.y = 251.90;
var quizSubSign:subtractionSign = new subtractionSign();
quizSubSign.x = 281.40;
quizSubSign.y = 323.80;
var quizMulSign:multiplicationSign = new multiplicationSign();
quizMulSign.x = 288.20;
quizMulSign.y = 414.05;
var quizDivSign:divisionSign = new divisionSign();
quizDivSign.x = 280.05;
quizDivSign.y = 489.20;
var quizAddEqualsSign:equalsSign = new equalsSign();
quizAddEqualsSign.x = 603.90;
quizAddEqualsSign.y = 251.90;
var quizSubEqualsSign:equalsSign = new equalsSign();
quizSubEqualsSign.x = 603.90;
quizSubEqualsSign.y = 330.55;
var quizMulEqualsSign:equalsSign = new equalsSign();
quizMulEqualsSign.x = 603.90;
quizMulEqualsSign.y = 409.20;
var quizDivEqualsSign:equalsSign = new equalsSign();
quizDivEqualsSign.x = 603.90;
quizDivEqualsSign.y = 489.20;
// Check quiz
var quizCheck:checkQuiz = new checkQuiz();
quizCheck.x = 369.95;
quizCheck.y = 626.60;
var answerWrong:wrongAnswer = new wrongAnswer();
var answerCorrect:correctAnswer = new correctAnswer();
// Home Page //;
// Create Header & Nav //
// Logo
addChild(headerLogo);
addChild(additionLink);
addChild(subtractionLink);
addChild(multiplicationLink);
addChild(divisionLink);
addChild(animation);
headerLogo.addEventListener(MouseEvent.CLICK, runIndexPage);
function runIndexPage(e:MouseEvent):void
{
// Hide other Pages
hideOtherPages();
addChild(animation);
animation.gotoAndPlay(1);
}
// Addition Page //
additionLink.addEventListener(MouseEvent.CLICK, runAddition);
function runAddition(e:MouseEvent):void
{
hideOtherPages();
createAdditionPage();
}
subtractionLink.addEventListener(MouseEvent.CLICK, runSubtraction);
function runSubtraction(e:MouseEvent):void
{
hideOtherPages();
createSubtractionPage();
}
multiplicationLink.addEventListener(MouseEvent.CLICK, runMultiplication);
function runMultiplication(e:MouseEvent):void
{
hideOtherPages();
createMultiplicationPage();
}
divisionLink.addEventListener(MouseEvent.CLICK, runDivision);
function runDivision(e:MouseEvent):void
{
hideOtherPages();
createDivisionPage();
}
//Global Functions
function createAdditionPage():void
{
addChild(addSimpleX);
addChild(addSimpleY);
addChild(addSimpleAnswer);
addChild(additionAddSign);
addChild(additionEqualsSign);
addChild(addSum);
addChild(addTryOut);
addChild(addDDLink);
addChild(addTQLink);
}
function createSubtractionPage():void
{
addChild(subSimpleX);
addChild(subSimpleY);
addChild(subSimpleAnswer);
addChild(subtractionSubSign);
addChild(subtractionEqualsSign);
addChild(subSum);
addChild(subTryOut);
addChild(subDDLink);
addChild(subTQLink);
}
function createMultiplicationPage():void
{
addChild(mulSimpleX);
addChild(mulSimpleY);
addChild(mulSimpleAnswer);
addChild(multiplicationMulSign);
addChild(mulEqualsSign);
addChild(mulSummary);
addChild(mulTryOut);
addChild(mulDDLink);
addChild(mulTQLink);
}
function createDivisionPage():void
{
addChild(divSimpleX);
addChild(divSimpleY);
addChild(divSimpleAnswer);
addChild(divisionDivSign);
addChild(divEqualsSign);
addChild(divSummary);
addChild(divTryOut);
addChild(divDDLink);
addChild(divTQLink);
}
function hideOtherPages():void
{
if(animation)
{
removeChild(animation);
SoundMixer.stopAll();
}
else if(addSimpleX)
{
removeChild(addSimpleX);
removeChild(addSimpleY);
removeChild(addSimpleAnswer);
removeChild(additionAddSign);
removeChild(additionEqualsSign);
removeChild(addSum);
removeChild(addTryOut);
removeChild(addDDLink);
removeChild(addTQLink);
}
else if(addLong)
{
removeChild(addLong);
removeChild(addDDSum);
removeChild(addDDB2B);
removeChild(addDDTQ);
}
else if(subSimpleX)
{
removeChild(subSimpleX);
removeChild(subSimpleY);
removeChild(subSimpleAnswer);
removeChild(subtractionSubSign);
removeChild(subtractionEqualsSign);
removeChild(subSum);
removeChild(subTryOut);
removeChild(subDDLink);
removeChild(subTQLink);
}
else if(subBudget)
{
removeChild(subBudget);
removeChild(subExpenses);
removeChild(subDDT1);
removeChild(subDDT2);
removeChild(subDDT3);
removeChild(subDDT4);
removeChild(subCheckBudgetLink);
removeChild(subB2BLink);
removeChild(subDDTQLink);
}
else if(mulSimpleX)
{
removeChild(mulSimpleX);
removeChild(mulSimpleY);
removeChild(mulSimpleAnswer);
removeChild(multiplicationMulSign);
removeChild(mulEqualsSign);
removeChild(mulSummary);
removeChild(mulDDLink);
removeChild(mulTQLink);
}
else if(mulDD1)
{
removeChild(mulDD1);
removeChild(mulDD2);
removeChild(mulDD3);
removeChild(mulDD4);
removeChild(mulB2BLink);
removeChild(mulDDTQL);
}
else if(divSimpleX)
{
removeChild(divSimpleX);
removeChild(divSimpleY);
removeChild(divSimpleAnswer);
removeChild(divisionDivSign);
removeChild(divEqualsSign);
removeChild(divSummary);
removeChild(divTryOut);
removeChild(divDDLink);
removeChild(divTQLink);
}
else if(divDD1)
{
removeChild(divDD1);
removeChild(divDD2);
removeChild(divDD3);
removeChild(divB2BLink);
removeChild(divDDTQLink);
}
else if(titleQuiz)
{
removeChild(titleQuiz);
removeChild(quizBG1);
removeChild(quizBG2);
removeChild(quizBG3);
removeChild(quizBG4);
removeChild(quizBG5);
removeChild(quizBG6);
removeChild(quizBG7);
removeChild(quizBG8);
removeChild(quizAddSign);
removeChild(quizSubSign);
removeChild(quizMulSign);
removeChild(quizDivSign);
removeChild(quizAddEqualsSign);
removeChild(quizSubEqualsSign);
removeChild(quizMulEqualsSign);
removeChild(quizDivEqualsSign);
removeChild(quizCheck);
//Dynamic Quiz Removal Section ****
}
}
This code looks terrifying, but I won't dive into it as it is not the merits of the question. The problem is that you are only checking (in function hideOtherPages()) an existence of the objects, and not if they are added to Stage. You cannot remove from stage an object that is not there, this is why you gets this error, and it states just that.
You can check if your objects are added to stage before you will try to remove them.
You can remove all children from an object by simple loop.
The second option is the best in this case. You would create a Sprite, and...
var myContainer:Sprite = new Sprite();
addChild(myContainer);
// Here you are adding children/first set of visible objects
myContainer.addChild(myObject);
// ...
And now just before you will add new set of objects to container you can call "clearContainer()" function to remove previous ones.
function clearContainer() : void {
while(myContainer.numChildren) {
myContainer.removeChildAt(0);
}
}
Your code will be GREATLY reduced because of this, as you won't be forced to remove every item manually...
Alternatively if you want to keep a brute force, you can just check if objects exist before remove them manually, and you can do this by using function getChildByName(name:String) . You can set a property "name" for your objects and then check if "getChildByName" will return object or null, and if it is an object, you would remove it. So at the beginning it would look like this:
var divisionLink:divPageLink = new divPageLink();
divisionLink.x = 597.95;
divisionLink.y = 144.60;
divisionLink.name = "divisionLink"; // setting a name
And your removing would look like this:
else if(divisionLink && this.getChildByName("divisionLink"))
{
removeChild(divisionLink);
}
And do this with every item. This is tedious and slow, so I wouldn't recommend it, but included it for educational purposes.

TabGroup within a NavGroup - Both navbars show and NavGroup title missing

I have an app that contains a messaging system. It consists of a TableView that splits off into two TabGroups, using a NavGroup (I'm using Ti 1.7.5).
The problem I'm seeing is two fold;
Both title bars of the NavGroup and the Tab are being displayed, and
The TabGroup's title is not being displayed in the NavGroup title bar.
The following screenshot illustrates both problems:
Code (please note this is heavily summarised):
csu.module.messages.createMainWindow = function() {
csu.module.messages.mainWindow = Ti.UI.createWindow($$.moduleMainWindow);
csu.module.messages.navGroupContainer = Ti.UI.createWindow($$.modalContainer);
var mainTableView = Ti.UI.createTableView($$.tableView);
csu.module.messages.navGroup = Ti.UI.iPhone.createNavigationGroup({
window: csu.module.messages.mainWindow
});
...
mainTableView.addEventListener('click', function(e){
// Event info
var index = e.index, section = e.section, row = e.row, rowData = e.rowData;
switch(index) {
case 0:
// inbox;
csu.module.messages.inboxView = csu.module.messages.createInboxView(); // returns the tabgroup
csu.module.messages.navGroup.open(csu.module.messages.inboxView);
break;
case 1:
// archive;
csu.module.messages.archiveView = csu.module.messages.createArchiveView(); // Returns another tabgroup
csu.module.messages.navGroup.open(csu.module.messages.archiveView);
break;
}
});
...
csu.module.messages.mainWindow.add(mainTableView);
csu.module.messages.navGroupContainer.add(csu.module.messages.navGroup);
}
csu.module.messages.createInboxView = function() {
var tabGroup = Ti.UI.createTabGroup({
title: 'Inbox',
navBarHidden: false,
backgroundColor: '#000000',
barColor: csu.ui.theme.headerColor // black
});
var criticalInbox = csu.module.messages.createListWindow(m_Config.MESSAGE_TYPE_CRITICAL, true);
csu.module.messages.criticalInboxTab = Ti.UI.createTab({
title: 'Critical',
icon: 'images/tab-critical.png',
window: criticalInbox
});
...
// two other tabs are created
tabGroup.addTab(csu.module.messages.criticalInboxTab);
tabGroup.addTab(csu.module.messages.importantInboxTab);
tabGroup.addTab(csu.module.messages.generalInboxTab);
return tabGroup;
};
csu.module.messages.createListWindow = function(listType, isInbox) {
var tabWindow, title, tableView;
switch(listType) {
case m_Config.MESSAGE_TYPE_CRITICAL:
title = 'Critical';
break;
case m_Config.MESSAGE_TYPE_IMPORTANT:
title = 'Important';
break;
case m_Config.MESSAGE_TYPE_GENERAL:
title = 'General';
break;
};
tableView = Ti.UI.createTableView();
var tableData = new Array();
tableView.setData(tableData);
tabWindow = Ti.UI.createWindow({
title: title,
navBarHidden: false
});
tabWindow.add(tableView);
return tabWindow;
}
Does anyone know of a work around or something to get the title in the Navigation bar from the TabGroup? Is this a bug?
Your assistance is appreciated.
Titanium discourage the use of tab groups within navigation groups as they are both window managers, displaying a titlebar at the top.
See: http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.UI.Window
While it doesn't look the same, a tabbed bar should be used instead.