Resize embeded FLIPBOOK in a .fla file - actionscript-3

I’m having the same problem every time I want to resize the Swf file of any flipbook (or Swftools template) as an external load in my main Flash website, through AS3. They always take the whole surface of the screen automatically, even if I’m using the same code for setting external proportions in general… That doesn’t work. I suppose I have to force the internal and encrypted code in those Swf files, because flipbook templates never provide a .fla files or any AS3 (in html it’s ridiculously easy, but unfortunately my entire site is flash-based). Any help? Thanks in advance!
var loader:Loader=new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,f);
loader.load(new URLRequest("flipbook.swf"));
function f(e:Event):void{
addChild(loader);
//////RESIZE EXTERNAL LOAD///////
loader.width = 700;
loader.height = 500;
}
////SET LOCATION EXTERNAL LOAD/////
loader.x = 100;
loader.y = 200;

Related

How make with AS3 downloading MP3 files in the background mode and plays it?

I need help with AS3 make downloading MP3 files in the background mode. Man goes to my site and it will automatically load MP3 file on his computer and plays it. I read these examples here http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLLoader.html but do not know how to do it? Prompt what code and how to use it properly?
You can directly load a Sound object with an URLRequest instead of using a separate Loader or URLLoader. A code could look like this:
// this code should reside in a function somewhere
var request:URLRequest = new URLRequest("http://your.site.com/your.mp3");
var sound:Sound = new Sound(request;
sound.addEventListener(Event.COMPLETE, completeHandler);
// this function should be at top level anyway
private function completeHandler(event:Event):void
{
var loadedMP3:Sound = Sound(event.target);
if (loadedMP3) loadedMP3.play();
}
Extra error handling is up to you.

Why won't dynamically loaded images in flash as3 display in Google Chrome?

I am working on a flash game where some of the content can vary from web page to web page depending on HTML parameters. Unfortunately, when I try to load the images in Google Chrome and send the bitmap itself to the stage, nothing shows up. I have been able to identify that this undesirable is due to the Pepper Flash plugin that comes with Chrome, as it works with the manually installed flash plugin.
It will be a pain for the user to have the users download a plugin that they think they already have just to use my game. It is necessary for my game to access the bitmaps themselves, because they will change color. How can I work around the undesirable behavior in Chrome's Pepper Flash plugin?
Below is a sample of what I am doing.
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
//could be any image, as long as image1.jpg is in the images directory relative to the HTML page
//eventually will be taken from a parameter.
var url:String = "images/image1.jpg";
var request:URLRequest = new URLRequest(url);
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaded);
loader.load(request);
}
private function loaded(e:Event):void
{
image = Bitmap(loader.content);
image.bitmapData.colorTransform(new Rectangle(0, 0, image.bitmapData.width, image.bitmapData.height), new ColorTransform(2, 1, 0.5, 0.25, 10, 10, -10, -10));
graphics.beginBitmapFill(image.bitmapData);
graphics.drawCircle(stage.stageWidth/2, stage.stageHeight/2, (image.width + image.height) / 4);
graphics.endFill();
}
There will be transformations other than this sample, but unless there is a way around this glitch/undesired feature/bug, the game can not be played properly on the average Google Chrome browser without work for the user.
push it onto a server. chrome has some extra security when you're running from localhost.

as3 loading screen

