Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Event Listener not working when called as a function

$
0
0

The MenuView sent a parameter to FirstView and a button.eventlistener must me trigger. The Button Event is clicked, but the function is not working o window is not moving using these method. Code bellow:

//Mode is the index from the MenuView
    if (mode >= 0){
        clickMenu();
MenuView
var self = Ti.UI.createView({   
        top:0,
        left:0,
        width:150
    });
 
    //// ---- Menu Table
    // Menu Titles
    var menuTitles = [
        {title: 'Menu 1'},
        {title: 'Menu 2'},
        {title: 'Menu 3'},
        {title: 'Menu 4'},
        {title: 'Menu 5'},
        {title: 'Menu 6'}
    ];
 
    // Tableview
    var tableView = Ti.UI.createTableView({
        top:30,
        font: { fontSize:11},
        data:menuTitles
    });
    self.add(tableView);
 
 
    tableView.addEventListener('click', function(e) {
        option = e.index;
        FirstView(option);
            //....if index = 0-5 change info in Second View...
    });
FirsView
var self = Ti.UI.createView({
        title:'Main Window',
        backgroundColor:'#28292c',
            barColor:'#28292c', 
            exitOnClose: true,
            height: 'auto',
            navBarHidden: true,
            width: 'auto',
            _moving: false,
            _startx: 0,
            _endx: 0,
            _toggle: false,
    });
 
    var header = Ti.UI.createView({
        backgroundColor:'#28292c',  
            top:0,
            left:0,
            height: 50,
            width:320,
            moving:false, // Custom property for movement
            axis:0 // Custom property for X axis
    });
 
    // Top left button
    var menuButton = Ti.UI.createButton({
        top:10,
        left:10,
        width:40,
        height:50,
        font: { fontSize:11},
        title:L('Menu'),
        //toggle:false // Custom property for menu toggle
    });
    header.add(menuButton);
 
    //EVENT Top left button
    menuButton.addEventListener('click', function(e){
    // If the menu is opened
    clickMenu();
    });
 
    function clickMenu(){
        Titanium.API.info('Button Clicked');
        if(win == 1){
                self.animate({
                    left:0, // Movie to Original Position 
                    duration:200,
                    curve:Ti.UI.ANIMATION_CURVE_EASE_IN_OUT,
                });
                win = 0;
            }
            // If the menu isn't opened
            else{
                self.animate({ 
                    left:150, // Move Left
                    duration:200,
                    curve:Ti.UI.ANIMATION_CURVE_EASE_IN_OUT,
                });
                win = 1;
                slide = 1;
            }
    }
    //Mode is the index from the MenuView
    if (mode >= 0){
        clickMenu();
    }

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>