now browsing by tag
Hi all, this is a question for the more experienced script programmers.
After some searching I found this: http://stackoverflow.com/questions/1646698/what-is-the-new-keyword-in-javascript
I implemented this in a small example script:
dummy = LL.getCurrentDesktop().addShortcut(“dummy”,new Intent(),0,0);
// OLD WAY
/*
function displayCenter(it, center){
it.setLabel(center[0]+”,”+center[1]);
}
function moveToCenter(it, center){
it.setPosition(center[0], center[1]);
}
function center(item){
var r=item.getRotation()*Math.PI/180;
var sin=Math.abs(Math.sin(r));
var cos=Math.abs(Math.cos(r));
var w=item.getWidth()*item.getScaleX();
var h=item.getHeight()*item.getScaleY();
return[item.getPositionX()+(w*cos+h*sin)*0.5,item.getPositionY()+(h*cos+w*sin)*0.5];
}
var center = center(dummy);
displayCenter(dummy, center);
moveToCenter(dummy, center);
*/
//NEW WAY:
myItem = function(){
this.getCenter = function(){
if(this.center==null){
alert(“test”)
var r=this.getRotation()*Math.PI/180;
var sin=Math.abs(Math.sin(r));
var cos=Math.abs(Math.cos(r));
var w=this.getWidth()*this.getScaleX();
var h=this.getHeight()*this.getScaleY();
var center = [this.getPositionX()+(w*cos+h*sin)*0.5,this.getPositionY()+(h*cos+w*sin)*0.5]
this.center = center;
}
return this.center;
};
this.displayCenter = function(){
this.setLabel(this.getCenter()[0]+”, “+this.getCenter()[1]);
};
this.moveToCenter = function(){
this.setPosition(this.getCenter()[0], this.getCenter()[1]);
};
};
myItem.prototype = dummy;
myDummy = new myItem();
myDummy.displayCenter();
myDummy.moveToCenter();
myDummy.setSize(288, myDummy.getHeight()) //ALSO STILL WORKS BOTH WORK ON SAME OBJECT DESPITE THAT I DIDN’T DEFINE A getPositionX() IN myItem 😀
As you can see this enables me to do what I explained herebove, but I haven’t seen anyone do it before, so I am wondering if there is anything bad happening here or I actually found something cool and useful.
Please tell me what you think in the comments.
Thanks for reading 🙂
cdfa
]]>Hi all, this is a question for the more experienced users: I was looking at ways to optimize my code and I found…
I implemented this in a small example script:
dummy = LL.getCurrentDesktop().addShortcut(“dummy”,new Intent(),0,0);
myItem = function(){
this.getCenter = function(){
var r=this.getRotation()*Math.PI/180;
var sin=Math.abs(Math.sin(r));
var cos=Math.abs(Math.cos(r));
var w=this.getWidth()*this.getScaleX();
var h=this.getHeight()*this.getScaleY();
return[this.getPositionX()+(w*cos+h*sin)*0.5,this.getPositionY()+(h*cos+w*sin)*0.5];
};
};
myItem.prototype = dummy;
myDummy = new myItem();
alert(myDummy.getCenter()[0])
alert(myDummy.getPositionX()) // BOTH WORK ON SAME OBJECT AND DIDN’T DEFINE A getPositionX() IN myItem 😀
I never seen anyone use this, so I was wondering if there is anything that makes this very inefficient or I actually discovered something pretty cool.
Thanks for reading 🙂
Colin
]]>Quick question: would it be more efficient for a script that is executed lots of times per second to get data with…
Might sound kinda stupid, but just to be sure…
]]>I just got this idea that I think wouldn’t be relatively easy to implement and would be really useful, especially…
In 12.5.1 dynamic texts are untouchable.
I have a script with only this line:
alert(LL.getEvent().getSource())
When i put the script on an touch event of an item event.getSource() somehow returns the source of the event that was fired before I touched the item. (For example it would say C_RESUMED if I had just switched to that desktop)
]]>Does anybody know a way to use a custom xml layout file for the childView in a expandable list?
This might be suggested before, or there might already be a known way of doing it, but is there a way to get all the…
New script if you want to have multiple things happen on the same event.
1:I don’t know of there is a special reason I’m missing this is how it is, but it I make an item invisible with…
2: I thought there used to be an option to turn this off, but since there is also snapping (I think that’s how it’s called) to the edges of items when you are moving an item in edit mode and not only to the center of another item I can’t find it anymore. I actually like the item snapping, but the thing that I would really like an option for or to be turned off by default is that the snapping also works with invisible items. I use quite a lot invisible items in a small space and it gets a bit annoying seeing all the bounding boxes because now the items is just snapping from place to place.
I might be asking for things that not a lot of people would use, but if you can find the time I would really like to see them implemented :).
Thanks for a great launcher
Colin
]]>