What you're looking at is a top-level class document - in this case a .as file describing a class called Main that extends Sprite (all top-level documents that will be compiled into .swfs extend Sprite or MovieClip).
You're right, Flash Professional basically hides this from you (though you can get to the document class if you dig around). But Flash Professional is really a creative tool (for drawing/animating). While it's possible to use it to write ActionScript code, that's not necessarily its strength.
FlashDevelop is a free IDE (that's unfortunately for Windows only) competing against Adobe's Flash Builder. These are geared toward actionscript software development. These IDEs are very handy for the beginner as they will automatically download and install any necessary SDKs, automate the build process, provide project templates, code completion, and debugging, all there in the IDE.
If you'd prefer an IDE to help get you started, then either one of these should work fine (though again, Flash Builder is a commercial tool, I believe Flash Develop is free).
However, do note that you don't need an IDE and can use entirely free Adobe tools to compile .as source code files into .swf files - use the Adobe Flex SDK. It's a command-line compiler that works in Windows, Mac, and Linux, so you'll be using the text editor of your choice to edit your .as files. If this is your preferred workflow, see this tutorial to get you started.
I'd also recommend this excellent article for getting started in flash game development - it's chock full of great info and tutorial links.
As for your question of where your code goes, yes, the import goes at the top with the others, your addCallback statement goes under the "entry point" comment, and the function becomes a function on the Main class (just like the init function - within a class it will need a scope declaration like public, protected or private). Where you place the myText variable depends on when you'll be wanting to change it, but this should do for now:
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.external.ExternalInterface;
/**
* ...
* @author Will Thomas
*/
public class Main extends Sprite
{
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
ExternalInterface.addCallback("sendOutput", sendStaticTextFromAS3);
}
protected function sendStaticTextFromAS3():void {
var myText:String = "Example String";
ExternalInterface.call("receiveTextFromAS3", myText);
}
}
}
If I recall how ExternalInterface.addCallback works, it looks like what this will do is, when you call sendOutput() from javascript, it will call the sendStaticTextFromAS3 method in ActionScript, which will send the "Example String" back out to the receiveTextFromAS3() JavaScript function - kind of a loopback. You might one one function to handle your javascript-to-as3 communication, while a separate function handles your as3-to-javascript communication:
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
// Setup js-to-as listener
ExternalInterface.addCallback("sendTextToAS3", receiveTextFromJS);
// Send example text to js
sendTextFromAS3("Hello from ActionScript!");
}
protected function receiveTextFromJS(text:String):void {
trace("Received text from js: "+text);
// TODO: do something with it
}
protected function sendTextFromAS3(text:String):void {
ExternalInterface.call("receiveTextFromAS3", text);
}
You should also note that there are security restrictions to using addCallback described in the ExternalInterface documentation (your SWF must be embedded on the webpage with allowScriptAccess parameter set).
Hope this helps. =)