CreateJS Tick function not updating from external values. - createjs

I think this might be quite basic, I'm still learning CreateJS. I won't include all the code as its a large program but basically.
Outside of my tick function I have this code:
var hitOrMiss = 'Mada';
function hit()
{
hitOrMiss = 'Hit';
//alert(hitOrMiss);
}
function miss()
{
hitOrMiss = 'Miss';
//alert(hitOrMiss);
}
When I click a button and call these they are testing ok (alerting out the values).
Inside my tick() function the values are not being picked up.
if(hitOrMiss = 'Mada')
{
var basic = 'basic';
}
else if(hitOrMiss = 'Hit')
{
if(gamePrincessBmpAnimation.x < 1000)
{
gamePrincessBmpAnimation.x += gamePrincessBmpAnimation.vX;
var basic = 'Not basic';
}
}
else if(hitOrMiss = 'Miss')
{
if(gamePrincessBmpAnimation.x > 60)
{
gamePrincessBmpAnimation.x -+ gamePrincessBmpAnimation.vX;
var basic = 'Miss Not basic';
}
}
Do I need to specify a listener, if so how should it be set up?
I have already triggered the below, Does something similar need to be added to the tick function?
createjs.Ticker.addListener(window);
createjs.Ticker.useRAF = true;
createjs.Ticker.setFPS(60);
gameStage.update();
The other if statements within the tick function are all firing, an example of which:
if (bmpAnimation.x >= screen_width - 16) {
// We've reached right side of our screen
// We need to walk left to go back to our initial position
bmpAnimation.direction = -90;
}
Any help would be appreciated! :)

Fixed this one, wasn't a createJS issue, was a silly Javascript issue, the code here: else if(hitOrMiss = 'Hit') should have been else if(hitOrMiss == 'Hit') etc.

Related

Installable Trigger Failing with Test Add-On

