Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

use api ...

Hi,
maybe its a stupid question, i just start to use titanium.
I have a problem. I don't understaind how use api.
I have a file index.html with :

<html><head><script>var menu = Titanium.UI.createMenu();  

  var file = menu.addSubMenu("File");  
   var help = menu.addSubMenu("Help");  
   file.addItem("Open", function () { alert('Do open');});  
   file.addSeparator();  
   file.addItem("Exit", function () { Titanium.App.exit(); });  

   help.addItem("About", function () { alert('Show about box here');  });  
   Titanium.UI.setMenu(menu);
 </script></head><body style="background-color:#1c1c1c;margin:0">
<div style="border-top:1px solid #404040">
<div style="color:#fff;;padding:10px">TEST !!!
<br /></div></div></body></html>

but the api don't work …
why ?
thanks !

— asked March 12th 2010 by Mathieu Matheod
  • api
0 Comments

6 Answers

  • Well, after some testing i came up with an working js snippet.

    <script>
    var menu = Titanium.UI.createMenu();
    // Menu var
    
    var testMenuItem = menu.addItem("Test"); 
    // add "Test" item to menu
    
    var testSub = Titanium.UI.createMenu(); 
    // Test item submenu
    
    testSub.addItem("Test1",function () { alert('Test1');});
    testSub.addItem("Test2",function () { alert('Test2');});
    testSub.addSeparatorItem();
    testSub.addItem("Test3",function () { alert('Test3');});
    testSub.addItem("Test4",function () { alert('Test4');});
    // Add menu items
    
    testMenuItem.setSubmenu(testSub);
    // Set as submenu
    
    Titanium.UI.setMenu(menu);
    // Set the whole menu
    
    </script>
    

    Hope this helps.

    — answered March 14th 2010 by Jeremy G
    permalink
    0 Comments
  • If you are starting out I would recommend setting up the KitchenSink app and learning from there:

    http://github.com/appcelerator/KitchenSink

    Also, check out the webinars.

    — answered March 12th 2010 by John Welch
    permalink
    0 Comments
  • You need to put your javascript in between script tags.

    — answered March 12th 2010 by David Crawford
    permalink
    0 Comments
  • thanks for your answer.

    With script tag, the scritp don't work to …
    but i go to see the kitchensink link ;-)

    — answered March 12th 2010 by Mathieu Matheod
    permalink
    0 Comments
  • The kitcheninks is for mobile developpement.
    I search for desktop developpement :-(

    — answered March 12th 2010 by Mathieu Matheod
    permalink
    0 Comments
  • up

    — answered March 13th 2010 by Mathieu Matheod
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.