How to use include? using their funcitons and change variables

You must Login before you can answer or comment on any questions.

var winAlert = Ti.UI.createWindow({})
 
 
var viewOpacity = Ti.UI.createView({
 
backgroundColor: "black",
 
opacity: 0.7
 
})
 
winAlert.add( viewOpacity )
 
 
var viewAlert = Ti.UI.createImageView({
 
backgroundImage: "/imagens/alertDialog/bg.png",
 
width: 250,
 
height: 163
 
})
 
 
var botao1 = Ti.UI.createButton({
 
image: "/imagens/alertDialog/botao1.png",
 
left: 10,
 
bottom: 5
 
})
 
viewAlert.add(botao1)
 
 
var labelSim = Ti.UI.createLabel({
 
font: {fontFamily:'Facebook Letter Faces',fontWeight:'bold', fontSize: 20 },
 
text: "Sim",
 
color: "white",
 
left: 40,
 
bottom: 10
 
})
 
viewAlert.add(labelSim)
 
 
var botao2 = Ti.UI.createButton({
 
image: "/imagens/alertDialog/botao2.png",
 
title: "Nao",
 
font: {fontFamily:'Facebook Letter Faces',fontWeight:'bold'},
 
right: 10,
 
bottom: 5
 
})
 
viewAlert.add(botao2)
 
 
var labelNao = Ti.UI.createLabel({
 
font: {fontFamily:'Facebook Letter Faces',fontWeight:'bold', fontSize: 20 },
 
text: "Não",
 
color: "white",
 
right: 40,
 
bottom: 10
 
})
 
viewAlert.add(labelNao)
 
 
var labelAlerta = Ti.UI.createLabel({
 
font: {fontFamily:'Facebook Letter Faces',fontWeight:'bold', fontSize: 20 },
 
text: "Você tem certeza?",
 
color: "white",
 
textAlign: "center",
 
width: 230,
 
top: 10
 
})
 
viewAlert.add(labelAlerta)
 
 
var labelAlertaText = Ti.UI.createLabel({
 
font: {fontFamily:'Facebook Letter Faces',fontWeight:'normal', fontSize: 15 },
 
text: "Você está prestes a deletar a lista de favoritos.",
 
color: "white",
 
textAlign: "center",
 
width: 230,
 
top: 40
 
})
 
viewAlert.add(labelAlertaText)
 
 
winAlert.add(viewAlert)
 
winAlert.open()
 
 
botao1.addEventListener( "click", function(){
 
//function of button1
 
winAlert.close()
 
} )
 
 
botao2.addEventListener( "click", function(){
 
//function of button2
 
winAlert.close()
this is the code that I have developed to make my custom alert dialog. my idea is to put this code in another. js and give an include in. js that I want to use this custom alert however, be able to change the text of the labels and the functions of the two buttons

anyone knows how to do this?

2 Answers

If you use Ti.Include, then at runtime, you will essentially have one giant app.js loaded with all your code in it.

labelAlerta.text = 'my new text'; is an example of how you would make your label text changes in an event.

— answered 9 months ago by Stephen Feather
answer permalink
5 Comments
  • for an exemple... I create an js called customAlert.js and put this code...

    in my app.js i need to give the include and then how do I acess the functions and variables?

    something like that

    var customAlert = Ti.include( "customAlert.js" )
    really don't know what to do now D:

    — commented 9 months ago by Douglas Hennrich

  • OK, couple of things:

    • Ti.Include will be going away in the future, you should embrace commonJS before that happens.
    • Ti.Include is just that, an include, not an assignment as you have tried to do here.
    • Ti.Include loads your code inline

    app.js

    // This is my First Line
    Ti.include('mysecondfile.js');
    // This is my Third Line
    mysecondfile.js
    // This is my Second line
    at runtime you essentially now have this:

    app.js

    // This is my First Line
    // This is my Second line
    // This is my Third Line

    — commented 9 months ago by Stephen Feather

  • In your code, you are trying to use Ti.include as require()

    — commented 9 months ago by Stephen Feather

  • Show 2 more comments

Your Answer

Think you can help? Login to answer this question!