Move cursor inside textarea to end - apache-flex

I have a text area control on a form that is supposed to accept 5 digit US zip codes. I have assigned the control a keyUp event that checks the number of characters entered until it reaches 5 then forces a new line.
public function forceNewLine(event:KeyboardEvent):void
{
var maxLineChars:int = 5;
var currentLine:int = 1;
var numChars:int;
numChars = (txtList.text.length);
currentLine = Math.round(txtList.text.length / 6);
if (numChars == (maxLineChars * currentLine))
{
txtList.text = txtList.text + "\n";
txtList.setCursorPosition()
//This is not a function I have defined but I think I need too..
}
}
<s:TextArea id="txtList" keyUp="forceNewLine(event)"/>
It works fine except that when the new line is inserted, the cursor moves to the beginning of the textarea. I want it to go to the end.

Try using the selectRange function of the spark textArea.
txtList.selectRange(txtList.text.length, txtList.text.length)

Related

Increment Cell Value by 1 using buttons (g.sheets)

I want to create some small buttons in my google sheet that add or substract the cell value incrementally.
Excuse my artistic abilities (I created the buttons in paint)
You would need to create the increment and decrement functions using Google Apps Script like this:
function increment1() {
var activeCell = SpreadsheetApp.getActiveSpreadsheet().getActiveCell();
var cellValue = activeCell.getValue();
activeCell.setValue(++cellValue);
}
function decrement1() {
var activeCell = SpreadsheetApp.getActiveSpreadsheet().getActiveCell();
var cellValue = activeCell.getValue();
activeCell.setValue(--cellValue);
}
function increment01() {
var activeCell = SpreadsheetApp.getActiveSpreadsheet().getActiveCell();
var cellValue = activeCell.getValue() + 0.1;
activeCell.setValue(cellValue);
}
function decrement01() {
var activeCell = SpreadsheetApp.getActiveSpreadsheet().getActiveCell();
var cellValue = activeCell.getValue() - 0.1;
activeCell.setValue(cellValue);
}
After saving the script, you can draw the buttons using Insert menu -> Drawing, then after you've finished the drawing and placed it onto the sheet, you can right click the drawing, then click on the three dots and select Assign Script:
Then type the function name on the dialog box that appears:
This would increment or decrement the value in the active/selected cell by 1 or 0.1, depending on the entered function.

How to find the clicked button in the action method

