Hi there,
I am EXTREMELY new to flash and I may come across as dumb as a brick. If you can explain things in as much detail as possible this would be highly appreciated.
Right now my flash script imports 2 other flash files and draws some rectangles (that is all it does). Here is the code for that.
(I think this is using AS3, I don't fully understand it all, much of it is copied and pasted from other sources)
Code:
var myLoader:Loader = new Loader(); // create a new instance of the Loader class
var url:URLRequest = new URLRequest("flash1.swf"); // in this case both SWFs are in the same folder
myLoader.load(url); // load the SWF file
addChild(myLoader); // add that instance to the display list, adding it to the Stage at 0,0
myLoader.x = 0; // move the loaded SWF 10 pixels to the right (from the left edge)
myLoader.y = 0; // move the loaded SWF 175 pixels down from the top
var whiteSpace:MovieClip = new MovieClip();
addChild(whiteSpace);
whiteSpace.graphics.beginFill(0,1);
whiteSpace.graphics.drawRect(400,0,200,800);
whiteSpace.graphics.drawRect(-25,0,25,800);
// (optional) load a second external SWF file
var my2ndLoader:Loader = new Loader();
var url2:URLRequest = new URLRequest("ExternalSWF2.swf");
my2ndLoader.load(url2);
addChild(my2ndLoader); // optionally, you could put the 2nd SWF beneath
// the 1st by using addChildAt(my2ndLoader, 1);
// (optional) scaling of the 2nd SWF file
my2ndLoader.scaleX = 2; // scale the SWF horizontally by 200%
my2ndLoader.scaleY = 2; // scale the SWF vertically by 200%
Now I would like to add a global hotkey (Ctrl + k) that when pressed redirects the user to google.com (there is no purpose to this I am just trying to learn)
With a bit of research I found some code that might achieve this but haven't got it to work.
Code:
package {
import flash.display.*;
import flash.events.*;
import flash.external.ExternalInterface;
public class TestMouseLeave extends Sprite
{
public function TestMouseLeave()
{
// Add event listener for when the mouse LEAVES FLASH
addEventListener(MouseEvent.MOUSE_OUT, onMouseLeave);
}
private function onMouseLeave(ev:Event):void
{
var jslink = new ExternalInterface();
jslink.call("redirect");
}
}
}
And then on the html page itself use
Code:
<script type="text/javascript" language="javascript">
function redirect(){
window.location.href ='http://google.com';
}
</script>
First: I am not sure where to put the flash code, when I put it at the top of my current script and try to compile I get an error 'Package cannot be nested'. Despite googling this error I can't quite figure out how to fix this, so I need a really good explanation of what to do considering I'm a complete newb.
Second: this script activates the redirect when the mouse pointer leaves the flash file, how can can change that to when the user press 'Ctrl + k'
Third: is this the only method/best method of redirecting the browser when a user presses 'Ctrl + k'?
Thanks in advance for any input at all.