I'm creating flash game for Facebook. For now after Game Over It opens new tab with share button (suggest share user's game score on wall).
It should pop-up window with share button on the same Game window.
For now my code in ActionScript 3 is:
function gameOver(evt:Event)
{
if (!m_iLives){
var req:URLRequest = new URLRequest();
req.url = "http://www.facebook.com/dialog/feed";
var vars:URLVariables = new URLVariables();
vars.app_id = "0000000000000"; // your application's id
vars.link = "https://www.facebook.com/.......";
vars.picture = "http:/pictureN.png";
vars.name = "Name...!";
vars.caption = "Caption";
vars.description = "My score is " + String(score) + " Try and you!";
vars.redirect_uri = "https://www.url.com";
req.data = vars;
req.method = URLRequestMethod.GET;
navigateToURL(req, "_blank");
}
}
For true pop-ups I always use ExternalInterface. The script below will let you create pop-ups. make sure the ExternalInterface is available. And to customize the size of your pop-up replace the with and height variable with your dimensions
ExternalInterface.call("window.open('" + url + "','PopUpWindow','width=" + width + ",height=" + height + ",toolbar=yes,scrollbars=yes')");
Related
I added a new button to my VSCode, such that when I click it - it compiles the current folder, and shows dialog boxes using vscode.window.showInformationMessage.
Each box shows a compilation error, and has a button in it. Once the user clicks the button - it opens the problematic file in a tab using vscode.workspace.openTextDocument.
I want to make the button to also navigate me to the problematic line in the problematic file.
My question is:
Given a number, is it possible to navigate to a specific line number inside a file?
Sample code of what I achieved so far:
// Bullshit to give some context
const pattern = /(In \w+.jack)/g;
var i = s.search(pattern);
var substring = s.substring(i + 1)
var j = substring.search(pattern);
var s = "bsadsdbla In main.jack (line 55) sqdwqe blasdsd wq qqweq"
let GoToFile = 'Go to File';
var k = s.search(/(\w+.jack)/);
var l = s.search(/(.jack)/)
var fileName = s.substring(k, l);
// ---------> This is the important part <----------------
vscode.window.showInformationMessage(s.substring(i, j), GoToFile).then(selection => {
if (selection === GoToFile) {
vscode.workspace.openTextDocument(currentDirectory + '\\' + fileName + '.jack')
.then(document => vscode.window.showTextDocument(document));
}
});
I am assuming you have some code/regex in place that gives you the line number. Whenever someone clicks your GoToFile method invoke the following code :
activeEditor.selections = [new vscode.Selection(lineToGo, lineToGo)];
var range = new vscode.Range(lineToGo, lineToGo);
activeEditor.revealRange(range);
Some background:
As #rioV8 mentioned, revealRange was the way to go, but the problem was that I couldn't understand how to use it using the VSCode API, so here #Shahriar Hossain came into the picture. #Shahriar Hossain's code works, however, there was an important declaration missing, and I also had to figure out how to run the code when the user clicks the button.
This is the full solution:
vscode.window.showInformationMessage(s.substring(i), GoToFile).then(selection => {
if (selection === GoToFile) {
vscode.workspace.openTextDocument(currentDirectory + '\\' + fileName + '.jack')
.then(document => vscode.window.showTextDocument(document))
// Whatever code inside this "then" block
// will be executed on button click
.then(x => {
let m = s.substring(i, j).search(/\(line \d+\)/);
let subStr = s.substring(m + 6);
let n = subStr.search(/\)/);
subStr = subStr.substring(0, n);
let lineToGo = parseInt(subStr.match(/\d+/));
// The missing declaration of the activeEditor
let activeEditor = vscode.window.activeTextEditor;
let range = activeEditor.document.lineAt(lineToGo - 1).range;
activeEditor.selection = new vscode.Selection(range.start, range.end);
activeEditor.revealRange(range);
})
}
});
On the app i'm currently developping,
I have several hyperlink to standard sap backend transaction such as BP, PDL and so on.
i'm opening them by means of CrossApplicationNavigation.
they open new tab.
on my main app, I implemented a button to close every tab and returning to root view.
I tried the following :
Script to close other tabs or browser
here is my code :
var oCrossAppNavigator = sap.ushell.Container.getService("CrossApplicationNavigation");
var oExtUi = oEvent.getSource().getText();
var hash = oCrossAppNavigator.hrefForExternal({
target: {
semanticObject: "ZSIMM_PDL",
action: "display"
},
params: {
"UtilitiesPDL": oExtUi
}
});
var url = window.location.href.split("#")[0] + hash;
this._oComponent = sap.ui.component(sap.ui.core.Component.getOwnerIdFor(this.getView()));
this._myModel = this._oComponent.getModel("oModelWindow");
this._myModel.setProperty("/Window", window);
sap.m.URLHelper.redirect(url, true);
},
this way, i open the new tab with my semanticObject. and I register it in my Model.
the next step is the method linked with my button :
this._myModel = this._oComponent.getModel("oModelWindow");
var aWindow = this._myModel.getData().Window;
aWindow.close();
I'm loading the window of the tab I opened.
the instruction close doesn't work it writes :
"Scripts may close only the windows that were opened by it."
what I understand in CrossApplicationNavigation is that it opened a new tab and redirect by use of sap.m.URLHelper.redirect(url, true);
does the current screen before calling the new one know which page it opens ?
and this way is there a method to close it manually ?
I found a solution which is the following :
when opening the crossApplicationnavigation, I put on memory the tab opened :
var oExtUi = oEvent.getSource().getText();
var hash = oCrossAppNavigator.hrefForExternal({
target: {
semanticObject: "ZSIMM_PDL",
action: "display"
},
params: {
"UtilitiesPDL": oExtUi
}
});
var url = window.location.href.split("#")[0] + hash;
this._oComponent = sap.ui.component(sap.ui.core.Component.getOwnerIdFor(this.getView()));
this._myModel = this._oComponent.getModel("oModelWindow");
var aWindow = this._myModel.getData().Windows;
aWindow.push(window.open(url, "_blank"));
this._myModel.setProperty("/Windows", aWindow);
and in the button method, I recall all tab and close them all this way :
this._oComponent = sap.ui.component(sap.ui.core.Component.getOwnerIdFor(this.getView()));
this._myModel = this._oComponent.getModel("oModelWindow");
//then you can iterate over them and close them all like this:
var oWindow = this._myModel.getData().Windows;
for (var i = 0; i < oWindow.length; i++) {
oWindow[i].close();
}
that way when clicking the button all other tab are closed.
I have this google app script which should
show file upload dialog
store file in google drive
write the url of the file into the current cell
All goes well except step 3, where the cell updated is always cell A1 in the first sheet. But the cursor is on sheet #3 on another cell.
function onOpen(e) {
var ss = SpreadsheetApp.getActiveSpreadsheet()
var menuEntries = [];
menuEntries.push({name: "File...", functionName: "doGet"});
ss.addMenu("Attach ...", menuEntries);
}
function doGet(e) {
var app = UiApp.createApplication().setTitle("Attach file to sheet");
var form = app.createFormPanel().setId('frm').setEncoding('multipart/form-data');
var formContent = app.createVerticalPanel();
form.add(formContent);
formContent.add(app.createFileUpload().setName('thefile'));
formContent.add(app.createSubmitButton('Submit'));
app.add(form);
SpreadsheetApp.getActiveSpreadsheet().show(app);
return app;
}
function doPost(e) {
var fileBlob = e.parameter.thefile;
var doc = DocsList.getFolderById('0B0uw1JCogWHuc29FWFJMWmc3Z1k').createFile(fileBlob);
var app = UiApp.getActiveApplication();
var label = app.createLabel('file uploaded successfully');
var value = '=hyperlink("' + doc.getUrl() + '","' + doc.getName() + '")'
app.add(label);
app.close();
SpreadsheetApp.getActiveSheet().getActiveCell().setValue(value);
return app;
}
I tried SpreadsheetApp.getActiveSheet().getActiveCell().setValue(value); outside of the doPost() function and this works when called in a normal context. What am I missing here?
judging from this answer, it is not possible to get the current spreadsheet/cell from the doPost function, the way I got it working is to get it in the doGet function via hidden fields and pass it via the form. Full blown working example here.
I want to integrate custom facebook like button through ACTIONSCRIPT(Flash) programming?
All I could get on the internet is the code to produce facebook Like button using javascript.
I want that same functionality to be provided to my custom button,
I don't want users to redirect intermediate page which having actual facebook Like button.
I tried with intermediate page but it too lengthy for users.they have to click again on that button to share.
Please help me to integrate this functionality.
any help will be great appreciate.
Thanks,
Sandeep
Here's a workaround: you can navigate to the sharing URL from Flash, loaded with the appropriate parameters and opening it on a new window. The following function should work for this purpose:
import flash.net.*;
/**
* Function that allows sharing a page in Facebook
* #param sharedTitle String with the title of the page that you want to share in Facebook
* #param sharedURL String with the full URL that you want to share in Facebook
* #param sharedSummary (Optional) String with a description about your shared content
* #param sharedImageURL (Optional) String with the full URL where the image to display next to your shared post is located
*/
function shareInFacebook(sharedTitle : String, sharedURL : String, sharedSummary : String = null, sharedImageURL : String = null) : void {
var fullURLString = "";
fullURLString += "http://www.facebook.com/sharer.php?s=100";
fullURLString += "&p[title]=" + encodeURIComponent(sharedTitle);
fullURLString += "&p[url]=" + encodeURIComponent(sharedURL);
if (sharedImageURL != null) {
fullURLString += "&p[images][0]=" + encodeURIComponent(sharedImageURL);
}
if (sharedSummary != null) {
fullURLString += "&p[summary]=" + encodeURIComponent(sharedSummary);
}
var theRequest : URLRequest = new URLRequest(fullURLString);
navigateToURL(theRequest, "_blank");
}
Call this function when a button is clicked and you should get a custom Facebook button inside Flash.
More information about how to build a URL to share in Facebook with all parameters (that you can call via Flash:)
Facebook Share doesn't show my description or my thumbnail
And more here as well, including the meta-tags that you can put into your embedding HTML:
How do I customize Facebook's sharer.php
I'm not sure if you are trying on a flash or AdobeAir project but if you are on mobile, here's the solution: https://github.com/myflashlab/facebook-ANE
var like1:LikeBtn = FB.createLikeBtn("https://www.facebook.com/myflashlab", LikeBtn.STYLE_STANDARD, LikeBtn.LINK_TYPE_PAGE, stage);
like1.name = "like" + Math.random();
like1.addEventListener(FBEvent.LIKE_BTN_CREATED, onBtnCreated);
like1.addEventListener(FBEvent.LIKE_BTN_ERROR, onBtnError);
like1.addEventListener(FBEvent.LIKE_BTN_UPDATED, onBtnUpdated);
private function onBtnCreated(e:FBEvent):void
{
var btn:LikeBtn = e.target as LikeBtn;
_btn = btn;
btn.x = Math.random() * 600;
btn.y = Math.random() * 600;
C.log("onBtnCreated, btn.name = " + btn.name);
C.log("width = " + btn.width);
C.log("height = " + btn.height);
btn.update("http://www.myappsnippet.com/", LikeBtn.STYLE_BOX_COUNT, LikeBtn.LINK_TYPE_OPEN_GRAPH);
}
private function onBtnError(e:FBEvent):void
{
var btn:LikeBtn = e.target as LikeBtn;
C.log("e.param = " + e.param);
}
private function onBtnUpdated(e:FBEvent):void
{
var btn:LikeBtn = e.target as LikeBtn;
C.log("onBtnUpdated");
C.log("width = " + btn.width);
C.log("height = " + btn.height);
/*btn.removeEventListener(FBEvent.LIKE_BTN_CREATED, onBtnCreated);
btn.removeEventListener(FBEvent.LIKE_BTN_ERROR, onBtnError);
btn.removeEventListener(FBEvent.LIKE_BTN_UPDATED, onBtnUpdated);
btn.dispose();
btn = null;
C.log("btn.dispose();");*/
}
I've never done this but the consensus appears to be that it's virtually impossible.
If you can, I think your best bet would be to create the button in HTML using the code supplied by facebook and try to integrate that as best you can with your Flash. The following example includes the button in a div positioned above the Flash so it looks like it is directly integrated:
http://www.magichtml.com/tutorial_facebook.html
It might also be worthwhile looking at the ActionScript ExternalInterface class which allows Flash to make JavaScript calls (and vice versa). You could use this to control when the like button is displayed (for example, when your Flash movie has loaded and rendered) for a more seamless integration:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/external/ExternalInterface.html
I have a search form and a login form on my website. When the enter button is pressed when the login form has focus, the search runs instead of the login. Is there a way to fix this?
I've already tried using a panel around the login form and use defaultbutton, but the loginview errors when I do this.
You could try setting up a keypress event on your login form. Off the top of my head, something like
$('#loginForm').keypress(function (e) {
if(e.keyCode=='13') //Keycode for "Return"
$('#login').click();
}
});
should work, assuming you give appropriate IDs to the elements involved.
If you're talking about HTML, then this suggests tab order (learn more about that here) is relevant or the order in which the forms were created, the behavior depending on the user agent.
could you try adding attributes at run time like this
Login loginControl = (Login)lvLoginView.FindControl("logLogin");
TextBox tbUserName = (TextBox)loginControl.FindControl("UserName");
TextBox tbPassword = (TextBox)loginControl.FindControl("Password");
Button loginButton = (Button)loginControl.FindControl("LoginButton");
tbUserName.Attributes["onKeyPress"] = "KeyDownHandler('" + loginButton.ClientID + "')";
tbPassword.Attributes["onKeyPress"] = "KeyDownHandler('" + loginButton.ClientID + "')";
and some JS:
function KeyDownHandler(btn){
// process only the Enter key
if (event.keyCode == 13) {
// cancel the default submit
event.returnValue = false;
event.cancel = true;
var obj = document.getElementById(btn);
obj.click();
}}
UPDATE
Auto-converted to VB.NET courtesy of telerik
Dim loginControl As Login = DirectCast(lvLoginView.FindControl("logLogin"), Login)
Dim tbUserName As TextBox = DirectCast(loginControl.FindControl("UserName"), TextBox)
Dim tbPassword As TextBox = DirectCast(loginControl.FindControl("Password"), TextBox)
Dim loginButton As Button = DirectCast(loginControl.FindControl("LoginButton"), Button)
tbUserName.Attributes("onKeyPress") = "KeyDownHandler('" + loginButton.ClientID + "')"
tbPassword.Attributes("onKeyPress") = "KeyDownHandler('" + loginButton.ClientID + "')"