I have an action script 2.0 request.
I have a flash movie with 7 check boxes. When the user has selected a total of 4 check boxes the flash movie goes to another frame.
I'll contain all the checkboxes in a movie clip called mcCheckBox.
I just need to the code to make it go to a new frame once four check boxes have been selected.
you need to create a counter that is incremented each time a checkbox is clicked , when the counter value is 4 , go to the next frame.
also you may have to keep an array of the boxes have been checked, in case a second click unchecks the box , in which case you would decrement the counter.
edit:
i don't use as2 , so i can only give you an example in as3...
i've added an Array of all the checkboxes names in order to filter the click events, if you click outside a checkbox, the event would be registered but you don't want to proceed with the code
import flash.events.MouseEvent;
var counter:int;
var allNames:Array = ['cb1', 'cb2' , 'cb3' , 'cb4'];
var boxesList:Array = [];
stop();
addEventListener(MouseEvent.CLICK , clickHandler );
function clickHandler(event:MouseEvent):void
{
var boxName:String = event.target.name;
//make sure the target is one of the checkboxes
if(allNames.indexOf(boxName ) != -1 )
updateCounter(boxName);
}
function updateCounter(bName:String):void
{
var index:int = boxesList.indexOf(bName);
if( index == -1 )
{
//add to the list of checked boxes
boxesList.push(bName );
//increment counter
++counter;
}else{
//remove from the list of check boxes
boxesList.splice(index , 1 );
//decrement counter
--counter;
}
if(counter == 4 )
gotoAndStop('nextFrame');
trace( counter );
}
Related
Im making a registration kind of google sheets project, where the amount of input is quite high, however the input in each cell only needs to be 1 number. It would therefore be usefull to have a script, which made the cursor jump to the cell below after input of 1 number.
efunction onEdit(e) {
var sheet = e.source.getActiveSheet();
var activeCell = sheet.getActiveCell();
var col = activeCell.getColumn();
var row = activeCell.getRow();
var value = activeCell.getValue();
if (value.length == 1) {
sheet.getRange(row + 1, col).activate();
}
}
However this only makes the cursor jump to the cell below the one which the input has been made, when another action is made, like clicking on 3rd cell. therefore not making the registrations easier.
Hope you can help.
The Google Sheets onEdit(e) trigger only runs when the user completes their data entry in a cell, usually by pressing Enter or Tab. You cannot watch individual characters as they are being entered.
What you can do, however, is let the user enter longer strings of digits in the cell, and when Enter is finally pressed, put each one of those digits in a cell of its own. You can then move the selection after the last digit that was thus filled down.
To do that, use String.split(), like this:
/**
* Simple trigger that runs each time the user hand edits the spreadsheet.
*
* Watches column Sheet1!A2:A as it is edited and splits digit strings such
* as 321654 or 321 654 into single digits 3, 2, 1, 6, 5, 4, and puts each
* digit in a cell of its own, stacking them vertically, starting at the
* cell where the digit string was entered.
* Moves the selection to the cell after the cell where last digit was put.
* Will happily overwrite values in cells under the cell that was edited.
*
* #param {Object} e The onEdit() event object.
*/
function onEdit(e) {
// version 1.0, written by --Hyde, 2 January 2023
// - see https://stackoverflow.com/a/74986570/13045193
if (!e) throw new Error('Please do not run the onEdit(e) function in the script editor window.');
if (!e.value
|| e.value.match(/[^\d\s]/i)
|| e.range.columnStart !== 1 // column A
|| e.range.rowStart < 2
|| !e.range.getSheet().getName().match(/^(Sheet1)$/i)) {
return;
}
const numbers = e.value
.replace(/\s/g, '')
.split('')
.map(n => [n]);
e.range
.offset(0, 0, numbers.length, 1)
.setValues(numbers)
.offset(numbers.length, 0, 1, 1)
.activate();
}
I am afraid that it is not possible to recognize what the users are typing until the edit is completely made. What you can do instead is to recognize if the value they have introduced is longer than 1 character and edit the cell by taking only the first character of what they introduce.
You can try the following script:
function onEdit(e) {
var ss = e.source;
var val = e.value;
var r = e.range;
if(val.length>1)
{
var x = val.substring(0,1);
}
r.setValue(x);
}
References:
Simple Triggers
Event Objects
setValue()
I want to create a conditional cell formation.
Say Column B has a value that is a live score:
In Column C, I want to create an if condition, like this:
if B>10, then C is YES.
However, as I mentioned, B column as live score, even if B falls below 10 afterward, I want C to remain unchanged. So essentially, I want C to remain at yes, once my live score condition hits.
Please let me know how to do it.
You can use the Apps Script editor with the code below:
function liveScorePass(){
var spreadsheet = SpreadsheetApp.getActiveSheet();
var i = 0;
Logger.log(i);
while (i == 0){
Logger.log('B1');
if (spreadsheet.getRange('B1').getValue() > 10){
spreadsheet.getRange('C1').setValue("YES");
Logger.log('C1');
i = 1;
}
else{
spreadsheet.getRange('C1').setValue("NO");
}
}
}
/* OPTIONAL FUNCTION*/
function onOpen(){
var ui = SpreadsheetApp.getUi();
// Or DocumentApp or FormApp.
ui.createMenu('Live Score Menu')
.addItem('Reset Script', 'liveScorePass') //creates a menu to start the script again
.addToUi();
var spreadsheet = SpreadsheetApp.getActiveSheet();
liveScorePass(); //starts the script whenever you open the spreadsheet.
}
It basically checks if your cell B1 is greater than 10. If it's not, the script keeps running indefinetly, but when it is, the value of C1 is set to YES and i is set to 1, breaking away from thw while loop, no longer changing the value of C1 independent of the value of B1.
Edit
To use it as a function rather than a tab on the toolbar menu, you can just call it as if it were a formula =LIVESCOREPASS(). However, this implicates three things:
You can't use any set*() methods, so you need to adapt you coding, leaving you with this:
function LIVESCOREPASS(){
var spreadsheet = SpreadsheetApp.getActiveSheet();
var i = 0;
Logger.log(i);
while (i == 0){
Logger.log('B1');
if (spreadsheet.getRange('B1').getValue() > 10){
var result1 = "YES";
Logger.log('C1');
i = 1;
return result1;
}
else{
var result2 = "NO";
return result2;
}
}
}
It won't allow changes in arbitrary cells other than the one you're using or its adjacents (not a problem here);
Every time you update your referenced cell (B1), the function is reset, so you'll lose the fix "YES" if it drops to 10 or below.
Here you can find the documentation on Custom Functions.
I'm super frustrated with this.
first for you to understand my code - My goal here is for the user to get randomly selected word appear to them in a way that every letter sits inside of a box.
Then if the user clicks on a button called "Pick a word", another word will be selected and the correct number of boxes will appear.
I have an array of words like this:
var word_group_1 = ["abolsh", "absorbent", "betrayal", "frutish", "commensurate", "eonfident", "zite"]
I'm using this function to select a random word from that array then splice it.. works perfectly:
function random_word_genereator() {
random = randomNumber(0, word_group_1.length);
//putting the chosen word from array in the chosen word variable
chosen_word = word_group_1[random]
//after we used the chosen word were removing it from the away
word_group_1.splice(random, 1)
//splitting the chosen word into an array
chosen_word_letters_arry = chosen_word.split("")
}
in a button click of "pick a word"- I'm creating 5 instances of a Movieclip I have in my library (just a blue box to put text in it) with text in at like this:
function create_boxes(e)
{
//to know which word has been displayed to the user//
old_word=chosen_word
random_word_genereator()
for (i=0;i<chosen_word.length;i++){
cell_boxes = new lib.cell_box();
stage.addChild(cell_boxes)
cell_boxes.name="cell_box"+i;
cell_boxes.x=(xlocation * i) + 50
cell_boxes.y = 80;
output = new createjs.Text();
cell_boxes.addChild(output)
output.text=chosen_word_letters_arry[i]
}
everything works fine on the first click As You Can View Here.
The word being selected and displayed on the stage
my problem is when I'm clicking Again on the button "pick a word"
its not deleting the correct number of boxes.
I'm putting visible false to the boxes which holds the "Old word" (the one I need to delete)
but As you can se here After I click again its getting messed up.
sometimes its's working, switches from 12 letter word, to a 4 one.
but it should be luck. I'm dying to get this to WORK! its for my school project.
Please help me!
Easy answer that will plug and play into your code:
js
...
//to know wichh word has been displayed to the user//
old_word=chosen_word
random_word_genereator()
for (i = 0; i < stage.numChildren; i++) // Loop through all children of the stage
if (stage.getChildAt(i) is lib.cell_box) // Checks if the child is a lib.cell_box
stage.removeChildAt(i--); // Removes child from stage and decrements i
for (i=0;i<chosen_word.length;i++){
...
Original answer (cleaner code, some restructuring):
It's best to break this kind of logic down into steps.
var boxes:MovieClip = new MovieClip();
boxes.y = 80;
addChild(boxes);
...
function createBoxes(word:String):void {
// Remove boxes first
while (boxes.numChildren > 0)
boxes.removeChildAt(0);
// Add boxes
for each(var c:String in word.split("")) {
var box:Box = new Box(c);
box.x = boxes.width + 50;
boxes.addChild(box);
}
}
Then set the text inside a Box class.
I made a function to get the closer feature to the one clicked. I use Openlayers 3.9.0 and the getClosestFeatureToCoordinate method.
var select = new ol.interaction.Select();//simple click interaction
map.addInteraction(select);//add it to the map
select.on('select', function(e) {
//get the extent of the first selected feature
var aa = e.selected[0].getGeometry().getExtent();
//in case of line or polygon get the center of that extent
var oo = ol.extent.getCenter(aa);
//use it to get the name of the closest feature
console.log((sourceVector.getClosestFeatureToCoordinate(oo)).get("mylayer_name")) ;
});
But in a case like the following
if I click the "u" Polygon (bottom down) I get "u" instead of , say, "e"
if I click any point I get its name , instead of the closest feature's name. I click "testpoint9" and I get "testpoint9" instead of "u" or "e". I click "h" and I get "h" instead of "p" or "k".
So maybe has to do with points, so I changed the select.on event function to
select.on('select', function(e) {
var closestType = e.selected[0].getGeometry().getType();
var oo;
if (closestType === 'Point'){
oo = e.selected[0].getGeometry().getCoordinates();
}
else{
var aa = e.selected[0].getGeometry().getExtent();
oo = ol.extent.getCenter(aa);
}
console.log("---------------------------------------------------");
console.log("Name: "+sourceVector.getClosestFeatureToCoordinate(oo).get('mylayer_name'));
})
and still nothing. So, how I fix this?
Thanks
When You click inside the "u" polygon - the distance to it is 0.
When you click on something - that thing will always be the closest (to itself).
What you can do there, is removing the clicked element from the layer, run the algorithm (without clicked point) and put the point back on the layer.
If You are afraid that point could be invisible for too long (but it shouldn't), place it in another layer for the time of algorithm.
select.on('select', function(e) {
var clicked = e.selected[0];
sourceVector.removeFeature(clicked);
var closest = sourceVector.getClosestFeatureToCoordinate(e.coordinate);
sourceVector.addFeature(clicked);
var closestType = closest.getType();
if (closestType === 'Point'){
oo = e.selected[0].getGeometry().getCoordinates();
}
else{
var aa = e.selected[0].getGeometry().getExtent();
oo = ol.extent.getCenter(aa);
}
})
I have a property called FitToPlay and it contains a list of Players that are not injured. What I want to do is make a drop down box for each position in a team and only fill the drop down box with the players in the fit to play list that have the position in question as either their primary or secondary position.
What I want to know is how can I just display specific objects using html drop down box helper.
Many thanks in advance.
J
I think you would want to loop through each position and inside the loop go through all the currently FitToPlay players and if either his first or secondary position is the currently looped through position then insert him into it.. in the end if someone was inserted create a dropdownlist
So something like..
//Loop through all the positions
foreach (var position in Model.positions)
{
//Create a list for each position
List<SelectListItem> playersInPosition = new List<SelectListItem>();
//Only loop through players with the current position as either primary or secondary
foreach(var player in Model.FitToPlay.Where(pl => pl.primary == position || pl.secondary == position))
{
//Put this player into the list
playersInPosition.add(new SelectListItem { Text = player.name, Value = player.id});
}
//If at least one fits the criteria make a drop down list from it
if(playersInPosition != null && playersInPosition.Count > 0)
{
#Html.DropDownList(position.name, playersInPosition);
}
}