URLRequest is not working perfect - actionscript-3

I want to link as3 code to a webpage. I click a button and then go to a web page. I used navigateToUrl. When I compile my fla file then the button is working perfect, going to the required webpage. But without compiling the fla file, when I directly run my swf file, then I cannot go to the required webpage. Why does this happen? Here is my code.
import flash.events.MouseEvent;
import flash.net.URLLoader;
import flash.net.navigateToURL;
import flash.net.URLRequest;
link3.addEventListener(MouseEvent.CLICK, WebHyperlink);
link3.buttonMode=true;
function WebHyperlink(e:MouseEvent)
{
var myURL:URLRequest = new URLRequest("http://www.republicofcode.com/");
navigateToURL(myURL, "_blank");
}

You have a security exception because Flash Player blocks internet access to your swf file. To see that exception, you can install a Flash Player debug version from here and to avoid the problem, take a look on my answer for this question.
Hope that can help.

Related

Logic Error in closing SWF in a tab and can't open new html with ExternalInterface AS3

I'm facing a logic error here when i want to close tab in firefox through ExternalInterface, strangely nothing goes wrong in my output and compiler ,
import flash.events.MouseEvent;
import flash.system.fscommand;
import flash.external.ExternalInterface;
letsPlay.addEventListener(MouseEvent.MOUSE_DOWN, loadIntro);
function loadIntro(e:MouseEvent){
sndStart.play();
sndmChannel.stop();
//System.exit(0);
fscommand("quit");
ExternalInterface.call("window.open","http://localhost/GAME_FLASH/stage1/stage1story.html","_blank");
ExternalInterface.call("closeWindow");
}
Firefox won't close the tab and won't the desired html in new window, i've checked everything including my html page. All the "import flash.bla bla" is complete nothing goes wrong there.

loading swf files to buttons all on same page in flash

Good day to everyone!Here is my problem to all that is familiar with Flash. I am creating a portfolio using Flash. It has been sometime since using actionscript and can't figure out this. I have 6 different jpeg that I turned into buttons on 1 project page.What I need is to add different swf files to each button and play in seperate window.The code I used first loaded 1 swf file in same window. I am unable to figure out the code to make all 6 buttons show their individual swf file in a seperate window. Please help I am using trial version of the new Flash CC.
Usually, here on StackOverflow we like to see some code indicating you actually tried something, but let me see if I can help anyway.
Sounds like you are asking how to click a button and have the response be to load another swf into a new window.
To do so, you need to reference an html file with a swf embedded in it, since to see a swf in the browser it needs to be in an html page.
So you would do something like the following:
import flash.events.MouseEvent;
import flash.external.ExternalInterface;
var myUrl = 'http://www.someSiteWhereMyFilesAre.com/myNewSwf.html';
myButton.addEventListener( MouseEvent.CLICK, onClick );
function onClick( e:MouseEvent ):void
{
if( ExternalInterface.available )
{
ExternalInterface.call( 'window.open', myUrl, '', 'width=400,height=300' );
}
}
That method will only work while you have it online. It will not load the file locally.
If you do not care about the size of the window that is opened:
Remove the ExternalInterface import.
add imports:
import flash.net.URLRequest;
import flash.net.navigateToUrl;
Change your onClick function to:
function onClick( e:MouseEvent ):void
{
navigateToURL( new URLRequest( myUrl ), '_blank' );
}

How To Create a Preloader to a Flash Game