I have been wrestling with an installable trigger issue for a couple of days now. All of my research indicates that an add-on should allow for an installable onEdit() trigger within a spreadsheet, but my attempts keep erroring out. I have simplified my project code a bit to exemplify my issue.
The error message:
Execution failed: Test add-on attempted to perform an action that is not allowed.
My code (listing functions is the order that they are called):
function onOpen() //creates custom menu for the evaluation tool ***FOR ADMININSTRATORS ONLY***
{
var ui = SpreadsheetApp.getUi();
if(!PropertiesService.getDocumentProperties().getProperty('initialized'))
{
ui.createMenu('Evaluation Menu') // Menu Title
.addItem('Create Installable OnEdit Trigger', 'createInstallableOnEditTrigger')
.addToUi();
}
else
{
ui.createMenu('Evaluation Menu') // Menu Title
.addSubMenu(ui.createMenu('Manage Observations & Evidence')
.addSubMenu(ui.createMenu('Create New Observation')
.addItem('Formal', 'createNewFormalObservation')
.addItem('Informal', 'createNewInformalObservation')
)
.addToUi();
}
}
function createInstallableOnEditTrigger() { // installable trigger to create employee look-up listener when user edits the EIN fields on the Documentation Sheet.
var ss = SpreadsheetApp.getActive();
ScriptApp.newTrigger('onEditListener')
.forSpreadsheet(ss)
.onOpen()
.create();
PropertiesService.getDocumentProperties().setProperty('initialized','true');
}
function onEditListener(event) //this function conitnually listens to all edit, but only engages only certain conditions such as when a timestamp is determined to be needed or the Documentation Sheet needs to be auto-populated
{
//Determine whether or not the conditions are correct for continuing this function
var sheetName = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getName(); //determines the name of the currently active sheet
if (sheetName.indexOf("Evidence") > -1) // if the active sheet is an evidence collection sheet, a timestamp may be needed
{
populateEvidenceTimeStamp(event, sheetName);
}
else if (sheetName == "Documentation Sheet") //if the active sheet is the "Documentation Sheet" than auto-population and EIN lookups may be needed
{
employeeLookup(event, sheetName);
}
}
What am I missing? Any help is greatly appreciated!!
The below code has been added as requested by #Mogsdad.
populateEvidenceTimeStamp() is dependent upon generateTimeStamp() which is also included below:
function populateEvidenceTimeStamp(event, sheetName)
{
var evidenceColumnName = "Evidence";
var timeStampColumnName = "Timestamp";
var sheet = event.source.getSheetByName(sheetName);
var actRng = event.source.getActiveRange();
var indexOfColumnBeingEdited = actRng.getColumn();
var indexOfRowBeingEdited = actRng.getRowIndex();
var columnHeadersArr = sheet.getRange(3, 1, 1, sheet.getLastColumn()).getValues(); // grabs the column headers found in the 3rd row of the evidence sheet
var timeStampColumnIndex = columnHeadersArr[0].indexOf(timeStampColumnName); //determines the index of the Timestamp column based on its title
var evidenceColumnIndex = columnHeadersArr[0].indexOf(evidenceColumnName); evidenceColumnIndex = evidenceColumnIndex+1; //determines the index of the evidence column based on its title
var cell = sheet.getRange(indexOfRowBeingEdited, timeStampColumnIndex + 1); //determines the individual timestap cell that will be updated
if (timeStampColumnIndex > -1 && indexOfRowBeingEdited > 3 && indexOfColumnBeingEdited == evidenceColumnIndex && cell.getValue() == "") // only create a timestamp if 1) the timeStampColumn exists, 2) you are not actually editing the row containing the column headers and 3) there isn't already a timestamp in the Timestamp column for that row
{
cell.setValue(generateTimeStamp());
}
}
function generateTimeStamp()
{
var timezone = "GMT-7"; // Arizona's time zone
var timestamp_format = "MM.dd.yyyy hh:mm:ss a"; // timestamp format based on the Java SE SimpleDateFormat class. http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
var currTimeStamp = Utilities.formatDate(new Date(), timezone, timestamp_format);
return currTimeStamp;
}
Below is the employeeLookup() function which is dependent upon lookupEIN()
function employeeLookup(event, sheetName)
{
if(sheetName == "Documentation Sheet" && !PropertiesService.getDocumentProperties().getProperty('initialized')) // if the activeSheet is "Documentation Sheet" and the sheet has not yet been initialized
{
var actRng = event.source.getActiveRange();
Logger.log("employeeLookup(): actRng: "+actRng.getRow()+" , "+actRng.getColumn());
if(actRng.getRow() == 4 && actRng.getColumn() == 9 && event.source.getActiveRange().getValue() != "") //if the "Teacher EIN" cell is the active range and it's not empty
{
var ein = actRng.getValue();
clearDocumentationSheetTeacherProfile(); //first clear the teacher profile information to avoid the possibility of EIN/Teacher Info mismatch if previous search did not yield results
var teacherDataArr = lookupEIN(ein, "Teachers");
if(teacherDataArr)
{
//write retrieved teacher data to Documentation Spreadsheet
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Documentation Sheet");
sheet.getRange(5, 9, 1, 1).setValue(teacherDataArr[1]); // Teacher First Name
sheet.getRange(6, 9, 1, 1).setValue(teacherDataArr[2]); // Teacher Last Name
sheet.getRange(7, 9, 1, 1).setValue(teacherDataArr[3]); // Teacher Email
sheet.getRange(11, 9, 1, 1).setValue(teacherDataArr[4]); // School Name
sheet.getRange(11, 39, 1, 1).setValue(teacherDataArr[5]); // Site Code
sheet.getRange(10, 30, 1, 1).setValue(calculateSchoolYear()); //School Year
}
else
{
Logger.log("employeeLookup(): type:Teachers 'died. lookupEIN() did not return a valid array'"); //alert message already sent by lookUpEIN
}
}
else if (actRng.getRow() == 4 && actRng.getColumn() == 30 && actRng.getValue() != "" && !PropertiesService.getDocumentProperties().getProperty('initialized')) //if the "Observer EIN" cell is the active range
{
Logger.log("employeeLookup(): 'active range is Observer EIN'");
var ein = actRng.getValue();
clearDocumentationSheetObserverProfile(); //first clear the teacher profile information to avoid the possibility of EIN/Observer Info mismatch if previous search did not yield results
var observerDataArr = lookupEIN(ein, "Observers");
if(observerDataArr)
{
//write retrieved observer data to Documentation Spreadsheet
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Documentation Sheet");
sheet.getRange(5, 30, 1, 1).setValue(observerDataArr[1]); // Observer First Name
sheet.getRange(6, 30, 1, 1).setValue(observerDataArr[2]); // Observer Last Name
sheet.getRange(7, 30, 1, 1).setValue(observerDataArr[3]); // Observer Email
}
else
{
Logger.log("employeeLookup(): type:Observers 'died. lookupEIN() did not return a valid array'"); //alert message already sent by lookUpEIN
}
}
else
{
Logger.log("employeeLookup(): 'active range is not a trigger'");
//do nothing (not the right cell)
}
}
else
{
//Observer log has already been initialized and documentation cannot be altered. notify user
Logger.log("employeeLookup(): 'log already saved.... alerting user'");
logAlreadyInitializedDialogue();
restoreDocumentationSheetData();
}
}
function lookupEIN(ein, type)
{
Logger.log ("lookUpEIN(): 'engaged'");
var ss = SpreadsheetApp.openById(teacherObserverIndex_GID);
var sheet = ss.getSheetByName(type); //lookup type aligns with the individual sheet names on the teacherObserverIndex_GID document
var values = sheet.getDataRange().getValues();
var val = sheet.getDataRange();
for (var i = 1; i < values.length; i++)
{
if(values[i][0] == ein)
{
Logger.log ("lookUpEIN(): values[i]: "+values[i]);
return values[i];
}
else
{
Logger.log ("lookUpEIN(): 'no match found'");
}
}
//a match could not be found
Logger.log("An EIN match could not be found"); // create a feedback pop-up
einNotFoundDialogue(type); //alert user that there is a problem with the provided ein
}
Triggers can't be created when running a script as Test as add-on.
From https://developers.google.com/apps-script/add-ons/test :
There are a number of things to keep in mind while testing add-ons:
Installable triggers are currently not supported when testing.
Functionality that depends on installable triggers will not be
testable.
Some possible workarounds
For on open and on edit installable triggers, temporally add simple triggers to call the functions of the installable triggers. This might only work if the execution time of is less than the simple triggers limit.
Call the functions from the installable triggers from functions that create object that emulates the corresponding event object
Instead of using a stand-alone project use bounded projects. You might use CLASP or an extension like Google Apps Script GitHub Assistant Chrome extension to make it easier to copy the code from the stand-alone project to a bounded project.
Related
How can I test a trigger function in GAS?
In my experience onEdit() is not available for test as Add-On.
I agree the documentation is not clear, it seems to be referring to only "Installable Triggers" but I think it applies to all Triggers except for the "onInstall" trigger that is run as soon as you start the test. (see: Testing Google Sheet Addon Triggers for more details)

Implement the same function in AS2 for an Array

I have an array, and I would like to make a function onRelease for all of the array positions.
The code would be like:
pick = new Array(2,3,4);
var botoes1:MovieClip = lev.attachMovie("block", "block_"+lev.getNextHighestDepth(), lev.getNextHighestDepth(), {_x:550, _y:1*22});
_root.botoes1.gotoAndStop(pick[1]);
var botoes2:MovieClip = lev.attachMovie("block", "block_"+lev.getNextHighestDepth(), lev.getNextHighestDepth(), {_x:550, _y:2*22});
_root.botoes2.gotoAndStop(pick[2]);
var botoes3:MovieClip = lev.attachMovie("block", "block_"+lev.getNextHighestDepth(), lev.getNextHighestDepth(), {_x:550, _y:3*22});
_root.botoes3.gotoAndStop(pick[3]);
for(i=0;i<3;i++){
_root['botoes'+i].onRelease() = Function () {
}
}
but it doesn't work this way...
and if possible, how can I make the MovieClip declaring for all the buttons in an for loop?
Couple syntax errors there, here's what this line should look like:
_root['botoes' + i].onRelease = function()
{
// Function body.
//
}
Your previous code was trying to assign the result of _root['botoes' + i].onRelease() (which would have been undefined) to the result of Function() (which would have been a Function object).

Refresh a dijit.form.Select

First, you have to know that I am developing my project with Struts (J2EE
Here is my problem :
I have 2 dijit.form.Select widgets in my page, and those Select are filled with the same list (returned by a Java class).
When I select an option in my 1st "Select widget", I would like to update my 2nd Select widget, and disable the selected options from my 1st widget (to prevent users to select the same item twice).
I succeed doing this (I'll show you my code later), but my problem is that when I open my 2nd list, even once, it will never be refreshed again. So I can play a long time with my 1st Select, and choose many other options, the only option disabled in my 2nd list is the first I've selected.
Here is my JS Code :
function removeSelectedOption(){
var list1 = dijit.byId("codeModif1");
var list2 = dijit.byId("codeModif2");
var list1SelectedOptionValue = list1.get("value");
if(list1SelectedOptionValue!= null){
list2.reset();
for(var i = 0; i < myListSize; i++){
// If the value of the current option = my selected option from list1
if(liste2.getOptions(i).value == list1SelectedOptionValue){
list2.getOptions(i).disabled = true;
} else {
list2.getOptions(i).disabled = false;
}
}
}
Thanks for your help
Regards
I think you have to reset() the Select after you've updated its options' properties. Something like:
function removeSelectedOption(value)
{
var list2 = dijit.byId("codeModif2"),
prev = list2.get('value');
for(var i = 0; i < myListSize; i++)
{
var opt = myList[i];
opt.disabled = opt.value === value;
list2.updateOption(opt);
}
list2.reset();
// Set selection again, unless it was the newly disabled one.
if(prev !== value) list2.set('value', prev);
};
(I'm assuming you have a myList containing the possible options here, and the accompanying myListSize.)

XAML DataGrid filtering won't apply the filter

I'm trying to create a form that has two tabs, each with a DataGrid with a different filter on it. I've created the filters as such:
ObservableCollection<ParcelVoucherDetails> _voucherDetails = new ObservableCollection<ParcelVoucherDetails>();
CollectionView cvFreightOut = new CollectionView(_voucherDetails);
cvFreightOut.Filter += FreightOutFilter;
dgFreightOut.ItemsSource = cvFreightOut;
CollectionView cvFreightIn = new CollectionView(_voucherDetails);
cvFreightIn.Filter += FreightInFilter;
dgFreightIn.ItemsSource = cvFreightIn;
I then created the filters as such:
public bool FreightOutFilter(object o)
{
ParcelVoucherDetails p = o as ParcelVoucherDetails;
if (p != null)
{
return (p.Type == "Freight Out");
}
return false;
}
public bool FreightInFilter(object o)
{
ParcelVoucherDetails p = o as ParcelVoucherDetails;
if (p != null)
{
return (p.Type == "Freight In");
}
return false;
}
Now, here's where it gets annoying. During a later event, when I add items to the ObservableCollection, I can see the filters firing and accepting or denying the filter as expected, but ALL the items still appear on both DataGrids.
I've tried using CollectionViewSource, and that also doesn't work. The only way I can get any filtering to work at all is to skip the ObservableCollection and use a DataTable with DataViews. I'd like to avoid that here, because of the convenience in the rest of the code for using the ObservableCollection.
Has anyone seen this actually work, and if so, how?
I finally found it after banging my head on the wall. I feel ridiculous right now, but I had to share the solution:
ListCollectionView cvFO = new ListCollectionView(_voucherDetails);
cvFO.Filter += FreightOutFilter;
dgFreightOut.ItemsSource = cvFO;
ListCollectionView cvFI = new ListCollectionView(_voucherDetails);
cvFI.Filter += FreightInFilter;
dgFreightIn.ItemsSource = cvFI;
This sets the filters separately. Apparently, using a generic CollectionView instead of a ListCollectionView is a no-no. :)

How to automate vertical scrolling in Flex AdvancedDataGrid when dragging item below bottom of visible rows?

I have an AdvancedDataGrid with XML dataProvider. Drag and drop in enabled, and works within the visible rows of the ADG.
HOWEVER, if I attempt to drag an item past the bottom-most visible row of the ADG, the ADG does NOT scroll to display the next rows, which makes it impossible to drag and drop beyond the immediately visible rows. Although this would seem to be logical default behaviour of a datagrid (drag to bottom and keep dragging to reveal subsequent rows), Flex evidently doesn't Do Things That Way. I'm flummoxed how to implement this programatically.
Can anyone help?
I had to do this with a few items in the past, basically what I did was monitor the mouses Y position in the DG, if it was 50 or fewer pixels from the top or bottom then I would set the verticalscrollposition of the DG += 20 or -= 20 as required.
Let me know if you need a code snip but you should be able to figure out how to do all of this.
this worked for me, from Andre's solution but also checking for maxVerticalScrollPosition
and i was extending the ADG
protected function onDragOver(event:DragEvent):void
{
var dropIndex:int = calculateDropIndex(event);
autoScoll(dropIndex);
}
//to have the adg scroll when dragging
//http://stackoverflow.com/questions/2913420/how-to-automate-vertical-scrolling-in-flex-advanceddatagrid-when-dragging-item-be
protected function autoScoll(dropIndex:int):void
{
var rowsDisplayed:Number = rowCount;
var topvisibleIndex:int = verticalScrollPosition;
var botvisibleIndex:int = topvisibleIndex + rowsDisplayed;
if (dropIndex <= topvisibleIndex)
{
verticalScrollPosition = Math.max(verticalScrollPosition - 1, 0);
}
else if (dropIndex >= botvisibleIndex - 1 && dropIndex < (rowCount + maxVerticalScrollPosition - 1))
{
verticalScrollPosition += 1;
}
}
Got to love Flex, man. Where the obvious stuff takes a ton of time.
So this is what I ended up doing:
mygrid.addEventListener( DragEvent.DRAG_OVER, handleDragOver);
public function handlerDragOver(event:DragEvent):void{
var dropIndex:int = mygrid.calculateDropIndex(event);
var rowsDisplayed:Number = mygrid.rowCount;
var topvisibleIndex:int = mygrid.verticalScrollPosition;
var botvisibleIndex:int = topvisibleIndex + rowsDisplayed;
if ( dropIndex <= topvisibleIndex) {
mygrid.verticalScrollPosition = Math.max( mygrid.verticalScrollPosition- 1, 0 );
} else if( dropIndex >= botvisibleIndex - 1 ){
mygrid.verticalScrollPosition += 1;
}
}