xml frame pause flash - actionscript-3

So is it posibble to create outside source from swf file so i can control frame pause lenght(xml file or AS pacage), and edit it with notepad. I have this code for each of my frames in swf file it goes like this:
Code on my first frame goes like this:
//PAUSE
function playit(e:TimerEvent):void {
play();
}
var Tim:Timer = new Timer(100, 1);
Tim.addEventListener(TimerEvent.TIMER, playit);
stop();
Tim.delay = 100; //Adjust Accordingly - 1000 Equals 1 Second
Tim.start();
And on the rest of the frames (10 more frames) goes like this:
//PAUSE
stop();
Tim.delay = 10000; //Adjust Accordingly - 1000 Equals 1 Second
Tim.start();

Sorry to say it, but your code is a bit messy. If you are actually trying to set how much frames should be played per second (as I can see the timer), you should check frameRate property. You can read specific number from a source file and then set it with ActionScript.
You won't need all those play/stop/timer things..
Hope that's the idea, otherwise I'm speechless..
p.s.
If you still need some other kind of solution - use nextFrame/prevFrame with that timer, don't play/stop it all the time..

The solution is simple but require a bit of math. Instead of letting the movie play you need to use your own custom system based on gotoAndStop(). You calculate the right timing and then call gotoAndStop() at the right moment with a variable of int type increasing on each call.

Related

Trigger a frame update in Flash

I've encountered a case where I'm calling code that causes a flicker in a bitmap data. Without changing the frame rate to a much higher value (don't know if this is possible to change dynamically at runtime) is it possible to redraw the frame quickly?
In the old days you could cause Flash Player to manually update the frame by calling updateAfterEvent(). Does this still work? Is there another way to update the frame?
Here is what I have so far:
// force redraw
var updateEvent:MouseEvent = new MouseEvent(MouseEvent.MOUSE_MOVE);
updateEvent.updateAfterEvent();
If it's local variables will this get garbage collected?
If you're changing a something during enter frame listener, it should get updated automatically. Otherwise, use updateAfterEvent() in a non-enterframe listener.
function onMouseMove(e:MouseEvent):void {
// ... code that changes something
e.updateAfterEvent();
}

AS3 Global Variables

Ok so I have managed to do this once before but I simply cannot remember how or find the source I found back then. I am making a simple flash game. There are several characters moving. To make each level more difficult than the other I have decided to alter the movement speed of each character from level to level. If I declare and assign values to these variables on my main timeline in frame 1 it doesn't work the way I want it. When you go to level 2, which is in another frame, the speed goes up like it should. But when you go to the next level, which is level 1 with higher movement speed, the value assignment is processed again, which means the movement speed goes back to scratch.
//frame 1
var speed:int = 5;
//level accomplished, speed++, goto frame 2
//frame 2
//level accomplished, speed++, goto frame 1
And then all the code on frame 1 runs again, setting the value of "speed" back to 5.
I have tried putting the variable in a class, but the problem is still the same, everytime it goes back to frame 1 the code "var speed:Speed = new Speed();" runs again and the value of the variable goes back to whatever I assigned in the speed.as file.
I have tried so many different combinations to just make the global variables inside a package but outside any class so that it is always globally accessible without creating a new object.
Here is my current code:
//speed.as
package
{
public var speed:int = 5;
}
//game.fla
import speed;
trace(speed);
This throws the error "Access of possibly undefined property speed..."
As I said, I have tried many different combinations and got a lot of different errors, been googling and digging for 8-9 hours and it's driving me crazy. You guys are now my last hope, I would be very grateful for an answer easily telling me how to use my global variables (I know global variables are bad, seen a lot of people writing it even though I don't really know why), if there is another easy and better solution please do tell, but I don't want to rewrite the entire code or anything to make it compatible with some other solution. I know that global variables will solve this problem for me, I just don't know how to use them.
I will need instructions on what to do in both the .as file and the .fla file. Thanks in advance!
Does it cycle between frame 1 and 2? If it does, use functions to do it instead. You don't need the .fla.
//Declare variables
var speed:int = 5;
//In this case I use a button to transit into the frame. Edit the code as you wish.
btnLevel1.addEventListener(MouseEvent.CLICK, level1);
private function level1(e:MouseEvent):void
{
MovieClip(root).gotoAndStop(2);
speed++;
//Your other code for the level goes here
btnLevel2.addEventListener(MouseEvent.CLICK, level2);
}
private function level2(e:MouseEvent):void
{
MovieClip(root).gotoandStop(3);
speed++;
//Again, your other code goes here
btnLevel1.addEventListener(MouseEvent.CLICK, level1);
}
Should work, I think.
I think you should try changing it to
package{
public class Speed{
public static var SPEED:int = 5;
}
}
and then access it via
trace(Speed.SPEED)
But: this is very dirty :)
Ok so I found a little workaround, not global variables in a separate package, but variables that can be accessed by my entire timeline.
I simply made an extra frame with just code. In this frame I put my variables + a frameCounter variable. On my first frame I put this code:
if (frameCount == 0)
{
gotoAndStop(7);
}
So the code declaring the variables only runs once. Probably not the best solution but atleast it works as intended =)

