How to use Code org creating simple program without using a bunch of OnEvents - code.org

using code.org i need to be able to have a user click on a button that takes them to another screen without using OnEvent(s) constantly, can anyone help me out? Newb here. Thank you for your time.

You can create a function with a value for button and string and put a callback inside
function event(button,input_type, screen) {
onEvent(button, input_type, function() {
setScreen(screen);
});
}

Related

GMap.Net .ToImage() Function Outputting Images With Blank Tiles

The .ToImage() function in GMap.Net does not appear to wait for the map data to be downloaded before the screenshot is taken. This results in images with blank tiles. Is there any existing capability that would allow GMaps to wait until the map is loaded?
I already posted my question on GitHub but haven't gotten a response so far. So any help is appreciated.
VB.NET Code
Private Function TakeBitmapScreenShot() As Image
'''''''''''''''''''''''''''''''''''''''''
'Code to wait until all tiles have loaded
'''''''''''''''''''''''''''''''''''''''''
Return GMapControl.ToImage()
End Function
You can Handle the event (OnTileLoadComplete ) which fires when the tile images completly loaded and then you can take the screenshot
GMapControl1.OnTileLoadComplete += GMapControl1_OnTileLoadComplete;
private void GMapControl1_OnTileLoadComplete(long ElapsedMilliseconds)
{
GMapControl.ToImage();
}
Two of the ways around this are using the TilePrefetcher or even better this code.

Smartface Codereader starts but do not read any code

I used the following sample code in order to test the CodeReader component :
function Page1_TextButton1_OnPressed(e){
Pages.Page1.CodeReader1.visible = true;
Pages.Page1.CodeReader1.readCode(SMF.UI.CodeType.linear,function()
{
alert(Pages.Page1.CodeReader1.value);
},function()
{
alert("There is an error");
});
When I press the button, the control displays the camera stream, but nothing ever happens afterwards : it does not reach neither the OnSuccess nor the OnFailure callback functions.
The camera does not focus either.
Is there any extra code I should add ? Should I explicitly call the phone camera ? How ?
Thanks,
nico
P.S. : I have tested on 2 different android phones
I guess that the codeReader object is so small to read a barcode.
I suggest you to read the article below;
http://www.smartface.io/developer/guides/controls/codereader/
Try this:
1 - Drag in CodeReader into your Design Area.
2 - Write this code in the script for that page.
function MyPage_Self_OnShow(e){
Pages.MyPage.CodeReader1.readCode("[CODE TYPE (e.g. "qr")]",
function(){
alert("Pages.MyPage.CodeReader1.value");
},
function(){
alert("fail");
});
}
Try reading the documentation if you have any other questions!

silverstripe dopublish function for ModelAdmin managed Pages

in the silverstripe backend I´m managing certain PageTypes via a ModelAdmin. That works fine so far, the only thing i can´t figure out is how to make a Page being "Published" when saving it.
Thats my code:
class ProjectPage extends Page {
public function onAfterWrite() {
$this->doPublish();
parent::onAfterWrite();
}
}
At the moment I can still see the ModelAdmin-created Pages in the Sitetree and I can see they are in Draft Mode. If I use the code above I get this error:
Maximum execution time of 30 seconds exceeded in
.../framework/model/DataList.php
Many thx,
Florian
the reason why you get "Maximum execution time exceeded" is because $this->doPublish(); calls $this->write(); which then calls $this->onAfterWrite();. And there you have your endless loop.
So doing this in onAfterWrite() or write() doesn't really work
you should just display the save & publish button instead of the save button
But I guess its easier said than done.
Well adding a button is actually just a few lines, but we also need a provide the functions that do what the button says it does.
This sounds like the perfect call for creating a new Module that allows proper handling of Pages in model admin. I have done this in SS2.4, and I have a pretty good idea of how to do it in SS3, but no time this week, poke me on the silverstripe irc channel on the weekend, maybe I have time on the weekend.
I found the same need/lack and I built a workaround that seems to work for me, maybe it can be useful.
public function onAfterWrite()
{
if(!$this->isPublished() || $this->getIsModifiedOnStage())
{
$this->publish('Stage', 'Live');
Controller::curr()->redirectBack();
}
parent::onAfterWrite();
}
Create a class that extends ModelAdmin and define an updateEditForm function to add a publish button to the actions in the GridFieldDetailForm component of the GridField.
public function updateEditForm($form) {
if ( ! singleton($this->owner->modelClass)->hasExtension('Versioned') ) return;
$gridField = $form->Fields()->fieldByName($this->owner->modelClass);
$gridField->getConfig()->getComponentByType('GridFieldDetailForm')->setItemEditFormCallback(function ($form) {
$form->Actions()->push(FormAction::create('doPublish', 'Save & Publish'));
});
}
Then create a class that extends GridFieldDetailForm_ItemRequest to provide an action handler for your publish button.
public function doPublish($data, $form) {
$return = $this->owner->doSave($data, $form);
$this->owner->record->publish('Stage', 'Live');
return $return;
}
Make sure the extensions are applied and you're done.
Or, you could just grab all the code you need from GitHub.

SWFUpload - How to Cancel Queued Files

I'm a little confused on how to cancel an upload in SWFUpload. I know you have to pass the cancelUpload() function the ID of the upload, but it seems like when I do this it doesn't work. A sample of my code would be:
function remove(number, id) {
cancelUpload(id);
}
<span onClick = "remove(0, 'SWFUpload_0_0')">filename</span>
However, the file still uploads. Any ideas?
Have to add the variable you assign SWFUpload to. In this case, swfu.cancelUpload() worked.
It is already in handlers.js file. This will cancel your current queued file.
ar progress = new FileProgress(file, this.customSettings.progressTarget);
progress.toggleCancel(true);

Creating an interactive Google Earth Tour (multiple tours)

I'm creating a Google Earth tour and I'd really like to be able to make this interactive so users can choose where they go.
I was thinking I could create each "scene" as a separate tour each ending with a decision (most likely through a placemark with a balloon containing a question and links for each possible answer).
However I'm having difficulties finding a way to load the next tour like this. Each tour will be available in a KMZ format and I'm open to if the new tour should be loaded from within the existing tour or from an external eventListener in the Google Earth API.
Any help or pointers would be gratefully received.
Dave
I presume you have already worked out how to play a tour using the plugin.If not, check this link
then you need to open a balloon at the end of each tour, which is two steps. Determine when the tour is ended, and then open a balloon which has a button or buttons to choose next tour.
To determine if the tour has ended use this function
function checkTour() {
// checks to see if it can read the time of the tour
// if it can it completes rest of function
try {
var duration = ge.getTourPlayer().getDuration();
var cTime = ge.getTourPlayer().getCurrentTime();
} catch (e) {
alert('error');
return false;
}
if (duration == cTime) {
// tour is over
tourOverSoOpenBalloonFunction();
} else {
// wait 1 second and check again
setTimeout('checkTour()',1000);
}
}
then use this example page of creating a balloon with a button in it that executes some javascript to load the next tour
essentially you would be changing this line
balloon.setContentString(
'Alert!');
to
balloon.setContentString(
'Tour 1<br/>Tour 2');
I might have missed something, but this should get you going in the right direction