I'm just beginning to get into flash game programming. I know enough to make a functioning project, but not how to make it efficient or do specific tasks, in this case how to add a preloader. I've found several tutorials online, but none that go along with how I've seen is the best method to program. From what I've seen, it is best to program all of my code into one .as file and link this file to the main document. This makes it easy for me to make all of my variables global in scope, which lets me addChild/removeChild in various different functions. The only problem is that I can't find a tutorial on creating a preloader with this method in mind. All tutorials that I've found generally have two frames in the timeline, one with the preloader and one with the content, but I've been told this is not a good way to program. If anyone could help I'd appreciate it a lot. I can paste the source code of one of my learning projects if it would help to provide an answer to my question.
I wouldn't go with the 2 Frame approach. Instead just make your game with your Document Class, like you said you would like to do.
Then when your done, load your compiled game swf into a loader swf.
Here is a simple example on how your loaderSwf should look like:
import flash.net.URLRequest;
import flash.display.Loader;
import flash.events.Event;
import flash.events.ProgressEvent;
function startLoad()
{
var mLoader:Loader = new Loader();//Or use ProLoader
var mRequest:URLRequest = new URLRequest(“Game.swf”);
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
mLoader.load(mRequest);
}
function onCompleteHandler(loadEvent:Event)
{
addChild(loadEvent.currentTarget.content);
}
function onProgressHandler(mProgress:ProgressEvent)
{
var percent:Number = mProgress.bytesLoaded/mProgress.bytesTotal;
trace(percent);
}
startLoad();
(needs to be wraped in a package and Class if you are using it as Document Class)

How can I create a working swf that embeds a mp3

I am using the following code from the Adobe ActionScript guide
(Programming ActionScript 3.0 for Flex):
package {
import flash.display.Sprite;
import flash.media.Sound;
import flash.media.SoundChannel;
public class EmbeddedSoundExample extends Sprite {
[Embed(source="smallSound.mp3")]
public var soundClass:Class;
public function EmbeddedSoundExample() {
var smallSound:Sound = new soundClass() as Sound;
smallSound.play();
}
}
}
The resulting swf refuses to play, tested on two different machines
with two different operating systems (one WinXP desktop, one Zenwalk laptop).
Does anyone have a better example of embedding mp3s using Flex SDK
(i.e. not FlashBuilder or CSx).
Thanks
As it turns out, mxmlc wasn't embedding my assets until I invoked it with the following switch:
-static-link-runtime-shared-libraries=true
After that, the resulting swfs were fine.
I hope this helps someone else using flex SDK / mxmlc.

Using Squiggly in Flash CS5

This is going to seem quite a lame question - basically we have downloaded a package called Squiggly - http://labs.adobe.com/technologies/squiggly/ - and we are trying to implement it into Flash (using AS3, CS5). And none of us are very good at flash, and have no clue how to do it, the actionscript in the .as is as follows:
package
{
import flash.display.Sprite;
import flashx.textLayout.container.ContainerController;
import flashx.textLayout.elements.TextFlow;
import flashx.textLayout.conversion.TextConverter;
import flashx.textLayout.edit.EditManager;
import com.adobe.linguistics.spelling.SpellUIForTLF;
public class SquigglyTLFExample extends Sprite
{
public function SquigglyTLFExample()
{
var markup:XML = <TextFlow xmlns='http://ns.adobe.com/textLayout/2008'><p><span>I know </span><span fontStyle='italic'>Enlish</span><span>. Use the context menu to see the suggestions of the missbelled word.</span></p></TextFlow>;
var textFlow:TextFlow = TextConverter.importToFlow(markup, TextConverter.TEXT_LAYOUT_FORMAT);
textFlow.flowComposer.addController(new ContainerController(this, 500, 600));
textFlow.flowComposer.updateAllControllers();
textFlow.interactionManager = new EditManager();
SpellUIForTLF.enableSpelling(textFlow, "en_US");
}
}
}
I have a blank swf, and just want to know how to implement it to a text area. Why do people still use flash? :(
Here's how I got it running in a new FLA file in Flash CS 5:
1) In Flash, go into 'Advanced Actionscript 3.0 Settings' and change to the Librarys path tab on the middle of that pane.
2) Add the AdobeSpellingUITLF.swc.
3) When the SWC has been added, select it in the list and click the little 'I'-icon(when you hover it, it should say: 'Set linkage options for a library').
Change the link type to 'Merged into code'.
4) Add the code you posted (SquigglyTLFExample) as your Document class.
5) Remember to copy the 'AdobeSpellingConfig.xml' and the 'dictionaries'-folder to the same folder as the generated SWF-file.
The configuration in Flash should look something like this:
i have built a class based on squiggle a while ago: http://apdevblog.com/actionscript-spell-checking-with-squiggly-as3-only-and-flash-9-compatible/
it's very easy to use and compatible with normal textfields >flash9.
cheers