AS3 save previous frame while going in next to do something

Is posible something like this: in frame1 I have some user interaction (drag drop graphics etc), when user click some button I open frame2 or frame3 where are fields for taking some input from user, then when user finish, I back him to frame1 but frame is not "reset"? I tried what described here, and I can even send data from frame 2 to frame 1 using global vars, but frame 1 is "reset" all user actions are clean, so is there a way in this situation to keep frame1 in memory or something?
Previous or next go to a frame if the frame is being initialized is natural. There's no way to save it. In other words, move the frame is The following concepts, removeChild(previous-stage), addChild(next-stage)
In my experience, the script code to control the frame, increasing complexity are highly undesirable. Maintenance is difficult and in the future, the readability of the code is very poor. Recommend to handle than that in a single frame. Something like a single frame of the object location, size, status, and stored as a variable because it can restore it, it's more reasonable to think that.
If you are working with Flash & AS3 together you can put the code:
gotoAndStop(3); // 3 is the number of the frame
If you are using:
gotoAndPlay(3); // it will begin to play the frames from 3 till the timeline finds a stop mark.
So, you'll need to put a stop on the frame you want.
e.g. stop();
check out this tutorial: http://www.youtube.com/watch?v=9N9vE7wjoc4

Cross fading sounds after event in Flash CS5

I am looking to cross-fade two sound files after an event (such as a button press) in Flash CS5.
Ideally, the first sound loops round until a button press at which point a fade out will begin with sound 2 simultaneously fading in. I have a pretty limited understanding of actionscript 3 .
Thanks for your help :)
In order to achieve this effect you will need to use two soundChannels. Since your using cs5 I am assuming your are looping your first sound file like so (and if not you should be):
var sc1:SoundChannel = myFirstSound.play(0, 999);
now when the event is called (button is clicked) you will want to decrease the volume of the first sound file and increase the volume of the second sound file. To do this you can use the soundTransform property on your soundChannels. this would be an example of decreasing the volume.
sc1.soundTransform = new SoundTransform(sc1.soundTransform.volume - .1, 0);
you would decrease the volume of the first sound file like this in an enterframe loop. also in this loop you would need to increase the volume of the second sound file:
var sc2:SoundChannel = mySecondSound.play(0, 999);
sc2.soundTransform = new SoundTransform(0, 0);
then inside the enterframe loop to increase the second sound it would be the same as above, but addition instead of subtraction:
sc2.soundTransform = new SoundTransform(sc2.soundTransform.volume + .1, 0);
the .1 in this case is how fast to fade the sound. you may have to play around with that. and once the first sound files volume hits zero you should remove it and end the loop. Anyways, I think this is enough information in order to complete your goal. good luck.

As3 Preloader (Blank until 100%)

I have an FLA file with two frames. On the first frame I have nothing but a textfield and some code to do the preloading. After it is done preloading it does gotoAndStop(2)
On frame 1 I have:
stop();
stage.scaleMode = StageScaleMode.SHOW_ALL;
//Import the required assets
import flash.display.*;
//Stop the playhead while loading occurs
this.stop();
//Create a listener to call the loading function as the movie loads;
this.loaderInfo.addEventListener(ProgressEvent.PROGRESS, PL_LOADING);
this.loaderInfo.addEventListener(Event.COMPLETE, PL_FINISH);
function PL_LOADING(event:ProgressEvent):void
{
var pcent:Number = event.bytesLoaded / event.bytesTotal * 100;
//Display the % loaded in textfield
txt.text = int(pcent) + "%";
//If the movie is fully loaded, kick to the next frame on the main timeline
}
function PL_FINISH(event:Event):void
{
removeChild(txt);
gotoAndStop(2);
}
On frame 2 I have nothing except:
var game:Game = new Game();
addChild(game);
In my publisher settings I have export to frame 2.
My problem is that the preloader won't display until 100%. Does anyone know why?
P.S. For testing I put a large image file on the stage in frame 2 and the result is the same.
This normally happens if you haven't deselected "Export in frame 1" in each of the library symbols that you are exporting for ActionScript.
You'll need to make sure that you create reference to these objects (so that ActionScript can access them) by placing them onto the stage in frame 2 (out of sight).
What's happening is that all of the symbols are being loaded before the preloader itself has loaded.
If this isn't the issue, then please provide some code so I can better assess your issue.
Have you tried putting something static on frame one? Just because there is a preloader, that doesn't mean that your swf will be displaying at all...
I know that I had one swf once which simply took a minute to actually get the Flex preloader to even show up because of network latency. It could be that your swf isn't displaying until 90% of it has already loaded.
I´m dealing with similar problems, and there is something i found out: my antivirus contains a kind of "browser protection" feature, which sort of checks all files in advance before it allows the browser to actually display them. If this antivirus feature has not been installed on the system, the preloader works beautifully. I´ve checked some other web-sites with flash content, and they also behave "wrong" under these circumstances. Now, some people seem to have found a way to stop the antivirus from messing around, but i don´t know how they do it... not yet...