When I have a dialog and multiple buttons have the same click-callback (action method) I mostly want to know which button has been pressed. How do I do that?
Example:
class ButtonDialog : UIFrame{
void button_pressed(object self){
// how do I get this button
TagGroup pressed_button = ?;
result("The button " + pressed_button + " is pressed.\n");
}
object init(object self){
TagGroup dlg, dlg_items, button1, button2;
dlg = DLGCreateDialog("Press a button", dlg_items);
button1 = DLGCreatePushButton("Button 1", "button_pressed");
button1.DLGIdentifier("button1");
dlg_items.DLGAddElement(button1);
button2 = DLGCreatePushButton("Button 2", "button_pressed");
button2.DLGIdentifier("button2");
dlg_items.DLGAddElement(button2);
self.super.init(dlg);
return self;
}
}
object dialog = alloc(ButtonDialog).init();
dialog.pose();
In my current program I have multiple rows created from a TagGroup. Each row has multiple buttons doing the same thing but for their specific row. Therefore I need to know which button it is to get the row to modify. Also the length of the TagGroup and therefore the row count is not fixed. So I cannot create button1_pressed, button2_pressed, ... functions except with doing some weird stuff with code evaluation on the fly which I want to avoid if possible.
The fact that you cannot pass an argument in the simple call-back of a push-button is a bit of a bummer. The easiest solution (albeit not elegant) is to use simple-one-line-callback methods which are unique but themselves call a generalized method as in the code below.
Of course mile7 stated that the number of buttons isn't fixed at compile time, which is an issue here. But unless the (potential) number of buttons is legion, this approach is still the easiest and cleanest, and as each "hard coded" call-back is only one line with a very systemic change, it should be fairly trivial to use Notepad++ or similar to provide an extensive enough set of such calls. (It doesn't hurt if some of them are actually never used.)
class ButtonDialog : UIFrame{
void button_pressed(object self, string buttonID){
// how do I get this button
TagGroup pressed_button = self.LookUpElement(buttonID);
if ( pressed_button.TagGroupIsValid() )
result("The button " + buttonID + " is pressed.\n");
else
result("The button " + buttonID + " was not found!\n");
}
// Need to be done for each button
void button_pressed_0(object self) { self.button_pressed("button0"); }
void button_pressed_1(object self) { self.button_pressed("button1"); }
object init(object self){
TagGroup dlg, dlg_items
dlg = DLGCreateDialog("Press a button", dlg_items);
number nButtons = 2
for( number n=0; n<nButtons; n++ ){
TagGroup button = DLGCreatePushButton("Button " + n , "button_pressed_" + n);
button.DLGIdentifier("button" + n);
dlg_items.DLGAddElement(button);
}
self.super.init(dlg);
return self;
}
}
object dialog = alloc(ButtonDialog).init();
dialog.pose();
So I kind of found an answer which I can live with, but I'm still hoping for better results.
My current idea is to use DualStateBevelButtons. If a button gets clicked, the state changes and the callback is executed. Then all buttons are checked if they have a changed state. If so, this is the clicked button and the state is reset.
The very very big downside of this solution is, that there are only buttons with images allowed, no text is possible. So this is not really the general solution to work with.
rgbimage button_img = RGBImage("button-image", 4, 16, 16);
button_img = max(0, 255 - iradius / 8 * 255);
class ButtonDialog : UIFrame{
TagGroup buttons;
void button_pressed(object self){
for(number i = 0; i < buttons.TagGroupCountTags(); i++){
TagGroup button;
if(buttons.TagGroupGetIndexedTagAsTagGroup(i, button)){
if(button.DLGGetValue() == 1){
// this button is toggled so it is clicked
string identifier;
button.DLGGetIdentifier(identifier);
result("Button " + i + " (" + identifier + ") is clicked.\n");
// reset button state
button.DLGBevelButtonOn(0);
// do not continue searching, found pressed button already
break;
}
}
}
}
object init(object self){
TagGroup dlg, dlg_items, button1, button2;
dlg = DLGCreateDialog("Press a button", dlg_items);
buttons = NewTagList();
button1 = DLGCreateDualStateBevelButton("button1", button_img, button_img, "button_pressed");
buttons.TagGroupInsertTagAsTagGroup(infinity(), button1);
dlg_items.DLGAddElement(button1);
button2 = DLGCreateDualStateBevelButton("button2", button_img, button_img, "button_pressed");
buttons.TagGroupInsertTagAsTagGroup(infinity(), button2);
dlg_items.DLGAddElement(button2);
self.super.init(dlg);
return self;
}
}
object dialog = alloc(ButtonDialog).init();
dialog.pose();

Player character won't go in front of buildings

