I have two window :
window1 : have an option_dialog width 3 option : 'Video','Image','Document'
var optionsDialogOpts = {
options:['Video','Image','Document'],
title:'Type'
};
var dialog_search_click = Titanium.UI.createOptionDialog(optionsDialogOpts);
dialog_search_click.addEventListener('click',function(e){
//spinner_search_click.setTitle(e.index);
if(e.index==0)
{
//save option select All
Ti.App.Properties.setString('option_dialog','0');
}
if(e.index==1)
{
Ti.App.Properties.setString('option_dialog','1');
}
if(e.index==2)
{
Ti.App.Properties.setString('option_dialog','2');
}
})
window2 : display option that selected in window1..
var option=Ti.App.Properties.getString('option_dialog');
Ti.API.info(option);
In the first time, option is displayed in window2 is true but when click back to window1 and select other option in option_dialog and go to window 2,it also only display option as the first time ,not change.Can you help me.
This code is right but, I thought one error with this.
your window1 and window2 both code in one .JS file. so this problem is ocurring.
var option=Ti.App.Properties.getString('option_dialog');
This line is not update always, it store information once.
You try this type,
add a new Button on Second window and check on Click Event this is working properly.
button.addeventListener('click',function(){
var option=Ti.App.Properties.getString('option_dialog');
alert("Option :- " + option);
});
If, this is working then. I think you can understand, What i want to say.
Cheers.....!
Related
I want to load the page https://game.ultimate-bridge.com/table/ in PhantomJS, choose tournament or 4-hand, populate table and board and then click the load hand.
I have mainly tried to click the button "Load Hand" but not even that is going well.
if ("complete" === readyState) {
console.log("if " + readyState);
var x = document.getElementById("root").querySelectorAll(".jss7.jss46.jss51");
x.click();
console.log("klick");
} // if-statement
The button do not get clicked
page.evaluate(function() {
var ev = document.createEvent("MouseEvents");
ev.initEvent("click", true, true);
document.querySelector("div.jss7.jss46.jss51 button[type='submit']").dispatchEvent(ev);
});
I've binded the same function to all elements that I want(let's say View and Label).
In this onClick handler function I want to get the element which was clicked and increase its 'top' by 1.
Please tell me if you know how to do that, I can't find an answer yet.
My global click handler function:
function increaseElementTop(e) {
// Here we should increase element's top position.
Ti.API.info(JSON.stringify(e));
}
Thanks, any help is appreciated.
Get the e.source attribute from the Event e. Then use the setTop() method.
if (e.source == $.yourLabel) {
$.yourLabel.setTop($.yourLabel.getTop() + 1)
}
UPDATE: Regarding your comment: I thought it would only be used for two elements. A universal approach would be something like this:
e.source.setTop(e.source.getTop() + 1);
Unfortunately I have no machine available to test the code but I will do so later (Tuesday I guess). Just try it and let your programm print the e.source variable. If this does not work you can also try to use e.source.getId().
function increaseElementTop(e) {
var theUIElement = e.source;
theUIElement.top = theUIElement.top + 1;
}
Add the event listener to each of your UIElements, and this will get the element you click on & modify the top.
I want to create a scoring system. I have 4 buttons with 4 different but similar scripts and want to share 1 GUI Text for the scores. Example Code:
var something : Sprite;
var SpriteRenderer : SpriteRenderer;
var score : int = 0;
var guiScore : GUIText;
function OnMouseDown () {
if(SpriteRenderer.sprite == something) {
score += 1;
guiScore.text = "Score: " = score;
}
}
Right now, if I pressed a button and got a point then I pressed a different button the score would start from 0 again. How can I share data something like static variables but different scripts? I know this sounds a bit noobie but any help would be much appreciated. Thanks in advance
Static variables won't appear in the inspector so you can't assign the GUIText in the inspector (thanks for making me find out). So try using GetComponent instead:
// make a variable of type GUIText
var guiScore: GUIText;
// assign the gameobject in the inspector
var staticObject: GameObject;
// Again I don't know the name of your script, so I'll name it StaticScript
// get the script
StaticScript scr = staticObject.GetComponent(StaticScript);
// assign local GUIText with the one from above
guiScore = scr.guiScore;
This way you have already shared 1 GUIText for all other scripts.
However you said:
Right now, if I pressed a button and got a point then I pressed a
different button the score would start from 0 again
Doesn't that mean something is wrong with the score, not the GUIText?
I am trying to create a simple safari extension. My current version of Safari is 5.1.7 running in Snow Leopard.
I have 2 documents :
global.html
<!DOCTYPE HTML>
<script>
safari.application.addEventListener("command", performCommand, false);
function performCommand(event) {
if (event.command === "traducir") {
var query = event.userInfo;
alert(query);
query = query.replace(/\s+/g,"+");
var newTab = safari.application.activeBrowserWindow.openTab();
newTab.url = "http://translate.google.es/#en/es/" + query ;
}
}
</script>
and the injected script : injected.js
document.addEventListener("contextmenu", handleMessage, false);
function handleMessage(msgEvent) {
var sel = '';
sel = window.parent.getSelection()+'';
sel = sel.replace(/^\s+|\s+$/g,"");
safari.self.tab.setContextMenuEventUserInfo(msgEvent, sel);
}
The extension is very simple :
1- When the user selects one text or word, click right-button and select the item of the contextual menu that raise the function.
2- The injected file gets the value of the selected text and it shared with the global.html through the userInfo.
3- The global.html script open a new tab with the url of google translate.
The problem is that event.userInfo is always NULL. I was searching in Google and all the examples are like this and I donĀ“t know where the problem is and why it returns always NULL.
This could possibly be due to a too strict setting for "Access Level" in the Extension Builder. Try setting the dropdown menu to "All", and tick the "Include Secure Pages" checkbox.
I am having real confusion with some flash banners I'm creating and making the button into a clickable object which opens a web page.
I have been using this code for a while below, which works...
on(release){
getURL("http://www.the-dude.co.uk", "_blank");
}
And I placed this code on actual button within the actions panel
However I have been told the code above is very old and that I should use action script like below...
buttonInstance.onRelease = function() {
getURL("http://www.the-dude.co.uk", "_blank");
}
So I've tried to get this method below to work but nothing happens when I click the button, and I get one error, this...
So in a nutshell I cannot get this newer code to work! Ahh
Can anyone please help me understand where I am going wrong?
I have tried placing the new code in the Scene 1 of my actions. No worky..
And I've also tried placing the code below, actually on my button within the actions panel...
this.onRelease = function() {
getURL("http://www.the-dude.co.uk", "_blank");
}
Still not working.
My scene settings are alway this...
Any help would be great thanks.
You need to place the code below on the same timeline as the instance of the button (as you tried). And the instancename of the button must be "buttonInstance".
You can set the instance name in the properties panel when the button is selected.
buttonInstance.onRelease = function() {
getURL("http://www.the-dude.co.uk", "_blank");
}