How to call a javascript function from flash on actionscript1.0 - actionscript

on (press)
{
here I want to call a javascript function
}
on (rollOver)
{
gotoAndPlay("guizhou");
}
on (rollOver)
{
startDrag ("1guizhou", true);
}
on (rollOut)
{
gotoAndPlay("kongk");
}
How to call a javascript function in the press event ? in as3.0 there is mouseevent but in as1.0 ,I don't konw how do that? Can you help me?

You can use getURL:
getURL("javascript:functionName()");
additional about this function can be found at:
http://help.adobe.com/en_US/as2/reference/flashlite/WS5b3ccc516d4fbf351e63e3d118ccf9c47f-7fc9.html

Related

Wait for JS Callback After evaluateJavaScript

I am trying to wait for javascript callback, however, the swift callback is being called before the javascript callback. How can I wait for JS callback?
AppWebView.evaluateJavaScript("$('.loading-gif').removeClass('hide', function() { return true } );") { (Any, Error) in
\\ .loading-gif successfully hided.
}
There is no way to do this using evaluateJavaScript, since it's callback is called as soon as the evaluated Javascript returns. This is most likely before your asynchronous call is done.
You will need to register a message handler in your swift code similar to…
let script = WKUserScript(source: javascriptString,
injectionTime: injectionTime,
forMainFrameOnly: true)
userContentController.addUserScript(script)
webView.configuration.userContentController.addScriptMessageHandler(self,
name: "didShowLoading")
You can then define a delegate method in your Swift code…
func userContentController(userContentController: WKUserContentController,
didReceiveScriptMessage message: WKScriptMessage) {
if message.name == "didShowLoading" {
// do something
}
}
Finally, you can post the message from your javascript code…
var script = "$('.loading-gif').removeClass('hide', function() {"
+ " webkit.messageHandlers['didShowLoading'].postMessage('');"
+ "});"
webView.evaluateJavaScript(script)
You can use this library https://github.com/marcuswestin/WebViewJavascriptBridge
On JS side:
bridge.registerHandler("show_loading", function(data, responseCallback) {
$('.loading-gif').removeClass('hide', function() {
responseCallback(true)
} );
})
And on Swift side:
self.bridge.callHandler("show_loading",data:nil, handler: { (data:AnyObject!) in
//do whatever you want...
})
You could notify the native iOS code via a callback from the javascript callback. If you add something like this to your javascript:
window.webkit.messageHandlers.observe.postMessage(JSON.stringify( { callback: 'show_loading' } ));
Then on the native side setup a WKUserContentController for your WKWebView (installed on the WKWebViewConfiguration). Your userContentController.didReceiveScriptMessage handler will get called with the JSON sent from the Javascript side.

Capybara or Jasmine?

I need to write a test (in Rails) that just shows a function was called. I am not sure to approach this in Jasmine or in Capybara?
My click event is:
<button class="player_vs_cpu_intro" onclick="playerVsCpu()">Player Vs. CPU's Selection</button>
My function is:
function playerVsCpu() {
alert("Hello World");
//other code is in here as well
}
Also, if I had a function within playerVsCpu();, can I test that as well?
Any advice would be appreciated!
You can use jasmine for that. To check if a function has been called you need to use spyOn().
describe("button click", function() {
var btn;
beforeEach(function() {
btn = $('.player_vs_cpu_intro')[0];
});
it("should call playerVsCpu", function() {
spyOn(window, 'playerVsCpu');
$(btn).click();
expect(window.playerVsCpu).toHaveBeenCalled();
});
});
You can also test if a function has been called inside playerVsCpu(). Let's say you call a function anotherFunction() inside playerVsCpu() and you want to assert that.
describe("playerVsCpu", function() {
it("should call anotherFunction", function() {
spyOn(window, 'anotherFunction');
playerVsCpu();
expect(window.anotherFunction).toHaveBeenCalled();
});
});

About navigator.geolocation.getCurrentPosition

i have a question about this topic. navigator.geolocation.getCurrentPosition does not seems to work for me on Android 4.2.2 on many browsers and 4 devices. It ask about my location, I can accept or decline but whatever I pick it does not fire success or errorr function.
My sample code:
function GoogleMap(){
this.initialize = function(){
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(geolocationSuccess,geolocationError);
} else {
geolocationError();
}
}
}
function geolocationSuccess(position){
alert(position);
}
function geolocationError(){
alert('Geolocation disabled');
}
Can You help me with that?

Soundcloud SC.Stream can't access Soundmanager events

I'm using the Soundcloud Javascript SDK (http://developers.soundcloud.com/docs/api/sdks#javascript) on a project and have happily got my player loading a sound and playing it like so:
SC.get("/resolve/",{
url: href
},function(response){
SC.stream("/tracks/"+response.id,{},function(sound){
sound.play();
});
})
I can trigger the soundmanager object to play in the callback using sound.play() but I can't work out how to access the events of the object mantioned in the docs (http://www.schillmania.com/projects/soundmanager2/doc/) like whileplaying()
How do I add these in? I've tried this kind of thing:
sound.whileplaying(function(){
alert("hooray!")
})
But that doesn't work.
Many thanks
Julian
This should work:
SC.stream("/tracks/" + response.id, {
whileplaying: function () {
console.log("track is playing");
}
}, function (sound) {
sound.play();
});
The correct way is:
SC.stream('/tracks/' + response.id).then(function (player) {
player.on('finish', function () {
console.log('finish');
});
player.play();
});
You found this answer and consult all events here:
https://developers.soundcloud.com/docs/api/sdks#player

jquery validation code isn't working proper

i cant get the issue in my code , every thing working proper but issue is that when user click or focus first time on textbox correct img show .. this is incorrect but i cant solved this problem when user typing then after completing wher user correct type then show otherwise not shown . can any one help me regarding this issue . my complete jquery and html or css code are available in this link pls check and solved my issue
my code link
i think error on this function but icant get the issue
$('#step1 #fName').focus(function(){
if($('#step1 #fName').hasClass('error_Aplha')==true)
{
$('#step1 #fntick').removeClass('block');
}
else {
$('#step1 #fntick').addClass('block');
}
}).blur(function(){
if($('#step1 #fName').hasClass('error_Aplha')==true)
{
$('#step1 .fname_error').fadeIn(100).delay(2000).fadeOut(1000);
$('#step1 #fntick').removeClass('block');
}
else {
$('#step1 .fname_error').removeClass('block');
$('#step1 #fntick').addClass('block');
}
});
thanks in advance
Wow, that's a lot of code for a simple task. Change it so the checks are only done in the .keyup() and .blur() events of the INPUT elements.
Not 100% sure what the intended behaviour is, but this will probably get you going:
$(document).ready(function(e) {
var errorAlpha = function() {
var reg = /^([A-Za-z]+)$/;
var check = $(this).val();
if (reg.test(check) == true && check.match(reg) != null) {
// VALID
$(this).removeClass('error_Aplha');
$(this).next('img').addClass('block');
$(this).prevAll('span.tooltip2').stop(true).delay(500).fadeOut(400);
} else {
// INVALID
$(this).addClass('error_Aplha');
$(this).next('img').removeClass('block');
$(this).prevAll('span.tooltip2').fadeIn(500).delay(2000).fadeOut(1000);
}
};
$('#step1 #fName, #step1 #lName').on('keyup blur', errorAlpha);
});​
Demo: http://jsfiddle.net/gU3PU/6/

Resources