Ok, so I managed to get all the buildings to stay in place, but now for some reason, the player character won't go in front of the buildings.
I tried switching the places in the code where the if the command for checking if the character's going behind the building and the if-else for checking if it's going in front of the code, but nothing changed.
here's the code:
var _dg = depth_grid;
var _inst_num = instance_number(obj_depth_buildings);
//below is for resizing the grid
ds_grid_resize(depth_grid,2, _inst_num);
//below adds instance info to grid
var _yy = 0;
with (obj_depth_buildings)
{
_dg[# 0,_yy] = id;
_dg[# 1,_yy] = y;
_yy++;
}
//below sorts the grid so that the ones with the biggest y variables end up at the top
ds_grid_sort(_dg,1,false);
//below goes through the grid and identifies everything
var _inst;
_yy = 0;
repeat (_inst_num)
{
//below pulls out an id
_inst = _dg[# 0, _yy];
//below gets the instance execute depth
with(_inst)
{
_inst.depth= layer_get_depth("collision") + _yy;
with (obj_nonbuilding_depths)
{
if object_index.y > _inst.y
{
object_index.depth = (_inst.depth + 1);
}
else if object_index.y <= _inst.y
{
object_index.depth = (_inst.depth - 1);
}
}
}
_yy++;
}
you should change the object depth by change the leyar depth in GMS2

Angular-ui ui-scroll - how to make it work when scrolling up?

I'm using the angular-ui ui-scroll and it's great when I scroll down, keeps adding items as expected. However when I scroll up, it stops at the top of the last batch that I loaded. For example if I have 100 items and my buffer size is 10, and I've scrolled down so that items 61-70 are showing, when I scroll back up I want to see items 51-60. However I can't scroll up past item 61. I don't know what I'm doing wrong.
Here's the html:
<div row="row" ui-scroll="row in transactionSource" buffer-size="10" >{{row.data}}</sq-transaction>
Here's the script:
$scope.transactionSource = {
get: function (index, count, callback) {
if (index < 0) {
callback([])
}
else {
var buffer = 10;
var end = ctrl.nextIndex + buffer;
if (end > ctrl.transactions.length) end = ctrl.transactions.length;
var items = ctrl.transactions.slice(ctrl.nextIndex, end);
ctrl.nextIndex = end;
callback(items);
}
}
};
If it's related, when I console.log the index and count values received, after the first load of 10 I get an index of -9 (in which case I return an empty array - if I don't do this, the entire array gets loaded). When I scroll up, I don't get a console.log message at all so it's like the 'get' only gets called when scrolling down.
Thanks in advance for any and all help.
Your datasource looks wrong. Items retrieving (slicing in your case) should be based on index and count parameters that you have from the datasource.get method arguments. I'd like to post an example of datasource implementation where the result items array is limited from 0 to 100 and should be sliced from some external data array:
get: function(index, count, success) {
var result = [];
var start = Math.max(0, index);
var end = Math.min(index + count - 1, 100);
if (start <= end) {
result = externalDataArray.slice(start, end + 1);
}
success(result);
};
Hope it helps!

Depending source for drop down list

I have one drop down list in my pages that its source comes of below code. Now I like to put 1 text box adjusted on my drop down list and when I type on that, source of drop down list (DocumentNo) depend on what I type in the text box and when text box is null drop downs list shows all the (DocumentNo) , please help how I have to change my code,
protected void ddlProjectDocument_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
var query = from p in _DataContext.tblDocuments
orderby p.DocumentNo
select p;
int maxs = 0;
foreach (tblDocument v in query)
{
if (v.DocumentNo.Length > maxs)
maxs = v.DocumentNo.Length;
}
foreach (tblDocument vv in query)
{
string doctitle = vv.DocumentNo;
for (int i = vv.DocumentNo.Length; i < maxs; i++)
{
doctitle += " ";
}
doctitle += " | ";
doctitle += vv.TITLE;
// Use HtmlDecode to correctly show the spaces
doctitle = HttpUtility.HtmlDecode(doctitle);
ddlProjectDocument.Items.Add(new ListItem(doctitle, vv.DocId.ToString()));
}
}
First, I would highly recommend storing the result of that query at the beginning of the method into something like a session variable so that you don't have to continually query the database every time you hit this page.
Second, you should use the OnTextChanged event in ASP.NET to solve this problem. Put in the OnTextChanged attribute to point to a method in your code behind that will grab the query result values (now found in your session variable) and will reset what is contained in ddlProjectDocument.Items to anything that matched what was being written by using String.StartsWith():
var newListOfThings = queryResults.Where(q => q.DocumentNo.StartsWith(MyTextBox.Value));
At this point all you need to do is do that same loop that you did at the end of the method above to introduce the correct formatting.

Resources