How do you create these "loading, please wait" splash screens with a loading bar and percentage for your swf? Does as3 have some built-in methods or should it be designed from scratch?
I mean, how do you detect that your swf file is being loaded into client's browser?
Oh and I have all my content stored in one frame only. pure as3 code.
If all of your code is on the timeline, then the easiest way is to make a second swf that is only used for loading your main swf. If your main swf is called main.swf, the code in your loading swf would be something like this:
//make a loader
var loader:Loader = new Loader()
//listen for loading progress
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress);
//listen for when the load is finished
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
//load begins...
loader.load(new URLRequest("main.swf"));
function onProgress(event:ProgressEvent):void
{
//calculate how much has been loaded
var percentageLoader:Number = event.bytesLoaded / e.bytesTotal;
//use your percentage number here to drive a loader bar graphic
}
function onComplete(event:Event):void
{
//remove listeners now that loading is done
loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, onProgress);
loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onComplete);
//add loaded swf to the stage
addChild(loader.content);
}
As an aside, externalizing your assets opens up new preloading possibilities. Instead of having everything in your main swf, you can have your main swf load external assets, and preload those assets. Since your main swf would then be small, there would be no need to have a second swf just for loading your main swf.
There's a few different ways to do this.
Either you can have a two step process - create a swf file that simply loads in the main file, reporting progress (by listening to the progress-event on the loader) and then adding the loaded swf as a child.
Or, you can place all your content on frame 2, and stay on frame 1, checking the root.loaderInfo.bytesLoaded compared to root.loaderInfo.totalBytes values, reporting the percentage and then moving on to frame 2 when done.
Personally, I think method 1 is better, since you don't need to sully yourself with frames.
There is also a third way which uses some weird meta-data tags to simulate the second way, but without frames. It's a bit messy, but should be googleable.
Flash has its own component you can use to accomplish this:
http://help.adobe.com/en_US/ActionScript/3.0_UsingComponentsAS3/WS5b3ccc516d4fbf351e63e3d118a9c65b32-7fa4.html
Or you can build your own progress bar from scratch:
http://www.zedia.net/2008/the-right-way-to-do-a-preloader-in-as3/
There are lots of resources on the web that allow you to customize the progress bar- browse around and find one that works for you and your coding style.

Cannot mask Stage3D SWF in Loader

Working in FlashBuilder, I build a mobile AS3 application that uses a Loader to display a local SWF file. It masks the loader so it only shows a 640x480 window. This worked fine using an old SWF file (a Flixel game, non-Stage3D).
I then tried it with a Stage3D-enabled SWF file. This failed to run, because the application was not set to run in the 'direct' renderMode (it had been in auto up until this point). This allowed the application to run, but the SWF file now ignores the Loader's mask and displays across the entire stage.
Is it not possible to mask Stage3D SWFs when loaded in this way? The loading looks like so:
public function FlixelTest()
{
super();
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
myLoader.x = (stage.fullScreenWidth-640)/2;
myLoader.y = (stage.fullScreenHeight-480)/2;
var url:URLRequest = new URLRequest("stage3dswf.swf"); // in this case both SWFs are in the same folder
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadProdComplete);
myLoader.load(url); // load the SWF file
addChild(myLoader);
}
private function loadProdComplete(e:Event):void{
var gameMask : Shape = new Shape;
gameMask.graphics.beginFill(0xffcc00);
gameMask.graphics.drawRect(myLoader.x,myLoader.y,640,480);
gameMask.graphics.endFill();
myLoader.content.mask = gameMask;
}
As you can read in Adobe's documentation on Stage3D, the special Stage3D layers are located "behind" the regular stage used for 2D content.
Since any mask applied within the 2D stage exists in a different display list, there is no way to use 2D masks on Stage3D content. If at all possible, the only way to get similar results is to use 3D layers and alpha masks within the Stage3D context.

Audio of a specific video swf doesn't stop when I load another URLRequest

I am trying to stop the audio of the video swf and I can't get it to stop. Here is my code for loading the file:
var myLoader:Loader= new Loader();
myLoader.x=420;
myLoader.y=200;
// boolean variable set for use below in our function
var screenCheck:Boolean = false;
//These three linces keep stafe elements the same size, so they don't distort
var swfStage:Stage = this.stage;
video_btn.addEventListener(MouseEvent.CLICK,contentvideo);
function contentvideo (event:MouseEvent):void{
myLoader.load(new URLRequest("prevideo.swf"));
addChild(myLoader);
movie_btn.stop();
movie_btn.visible=false;
}
Now I have other functions that load different URLRequest and when they are loading, the audio keeps playing. Do I have to add a line of code to them? I also have an MP3 player and tried SoundMixer.stopAll(). I still need the mp3 player to keep playing.
I'm not familiar with what you're doing but just looking at the code and given the problem you're experiencing I wonder if that
addChild(myLoader);
has anything to do with it. It seems like the kind of thing that could easily create multiple child objects which is why you continue to experience the sound play back. Is there a removeChild[0] option or something?
A shot in the dark I know but I thought I'd offer the possibility anyway.