AS3 - how to start all over again a flash movie - actionscript-3

This may be very simple, but I have no idea how to do this.
I created a photo gallery in AS3, everything is on one keyframe. In this photo gallery I have a link to home. My goal is, when someone clicks the "home" link I want everything to start over. Any ideas on how to do this in AS3?
Appreaciate it.
L.

call flash player container
usually the HTML page and use JavaScript to reload the flash player
flash.external.ExternalInterface.call(jsFuncRestart);
jsFuncRestart is a JavaScript function in the HTML file
and now in the js function just create a new object and replace the current flash object
with the new one

You probably animate everything with as3, right? Then just make a reset function that puts all the images back to their original place and start the animation all over.

Related

User interface flash AS 3.0

since the Site seems to be pretty buggy i have to post my question below. Sorry for the inconvenience.
Hi guys
I'm new to flash and i want to create a GUI for my little game.
How can i create a start window where I can select stuff like how many objects to spawn or move speed of my character.
My first idea was to hide everything else on the stage until I click start.
Would that be right. Is the a better way. how to do this anyway.
And where do i put my GUI script. Stage or extern class.
Place your start button in the first frame and put your other elements in second frame. On click of the start button gotoAndPlay to next frame.

How to put music in individual scenes and have it change when i select a new scene

Alright I've managed to make an almost web page style thing in flash. I have all the coding to navigate the pages finished, but now I'm having the issue of when I change pages my main page music continues while the other pages music begins. I.,m unsure of how to code this. can anyone help? also I already have click sound effects going for my buttons and they seem to be working fine. Don't know if that helps at all. I'm also using flash cs6 and don't want to go to cc, because the removal of the bone tool.
To stop a sound, you will need to use a SoundChannel object when you tell the sound to play. Then, with the reference to the SoundChannel, you can stop the sound before you exit the section.
// save this reference for later so you can stop the sound when you want..
var mySoundChannel:SoundChannel = mySound.play(); // Get a sound channel.
// Call this later
mySoundChannel.stop();
Without a SoundChannel to control it, the sound object will do its default behavior, which is to play to completion.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/SoundChannel.html

AS3 AIR in app loading screen

I was wondering if someone could share some thoughts about how best to implement an in app loading screen.
I am building a mobile app using Starling and Feathers UI for iOS and Android and some times when a menu item is clicked to go to a new page it takes a few seconds due to the components that are on the stage on the called page. I would like to display a generic 'loading...please wait' screen which will have a message and a loading spinner which will be shown every time a new page is requested.
Thanks
This is how it's actually done, while you're directing your user to the frame, you make the loader MovieClip visible, the loader movie clip is a simple animation, like this:
loader http://www.pockettorah.com/wp-content/app/images/loader.gif
Make a movieclip and in instance name name it loader, and animate it like above
At the top of your code, say loader.visible = false;
In your code, after gotoAndStop/gotoAndPlay or whatever, say loader.visible = true;
There is no real way of displaying this, usually it's just a fake animation that displays while the data is being processed.
Its called a splash screen, it can be a simple jpeg. Adobe help here

How to ENTIRELY remove an flvplayback from stage when going to another flvplayback on another frame?

I'm trying to create an EXE projector using flash 5.5 AS3 where I have a few videos (FLVs) to show (their location is right next to the exe file in the same directory) - each load in a different frame, and all of those videos should also have a full screen option to them. Those are original videos that people WILL want to watch in full screen. It's essential for the experience...
The problem(s) I currently have (after fixing the sound that didn't stop after going to a different video) are hard to describe, but I'll try really hard.
Ok, so when I click the full screen button on a video and watch it in full screen, I will eventually want to exit the full screen, so I click on the same icon at the bottom to exit full screen (or ESC button, it's the same) and then click the navigation button to go to the SECOND FLV's frame to watch the other video. After watching the second video in full screen and then exiting full screen, flash takes me to the FIRST video's frame and that is a big problem. Also, now the button that takes me BACK to the second video's frame won't work. It's like flash is stuck.
I use the Components --> FLVPlayback 2.5 from the componant menu (I don't really know AS3 programming) and I fix its properties in the component parameters.
Also, I don't think that any of the followings are the reason for the bug, but I use these 3 scripts to stop all sound when navigating away from one frame (with an FLVplayback) to
another frame with another FLVplayback:
MyFLV.stop();
SoundMixer.stopAll();
MyFLV.addEventListener(Event.REMOVED_FROM_STAGE,xyz);
function xyz(e:Event):void{
MyFLV.stop();
}
I've found these online where people asked help for the sound bug I described.
The third script was suppose to remove the FLVplayback from the stage before going to another frame, but it works only when NOT GETTING INTO FULL SCREEN. I need something that will COMPLETELY remove the previous video from the stage so after exiting the SECOND viewed video, flash won't take me to a video that from some reason is still in its memory. I have something like 30 videos in my project and I need to remove each and every one of them off of the stage before navigating to the next frame to open a new FLVPlayback.
I tried to add a link to a demo I made with the problem so you can look at it, but it triggered a "oops, something went wrong" error, probably anti spam mechanism...
I would recommend using only one frame and only one flvplayback instance. Otherwise you have to deal with weird bugs like the one you are getting (usually caused by misplaced or forgotten code). Of course, using only one frame requires using more code, but with the number of hard-fixes it looks like you were making for the bugs, you may end up with less code.
Don't worry, I'll walk you through everything!
Reasons to use code (as opposed to multiple frames):
Easier to keep track of:
Know where all your code is so you can easily find and fix any problems.
Make changes more easily
You want to switch an existing video? edit a file reference and you are done.
Want to add a video? no more dragging a new flvplayback instance onto a new frame just add some very simple code and a button and you're done.
More customization
Reasons to use multiple frames (and multiple flvplayback instances):
easier to place visually
Some people find it easier when they have an actual movieclip that they can visually place on the stage
Less code
Here we go:
//import flv library
import fl.video.*;
This allows you to use ActionScript to manipulate the flv player
//video playback code-----------------------//
var myVideo:FLVPlayback = new FLVPlayback();
this creates an instance of FLVPlayback called myVideo (referenced from now on in the code as myVideo)
this next chunk shows many of the customizable features of the flv player. It is not necessary to include them.
//places the video player on stage at x,y
myVideo.x = 115;
myVideo.y = -10;
//uses SkinOverPlayFullscreen.swf for controls
myVideo.skin = "SkinOverPlayFullscreen.swf";
//color of controls
myVideo.skinBackgroundColor = 0x333333;
//hide controls and time it takes controls to fade and reappear (milliseconds)
myVideo.skinAutoHide=true;
myVideo.skinFadeTime=300;
//add the player to the stage
addChild(myVideo);
And now comes the important part. I have made buttons and added them to the stage. I gave each of the buttons a different instance name (box1_btn, box2_btn, and box3_btn). When someone clicks on a button, an "event" will occur.
//button listener code-------------------------//
//when button 1 is clicked throw button 1 event
box1_btn.addEventListener(MouseEvent.CLICK, clicked1);
//when button 2 is clicked throw button 2 event
box2_btn.addEventListener(MouseEvent.CLICK, clicked2);
//when button 3 is clicked throw button 3 event
box3_btn.addEventListener(MouseEvent.CLICK, clicked3);
//play different videos for different buttons---------//
//when button 1 event is thrown
function clicked1($e:MouseEvent):void
{
//play video 1.flv
myVideo.source = "1.flv";
}
//when button 2 event is thrown
function clicked2($e:MouseEvent):void
{
//play video 2.flv
myVideo.source = "2.flv";
}
//when button 3 event is thrown
function clicked3($e:MouseEvent):void
{
//play video 3.flv
myVideo.source = "3.flv";
}
This code will not have any sounds that keep playing because two videos cannot play at the same time in one instance of the player. Nor will it have any mess-ups when you come out of fullscreen because there is only one frame for the video to go back to.
Some possible problems you may run into:
It doesn't work at all:
Make sure you have added an instance of FLVPlayback to the library by adding an instance to the stage from the components menu (window>>components or ctrl+F7) and then deleting it from the stage (it should still appear in the library).
The playback buttons I want aren't showing up:
There is a great explanation of how to use As3 to manipulate FLVPlayback here:
http://www.republicofcode.com/tutorials/flash/as3flvplayback/
find the section about "Applying a Skin to the FLVPlayback Component" and follow it to use an adobe playback skin. If you want to make your own unique skin I would recommend opening and editing one of the pre-made skins. I found mine in
C:\Program Files (x86)\Adobe\Adobe Flash CS6\Common\Configuration\FLVPlayback Skins\FLA\ActionScript 3.0
I hope this helps!
Below would be simplest way to unload the FLVPlayback
removeChild(MyFLV);
it works fine for me
flvPlayBack.stop();
removeChild(flvPlayBack);
stops the sound and removes the playback.

AS3 - How to handle assets during preload

I'm having some difficulties with preloader and assets.
I'm working with FlashDevelop so pure AS3/Flex, no FLASH IDE
The thing is : when I try to addChild() something like a swf or event a simple png/jpg it kills the preloader completly (blanck screen until the game is fully loaded, then the preloader is launch (but the game is already loaded) so one frame later I'm after the preloader.
I think I missed something in the logic behind the management of the famous "first frame" and the loader progress event.
If someone have any idea about what I'm talking about. I'd like some light about the subject ^^
Thx !
-UPDATE-
I re-searched for more informations and found this post :
How does the preloader work in as3?
MichaelJW points my problem but doesn't answer it :
"You can do whatever you like in a preloader, but it won't run any of its code until everything needed by the preloader has downloaded. So if you make a preloader with a 3MB image file and a progress bar, the progress bar won't do anything until the entire image has downloaded!"
So how do you get to use some image to build a preloader ?
I have encountered this before and my "work around" was to build 2 separate loaders. The first is VERY light weight and loads all initial assets (like a rotating 5k png), the second if the "bulk load" of assets etc..
when the first is done loading it triggers the load of the second round of assets. You are right tho, you CANNOT use assets till they are loaded completely..