AddEventListener And Event.ENTER_FRAME Problem
I need a little help with because I can't not see why this is not working. I have a website with several pages, and each page is a flash scene. I also have this var GoToNextScene. And whenever I click at a button to go for a page, I change the GoToNextScene var to the value of that page, reproduce the fading out animation for the current scene, and when it comes to the last frame of the current scene, it should run this code, and it is runing, but for some reason it is not going to the another scene. And if I remove this code and add just the gotoAndPlay, it will work. Can anyone help me with this? Thanks.
Code:
addEventListener(Event.ENTER_FRAME,myFunction); function myFunction(event:Event) { switch (GoToNextScene) { case 0 : this.gotoAndPlay(1, "Intro"); break; case 1 : this.gotoAndPlay(1, "Home"); break; case 2 : this.gotoAndPlay(1, "A Empresa"); break; case 3 : this.gotoAndPlay(1, "Produtos"); break; case 4 : this.gotoAndPlay(1, "Contactos"); break; } }
FlashKit > Flash Help > Actionscript 3.0
Posted on: 09-18-2008, 06:29 AM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
- AddEventListener And Event.ENTER_FRAME Problem
- Adding Multiple Event Listeners To The ENTER_FRAME Event, Calling Different Functions
- Event.ENTER_FRAME
- ENTER_FRAME:Event Issue
- ENTER_FRAME And Event Prioritizing
- Deleting ENTER_FRAME Event
- A Better Way? Trying To Avoid Event.ENTER_FRAME
- Trouble Using Event.ENTER_FRAME
- [AS3] Event.ENTER_FRAME Getting Clipping
- Cannot Make Event.ENTER_FRAME Work, I Am New To AS3
- Perfomance Issue With ENTER_FRAME Event
- Triggering ENTER_FRAME On A Mouse Event
- Event ENTER_FRAME Stops Other Events?
- Event.enter_frame Only Fires Once? Prob Easy...
- Pass Event.currentTarget On To Another ENTER_FRAME Function
- .addEventListener(event, FunctionInSeperateAs)?
- AddEventListener(<event>, UnZoomClick <more Params>)?
- I Can Never Get AddEventListener(Event.PROGRESS... To Work
- [CS3] ContentLoaderInfo.addEventListener(Event.INIT Problem
- MyClass.addEventListener(onChange.Change,func); Event, Is It Possible? How?
- AddEventListener(Event.COMPLETE, OnLoaded) Function Problem
- Return A Obj From A Class, After A URLLoader.addEventListener(Event.COMPLETE,onJSON);
- Variable.addEventListener OR DynamicVariable.addEventListener
- ENTER_FRAME Handler
- Why Can't I Use ENTER_FRAME In A Timer?
- Terminate ENTER_FRAME ?
- ENTER_FRAME Undefined?
- Problem With ENTER_FRAME Help Please
- ENTER_FRAME Issue
- Better Than ENTER_FRAME For This Project?
- ENTER_FRAME Listeners..
- Particals + ENTER_FRAME
- Conquering ENTER_FRAME :)
- Slow Down ENTER_FRAME
- ENTER_FRAME Lags In CS4?
- GotoAndStop(); Not Running Along With ENTER_FRAME?
- ENTER_FRAME Is Not On Line With Framerate?
- Is Tweenlite Faster Than ENTER_FRAME ?
- Problem With Reversing ENTER_FRAME
- Noob ENTER_FRAME Question
- ENTER_FRAME Return Values
- Stopping ENTER_FRAME Motion
- Stopping A ENTER_FRAME Function
- Fading A Movieclip Using ENTER_FRAME
- ENTER_FRAME's 1 Parameter Limit
- Multiple ENTER_FRAME, EventListeners?
- Good OO Practice: ENTER_FRAME
- One ENTER_FRAME Vs Multiple ENTER_FRAMES
- AS3 And Tweener Enter_Frame Events
AddEventListener And Event.ENTER_FRAME Problem
I need a little help with because I can't not see why this is not working. I have a website with several pages, and each page is a flash scene. I also have this var GoToNextScene. And whenever I click at a button to go for a page, I change the GoToNextScene var to the value of that page, reproduce the fading out animation for the current scene, and when it comes to the last frame of the current scene, it should run this code, and it is runing, but for some reason it is not going to the another scene. And if I remove this code and add just the gotoAndPlay, it will work.
Can anyone help me with this?
Thanks.
Code:
addEventListener(Event.ENTER_FRAME,myFunction);
function myFunction(event:Event)
{
switch (GoToNextScene)
{
case 0 :
this.gotoAndPlay(1, "Intro");
break;
case 1 :
this.gotoAndPlay(1, "Home");
break;
case 2 :
this.gotoAndPlay(1, "A Empresa");
break;
case 3 :
this.gotoAndPlay(1, "Produtos");
break;
case 4 :
this.gotoAndPlay(1, "Contactos");
break;
}
}
Event.ENTER_FRAME
Hi guys,
If I add an event listener for Event.ENTER_FRAME can it interupt my function ? This is what I mean:
public function myFunction() : void {
a=1;
b=2;
c=3;
// frame gets entered, will it jump to the listener function right here ?
d=4;
e=5;
f=6;
}
Thanks.
ENTER_FRAME:Event Issue
I have a video playing and when it completes (it's time property is greater than 3.3) buttons appear on the stage (AddChoiceGen2). When the user clicks one of the two buttons they are removed and the next video begins to play. This process is to continue numerous times.
The problem I'm having is that as soon as the buttons are removed from the stage the next set of buttons instantly appear (ignoring the videoStream.time). Is there a way to reset the .time before playing it again in the next video? Or do I need to reset something? Or do I need to do something different?
Any help is much appreciated. Thank you in advance.
PHP Code:
//monitor the video AddChoiceGen1
function checker1(ENTER_FRAME:Event):void{
if (videoStream.time >= 3.3) {
trace("VidGen1 is finished!");
AddChoiceGen2(null);
this.removeEventListener(Event.ENTER_FRAME, checker1);
}
}
//functions called by CLICK of buttons (Decision 1)
function vid1Play(CLICK:Event):void{
videoStream.play("vid1.flv");
//Monitor the video
this.addEventListener(Event.ENTER_FRAME, checker1);
}
ENTER_FRAME And Event Prioritizing
I've got a Sprite(sChild) inside another Sprite(sParent)
both have the typical enter frame listener and a trace function
when I run it, I get this
sParent enter frame
sChild enter frame
repeating in that order
essentially the parent is prioritized and fires before the child
here's the question, how can I get it to reverse?
essential I would want the parent to have a on exit frame, so that it fires last.
other than creating my own dispatcher class, is it at all possible ?
Deleting ENTER_FRAME Event
I added an ENTER_FRAME event listener to the stage. I want to remove it when the endQuiz function runs, how could a go about doin this? Thanks.
Attach Code
stage.addEventListener(Event.ENTER_FRAME, checking);
function checking(event:Event):void
{
//question_txt.text = allQuestions[current_question];
//getChildByName("block" + current_question).alpha = 1;
if (current_question < numberOfQuestions)
{
question_txt.text = allQuestions[current_question];
getChildByName("block" + current_question).alpha = 1;
} else {
endQuiz();
}
}
function endQuiz():void
{
//this function will trigger actions that will end the quiz and show your results
question_txt.text = "You have completed the quiz. How do you think you did?";
next_btn.visible = false;
//enter_btn.visible = true
stage.removeEventListener(Event.ENTER_FRAME); // <---how's this part go?
}
A Better Way? Trying To Avoid Event.ENTER_FRAME
I've got a Parent SWF that loads a few child SWFs, one at a time. I've got some global variables set up in class, that allows me change properties of child2, based on what the user selects in child1, since I can share the variable amongst any SWFs that import that class.
That works great, save for the fact that I need some way of triggering the function in the Parent SWF that unloads child1 and loads child2.
Right now, all I can cook up is using and event listener with Event.ENTER_FRAME in the parent to see if a variable coming from child1 has been changed from it's default - and if it has run my function to change out the child SWFs.
Sure this constantly checks for changes - but it seems there's a better way to check for updates like that.
I can't call any functions in another SWF, like on might with localConnection - so I've got to rely on something in the Parent to do my checking. And yes, I've tried local connection - but it got surly when I did more than one Child swap.
I'm still learning, so be sure to sound out any explanations
Trouble Using Event.ENTER_FRAME
Hi all, I've just started using flash again and I've jumped into this new project feet first and upgrade my knowledge of ActionScript from 1 (and a bit) to 3. I have some pretty good experience of OOP languages so it's not completely foreign to me!
So the problem I'm having shouldn't really be a problem at all and I don't understand what's going on. It's all about adding a listener for Event.ENTER_FRAME to a movieclip.
This does not work for some reason:
Code:
public function setupListener(){
myClip.addEventListener(Event.ENTER_FRAME,doEnterFrame);
}
private function doEnterFrame(e:Event){
trace('doing it!');
}
But for some reason this does:
Code:
myClip.addEventListener(Event.ENTER_FRAME,function(){
doEnterFrame();
});
private function doEnterFrame(){
trace('doing it!');
}
The problem being that passing an anonymous function means I can't reference it for when I need to call removeEventListener.
Any idea whatsoever why I might be getting this behaviour?
[AS3] Event.ENTER_FRAME Getting Clipping
Hey,
I am trying some animation using actionscript and the only place in the code that changes the propeperties of any ojbect that is in displayList is called like:
ActionScript Code:
addEventListener(Event.ENTER_FRAME,drawTree);
private function drawTree(e:Event):void
{
// change some properties of objects in the display list.
//like dispObj.x = 23;
//like dispObj.y = 23;
}
framerate i am using: 50
The problem is it looks like I am getting clipping or something? when the green squares are animating and the object isnt fully drawn or something when the screen is being refreshed?
example of clipping:
http://www.davegeurts.com/TTas3/tree.html
THANKS for anybody with some free time!
Cannot Make Event.ENTER_FRAME Work, I Am New To AS3
Hey. I am struggling to make this simple function work. It was an AS1/2 onEnterFrame function and i thought making it work in AS3 should be easy. Here is my code. Great if anyone can point to the basics i have to do to make this work.
ActionScript Code:
[font="Courier New"]
import flash.display.*;
import flash.events.*;
function Main() {
stage.addEventListener(Event.ENTER_FRAME, sprelling());
}
Main();
function sprelling(){
trace("Potte");
//lux = this._xmouse;
//luy = this._ymouse;
var lux = stage.DisplayObject.mouseX;
var luy = stage.DisplayObject.mouseY;
//trace (luy);
stage.sprell.rotation = (((((lux)-(350))*(-0.005)))+(((luy)-(50))*(0.08)));
stage.sprell.laar.rotation = ((((lux)-(350))*(-0.01))+(((luy)-(50))*(-0.15)));
stage.sprell.laar.kropp.rotation = ((((lux)-(350))*(0.06))+(((luy)-(350))*(0.07)));
stage.sprell.laar.kropp.arm.rotation = (((lux)-(350))*(0.04));
stage.sprell.laar.kropp.bakarm.rotation = (((lux)-(350))*(0.04));
stage.sprell.laar.baklaar.rotation = (((lux)-(350))*(-0.03));
stage.sprell.laar.baklaar.bakfot.rotation = (((lux)-(300))*(0.06));
}
Perfomance Issue With ENTER_FRAME Event
Hi all, i've been working on this for some time, its a text marquee that i use in lots of applications, just recently upgraded it to AS3, but i've always had performance issues, that i tought would be over with the conversion, but that is so not true, so i ask for your help.
Here is the snippet that i think is causing all the trouble.
ActionScript Code:
private function CreateTextMotion(spr_Source:Sprite):void {
try {
//GOOD FIX, enhaces a bit
spr_Source.cacheAsBitmap = true;
spr_Source.x=- spr_Source.width;
spr_Source.y=mint_Height / 2 - spr_Source.height / 2;
spr_Source.addEventListener(Event.ENTER_FRAME,AnimationDealer00,false,0,false);
}
var mbool_Enter:Boolean=new Boolean;
//### DIRECTION 0 - ORITENTATION 0
function AnimationDealer00(e:Event):void {
var currentX = e.currentTarget.x=e.currentTarget.x + mint_Speed;
if (currentX - mint_Height > 0 && mbool_Enter == false) {
if (mbool_Reload == false) {
NextEntry();
}
mbool_Enter=true;
}
if (currentX > mint_Width) {
removeChild(spr_Source);
spr_Source=null;
e.currentTarget.removeEventListener(Event.ENTER_FRAME,AnimationDealer00,false);
}
}
} catch (error:Error) {
SendToLog("ERROR-CreateTextMotion: " + error.message);
}
}
Basically what this does is as soon as the sprite is fully inside the screen the next one goes in, and so on, when the sprite leaves the screen i erase it and its listener.
The problem is in the performance, in regular pc's (not very old) it runs nice and doenst take up too much CPU, the problem is that this is for machines that run celerons under 1ghz, and i really have to save a lof ot cpu , now it is around 50%, with the scroll , and i have to narrow it down to at least half, because videos will have to be played also , and i cant drop fps below 30, otherwise the motion becomes choppy.
Any hints on the drop the load, i've tried out with tweens, but i cant work with them , because text is received from a xml, and it has various lenghts, so tweens would have to have diferent times also, i think i really cant have anything simpler than incrementing the x, but i do need sugestions.
cacheasbitmap helped to trim a bit on the load, i'm not using embed fonts also, but in the future i probly going to have to.
so any and all help is usefull, already tried to add weakreference to the listeners, but its no good because i need them working all the time.
if you guys want i can post the whole class, but i think the issue is in this function.
Triggering ENTER_FRAME On A Mouse Event
So i posted this other post in the General Flash section. But i had no luck there so far, so i thought i'd give it a go here as well, now that i've made an attempt in AS3.
Code:
import flash.events.MouseEvent;
import flash.events.Event;
maskMC.addEventListener(MouseEvent.CLICK, maskclick);
function maskclick(event:MouseEvent) {
addEventListener(Event.ENTER_FRAME, onenterframe);
}
function onenterframe(event:Event) {
if (maskMC.DisplayObject.scaleX < 1000) {
maskMC.DisplayObject.scaleX += 15;
}
}
So as i said in my other post, basically i have this shaped stored within a movieclip, instance named maskMC, that i want to work as a mask for a picture (I want there to be a roll over function as well, but i have to start somewhere). And after a very quick introduction to AS3 i made an attempt there as well. But this just simply wouldn't work at all this time.
So my question is, how do i get what i described above to work? Or does it even work?
Event ENTER_FRAME Stops Other Events?
Hi,
I've adapted Lee's Caroussel into AS3 , got it working perfectly. Later on i converted it into a class and still no probs.
But i keep encountering some strange behaviour:
All the spinning items have the ENTER_FRAME and MOUSE_OVER/OUT/CLICK EventsListeners attached,
yet when i'm testing for MOUSE_OVER/OUT/CLICK nothing happens, the functions just won't fire so to speak.
Yet, when i comment out the item.addEventListener ENTER_FRAME, suddenly all the item MOUSE Events start to respond.
Same goes for item.addEventListener(Event.ENTER_FRAME, mover, true). The caroussel doesn't spin, but the MouseEvents
fire.
Can anybody help me? Where did i go wrong from a working stage/fla based caroussel to the class where only one half is
working. What am i missing?
(class package and stuff is as it should be, isn't my first class)
Any suggestions?
Thx!
Event.enter_frame Only Fires Once? Prob Easy...
Hello there,
I've got a strange error occurring. I'm trying to have a symbol drawn to BitmapData every frame, and I've made addEventListener(Event.ENTER_FRAME, function) but it only fires once, even though I've set my movie at 24FPS and made multiple frames in the scene (I've tried with only one frame too).
Here's my code:
ActionScript Code:
import caurina.transitions.*;
var bmd:BitmapData = new BitmapData(720, 70, true, 0x000000);
var bm:Bitmap = new Bitmap(bmd);
addChild(bm);
var bf:BlurFilter = new BlurFilter(8,8,3);
addChild(title2);
function mover():void
{
Tweener.addTween(title2, {x:200 , time:1});
}
mover();
addEventListener(Event.ENTER_FRAME, loop);
function loop(e:Event):void
{
bmd.draw(this);
bmd.applyFilter(bmd, bmd.rect, new Point(0,0), bf);
}
any ideas? I want to have it draw the current position of the tween'd object "title2" each frame, but it only does the last one.
Pass Event.currentTarget On To Another ENTER_FRAME Function
i've got a function associated with a mouse event listener with one clip which sets the x and y of another clip (here it's 'myClip') as well as specifying the ENTER_FRAME function for that clip:
Code:
function mcOver(event:MouseEvent):void{
myClip.x = event.currentTarget.x;
myClip.y = event.currentTarget.y;
myClip.addEventListener(Event.ENTER_FRAME, moveClip);
}
then i have a function that i want to use for the ENTER_FRAME function which will cause the second clip ('myClip' again) to continue to follow the clip targeted with the mcOver function above:
Code:
function moveClip(){
myClip.x = ??? // need to target the event.currentTarget of the 'mcOver' function above
myClip.y = ??? // ditto.
}
I'm not sure how to target the currentTarget of that first mouse event within the enter frame function... I know there was a delegate method/class in AS2... how can i do this in AS3???
thanks for any help!
.addEventListener(event, FunctionInSeperateAs)?
Question!
Is it possible to register an event listener with an object in a custom class that calls a function from the main document class? Or perhaps, call a function from the main document class from a function in the custom class?
(If it is possible, is that a bad idea, prone to causing conflicts later?)
AddEventListener(<event>, UnZoomClick <more Params>)?
Code:
myObj.addEventListener(MouseEvent.CLICK, clicked);
Is there a way to pass parameters to clicked? say, I want to send it an array something like this:
Code:
var list:String = "one,two,three,four";
var myArray:Array = list.split(",");
myObj.addEventListener(MouseEvent.CLICK, clicked(myArray));
function clicked(e:MouseEvent, arr:Array)
{
// stuff
}
I Can Never Get AddEventListener(Event.PROGRESS... To Work
Whenever I try to use the progress event for any type of loading, I always get this error:
Desc: 1119: Access of possibly undefined property PROGRESS through a reference with static type Class.
Source: picLoader.addEventListener(Event.PROGRESS, picProgressHandler);
What am I doing wrong?
This code is straight from Adobe's example...
http://livedocs.adobe.com/flash/9.0/Act ... oader.html
Code:
//on timeline in flash movie
import fl.containers.UILoader;
import fl.controls.Label;
import fl.controls.ProgressBar;
import fl.controls.ProgressBarMode;
var picLoader:UILoader = new UILoader();
picLoader.scaleContent = true;
addChild(picLoader);
picLoader.x = 25;
picLoader.y = 25;
picLoader.width = 190;
picLoader.height = 230;
picLoader.source = "mypicture.jpg";
picLoader.addEventListener(Event.PROGRESS, picProgressHandler);
picLoader.addEventListener(Event.COMPLETE, picCompleteHandler);
function picCompleteHandler(event:Event) {
trace("Number of bytes loaded: " + picLoader.bytesLoaded);
}
function picProgressHandler(event:ProgressEvent):void {
var myLabel:Label = new Label();
myLabel.autoSize = TextFieldAutoSize.LEFT;
myLabel.text = "";
myLabel.move(10, 10);
addChild(myLabel);
var myProgressBar:ProgressBar = new ProgressBar();
myProgressBar.mode = ProgressBarMode.MANUAL;
myProgressBar.move(10, 30);
addChild(myProgressBar);
var uiLdr:UILoader = event.currentTarget as UILoader;
var kbLoaded:String = Number(uiLdr.bytesLoaded / 1024).toFixed(1);
var kbTotal:String = Number(uiLdr.bytesTotal / 1024).toFixed(1);
myLabel.text = kbLoaded + " of " + kbTotal + " KB" + " (" + Math.round(uiLdr.percentLoaded) + "%)";
myProgressBar.setProgress(event.bytesLoaded, event.bytesTotal);
}
[CS3] ContentLoaderInfo.addEventListener(Event.INIT Problem
Hi,
I hope someone can help me or give me some suggestions because i have been trying to get a good solution to this for a while now and i have had no luck.
What happens in my code is
1) I load an object on my stage (a server icon and a switch)
2) I then run some code to connect these two together
The problem
When i load the server and the switch
I think my code trys to connect them before the objects are loaded
as in the below code.
Is this true that code continues to execute while the loader loads the object.
I have ran some trace commands and from what i see this is true.
Is their away to stop code execution when the loader starts to load an object and then continue code execution after.
I would be some happy if someone could give me some info on this..thanks
Code:
var request:URLRequest = new URLRequest('port.swf');
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onPortComplete);
loader.name = port_name;
loader.load(request);
MyClass.addEventListener(onChange.Change,func); Event, Is It Possible? How?
Hi there,
I'm writing my own Dropdown class that extends a MovieClip. Now i need to get id of selected item everytime the selected item is changed. For that, the best idea i could think of is to add addEventListener to my class, so it would know when data is changed inside the class.
Could anyone advice me where to dig? I've been searching for Custom Events, but i can't get idea of how it works.
All the best and thanks in advance!
AddEventListener(Event.COMPLETE, OnLoaded) Function Problem
hi, everyone, i am new and i need help
i hope my problem is not one everyone knows and talks about, but i couldn't really find an answear to it via google, and am a little bit desperate to find a solution..
problem is: the
addEventListener(Event.COMPLETE, onLoaded) does not finish what it should do before i call the
addEventListener(Event.ENTER_FRAME, loop) function, or so it seems..
WHY!?!?
i do not really understand why this is happening, maybe someone can explain to me where my thinking is wrong..
the error msg is:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
that shouldn't be possible tho, since i initialize the concerning variable (sc:Soundchannel) beforehand..
code:
ActionScript Code:
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.net.URLLoader;
import flash.net.URLRequest;
public class testprojekt extends Sprite
{
public var loader:URLLoader = new URLLoader();
public var sound: Sound = new Sound();
public var sc:SoundChannel = null;
public var xml:XML;
public var il: XMLList = new XMLList();
public var soundIndex:Number = 0;
public var soundEndIndex:Number;
public var speed:Number = 100;
public var chordList:XMLList;
public var testString:String;
public function testprojekt()
{
loader.load(new URLRequest("sound.xml"));
loader.addEventListener(Event.COMPLETE, onLoaded);
// chordList from SoundInput class
var sInput: SoundInput = new SoundInput("soundFile_test.xml");
chordList = sInput.getSoundInput();
addEventListener(Event.ENTER_FRAME, loop);
}
public function onLoaded(e:Event):void
{
// xml loaded
xml = new XML(loader.data);
il = xml.tracks.sound;
soundEndIndex = il.name.length();
// start first sound
sound = new Sound(new URLRequest("sounds/" + il.name[soundIndex]) );
sc = sound.play();
}
public function loop(e:Event):void
{
//trace("here is the error and i do not know why");
if (sc.position >= speed)
{
sc.stop();
setSound();
}
}
public function setSound():void
{
soundIndex++;
if (soundIndex < soundEndIndex)
{
trace(soundIndex);
sound = new Sound(new URLRequest("sounds/" + il.name[soundIndex]) );
trace(il.name[soundIndex]);
sc = sound.play();
}
else
{
removeEventListener(Event.ENTER_FRAME, loop);
}
}
}
}
thx for anyone reading this through
Return A Obj From A Class, After A URLLoader.addEventListener(Event.COMPLETE,onJSON);
Hey all,
coment below
ActionScript Code:
loadJSON.init("data.json");//run from Doc Class
function parentTrace(decoded)
{
trace(decoded);
}
loadJSON.as
ActionScript Code:
package
{
import com.adobe.serialization.json.*;
import flash.display.MovieClip;
import flash.events.*;
import flash.display.*;
import flash.net.URLRequest;
import flash.net.URLLoader;
public class loadJSON extends MovieClip
{
public static function init(jsonFile):void
{
var loader:URLLoader=new URLLoader;
loader.addEventListener(Event.COMPLETE,onJSON);
loader.load(new URLRequest(jsonFile));
}
public static function onJSON(e:Event):void
{
var jsonData:String=e.currentTarget.data;
jsonData=jsonData.replace(/
/g,"");
var decoded:Object=JSON.decode(jsonData);
stage.parentTrace(decoded); // this does not work
//i just want decoded to be push back to where the class was called after the file load.
}
}
}
Variable.addEventListener OR DynamicVariable.addEventListener
This is my first post on these forums though I've appreciated tons and tons of help from others that have posted their questions (and answers). I'm trying to dynamically create a menu based on the number of entries in an xml file. I need to create a button for each entry which then triggers a function through an eventListener. So I need to either dynamically name my movieClips I'm creating (for my buttons) OR find a way to take "tempName = mc.name" and then use that in tempName.addEventListener.
The relavent code is below! Thanks for the help!
Code:
function drawImage(i) {
for (var item:int = 0; item < i; item++) {
objectType = myXML.slide[item].objectType;
if (objectType == "image") {
dataPath = myXML.slide[item].src;
var mc:MovieClip = new MovieClip();
imageMaster.addChild(mc);
mc.graphics.beginFill(0x00000);
mc.graphics.drawRect(wide*100 - 100, high*50, 40, 40);
mc.graphics.endFill();
mc.name = "mc"+item;
mc.addEventListener(MouseEvent.MOUSE_UP,function(evt:MouseEvent){switchSlide(dataPath)});
}
}
}
The code does create all the buttons but when I click on any of the buttons the action performed is the action intended for the last button.
Thanks again!
ENTER_FRAME Handler
i got a btn_mc on stage, 10 frames length, the width shape tweens from 1 -> 50
this is my actionscript :
ActionScript Code:
btn_mc.buttonMode = true;
btn_mc.addEventListener(MouseEvent.ROLL_OVER, btn_rollOver);
function btn_rollOver(event:MouseEvent):void
{
event.currentTarget.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
function btn_rollOut(event:MouseEvent):void
{
event.currentTarget.removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
event.currentTarget.addEventListener(Event.ENTER_FRAME, exitFrameHandler);
}
function enterFrameHandler(event:Event):void
{
event.currentTarget.nextFrame();
event.currentTarget.addEventListener(MouseEvent.ROLL_OUT, btn_rollOut);
}
function exitFrameHandler(event:Event):void
{
btn_mc.prevFrame();
if (event.currentTarget.currentFrame == 1)
{
event.currentTarget.removeEventListener(Event.ENTER_FRAME, exitFrameHandler);
}
}
nextFrame() and prevFrame() seem to work allright, but you can manage to pause the prevFrame() function if you rollOver it again quickly.
so from what i can tell what is happening :
btn_mc gets a ROLL_OVER event, if ROLL_OVER event occurs, btn_mc enterFrameHandler starts running, and keeps playing nextFrame(). Also an ROLL_OUT event is added at this time. So when we ROLL_OUT, exitFrameHandler starts prevFrame() until the currentFrame of the btn_mc == 1, it then removes the exitFrameHandler.
what happens now is that when your ROLL_OVER, ROLL_OUT and immediatly ROLL_OVER again, the nextFrame() should be running again, but this doesnt happen, it seems enterFrameHandler is not being started, prevFrame() pauses on a certain frame, even though it is listening...
anyone care to see what the potential problem is ?
Kind regards,
Juan
Why Can't I Use ENTER_FRAME In A Timer?
Here's a piece my code:
ActionScript Code:
var imageTimer:Timer = new Timer(4000,1);
imageTimer.addEventListener(TimerEvent.TIMER, switchImage);
function switchImage(Event:TimerEvent):void
{
images[i].addEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
basically, I have a bunch of MC's in an array, and when the timer goes off, it will start the animation to switch images using an EnterFrame event. Yet, when I test the movie, I get this error, pointing at the EventListener in my switchImage function....
1119: Access of possibly undefined property ENTER_FRAME through a reference with static type flash.events:TimerEvent.
What's wrong? Why can't I add an EnterFrame listener when a timer goes off??
Terminate ENTER_FRAME ?
Greetings,
I can't seem to get this to work:
stage.addEventListener(Event.ENTER_FRAME,startUp);
function startUp() {
rowsReq();
columnsReq();
matchDef();
_itemPosition();
if (stopEnterFunc == 1)
{
stage.removeEventListener(Event.ENTER_FRAME);
for (var i=1; i < 17; i++)
{
this['dry' + i]=this["_item" + i + "_drag"].y;
}
for (var j=1; j < 17; j++)
{
this['drx' + j]=this["_item" + j + "_drag"].x;
}
for (var k=1; k < 16; k++)
{
this['_item' + k + "_drag"]._txt.htmlText=dWords[k];
}
}
}
In AS2 this was easier, or so it seems. Just used:
delete this.onEnterFrame;
Any help will be greatly appreciated!
ENTER_FRAME Undefined?
This is the code of a little program I'm working on. It's pretty simple, but when I try to test it the following error occurs: "1119: Access of possibly undefined property ENTER_FRAME through a reference with static type flash.events:MouseEvent." Which is a little strange, considering that I have used almost the same syntax in some other cases and there wasn't any problem. Any help would be appreciated.
ActionScript Code:
import flash.display.Graphics;
import flash.display.MovieClip;
import flash.events.Event;
var Vx:Number = 0;
var Vy:Number = 0;
var a:Number = 0.98;
var h:Number = 0;
var X:Number = 0;
var Y:Number = 0;
var ball:MovieClip = new MovieClip();
ball.x=ball.y=0;
this.addChild(ball);
var mc:MovieClip = new MovieClip();
mc.x=mc.y=0;
this.addChild(mc);
button_submit.addEventListener(MouseEvent.CLICK, EventReceiver);
function EventReceiver(Event:MouseEvent):void{
Vx = v_ns.value;
h = h_ns.value;
X = 0;
Y = 400 - h;
mc.graphics.clear();
mc.graphics.moveTo(0, 387-h);
mc.graphics.lineStyle(1, 0x000000);
mc.graphics.beginFill(0x000000);
mc.graphics.lineTo(40, 387-h);
mc.graphics.lineTo(40, 417-h);
mc.graphics.lineTo(0, 417-h);
mc.graphics.lineTo(0, 387-h);
mc.graphics.endFill();
addEventListener(Event.ENTER_FRAME, startAnimation);
}
function startAnimation(e:Event):void{
if(Y<400){
X += Vx;
Vy += a;
Y += Vy;
ball.graphics.clear();
ball.graphics.beginFill(0x000000);
ball.graphics.drawCircle(X,Y,13);
ball.graphics.endFill();
}
else {removeEventListener(Event.ENTER_FRAME, startAnimation);};
}
Problem With ENTER_FRAME Help Please
Just started migrating and am having problems with the enter frame event.Did a simple rotating star animation with the following code
import flash.events.*;
function rte(event:MouseEvent) {
function rotate(event:Event) {
m_mc.rotation+=40;
}
m_mc.addEventListener(Event.ENTER_FRAME,rotate);
}
b_mc.addEventListener(MouseEvent.CLICK,rte);
When I press the button (b_mc) more than once the star starts rotating faster every time.What is going on?Doesn't happen in AS 2.0
ENTER_FRAME Issue
Hi guys, I'm really quite new to actionscript let alone AS3, hopefully you can help me out with an issue I'm having.
I have a movieclip with instance name "Title" within my main timeline. I want to jump to a frame within "Title" labelled "Appear" whenever the playhead reaches a certain frame on the main timeline.
In AS2 I would have gone with onEnterFrame, but I'm not sure what to do with AS3. Here's what I've attempted, but it doesn't seem to work:
Code:
addEventListener(Event.ENTER_FRAME,myFunction);
function myFunction(event:Event) {
trace("MovieClip(root).Title.gotoAndPlay(Appear)");
}
removeEventListener(Event.ENTER_FRAME,myFunction);
Any help you could give would be great.
Thanks!
Better Than ENTER_FRAME For This Project?
I'm not a developer and over the course of the past year during which I've learned a lot of AS3, I have probably not come close to applying what would be considered "best practices." I have lots of code that could probably be dramatically changed to improve performance.
Here's a bit of my code that I'd like advice about. Is there a different technique I can use to do the following, that's more streamlined?
masterCounter is variable that's iterated every tenth of a second on the root timeline. The following code is in a movie clip that's been added to the stage:
PHP Code:
addEventListener(Event.ENTER_FRAME, s003Listener);function s003Listener(event:Event):void { if (!event.target.parent.masterIsPlaying) { pauseAudio(); } if (event.target.parent.masterIsPlaying) { resumeAudio(); } if (event.target.parent.masterCounter == 1) { startAudioBkgd(); } if (event.target.parent.masterCounter == 10) { startAudio01(); } if (event.target.parent.masterCounter == 50) { Tweener.addTween(s003Presented, {alpha:1, time:fade}); } if (event.target.parent.masterCounter == 62) { playWhoosh(); } if (event.target.parent.masterCounter == 65) { s003Presented.gotoAndPlay(2); } if (event.target.parent.masterCounter == 95) { Tweener.addTween(s003Presented, {alpha:0, time:fade}); Tweener.addTween(s003title, {alpha:0, time:fade}); }// ...etc. Imagine there are a hundred of these if statements...
Don't flame me for being a Flash Butcher!
Thanks for any help!
ENTER_FRAME Listeners..
so in an attempt to leave no stone unturned, I need to understand why things happen, when applying an ENTER_FRAME listener, does the code excecute as long as your on the frame, kinda like a loop but with no statement to stop it? for example I have the following code:
var contRotate:Number = 1;
stage.addEventListener(Event.ENTER_FRAME, spinWheel)
function spinWheel(e:Event) {
var bigWheelRotate:TequilaTween = new TequilaTween(bigWheel, {x:90});
bigWheelRotate.start();
bigWheel.x = contRotate + 1;
trace("wheel spinning");
}
the string"wheel spinning" keeps tracing, however,bigWheel doesnt rotate, so do ENTER_FRAMES excecute once, or as long as your on the frame?
Particals + ENTER_FRAME
Hi everyone.
I looked through the posts and don't think this has been covered yet.
I'm creating a smoke trail effect that moves from the left of the screen to the right using particles.
In order to know where to go, and to create a random effect each particle has its own ENTER_FRAME, and they are being created one-per-frame until they are removed at the other end. (this is all done in an external file).
By the time they begin being removed there are hundreds and the app slows down. My guess is that this is due to hundreds of ENTER_FRAMES running simultaneously.
I was wondering if there is any way to use a central ENTER_FRAME in the main file that simply 'fires' a function in all of the existing particles (to make them listen for a command rather than having separate ENTER_FRAME). This would reduce system load and keep individual movement.
Thanks in advance!
James
Conquering ENTER_FRAME :)
touching is a Boolean which is declared as false;
it becomes true in here:
PHP Code:
mc.addEventListener(MouseEvent.MOUSE_OVER, onRollOver); function onRollOver(e:MouseEvent):void { touching = true;}
and then false again in here:
PHP Code:
mc.addEventListener(MouseEvent.MOUSE_OUT, onRollOut); function onRollOut(e:MouseEvent):void { touching = false;}
first of all, i wanted to say it like this:
PHP Code:
if (touching == true) {addEventListener(Event.ENTER_FRAME, scrollMouse);function scrollMouse(e:Event):void { TweenLite.to(container, 1, {x:((stage.stageWidth - container.width)/stage.stageWidth * mouseX)}); }}if (touching == false) {removeEventListener(Event.ENTER_FRAME, scrollMouse);}
But it doesnt work, the listener is never added, dont understand why...
it WORKS like this:
PHP Code:
addEventListener(Event.ENTER_FRAME, scrollMouse);function scrollMouse(e:Event):void {if (touching == true) { TweenLite.to(container, 1, {x:((stage.stageWidth - container.width)/stage.stageWidth * mouseX)}); }}if (touching == false) {}
But it defeats a purpose of adding/removing event listener when not necessary, especially ENTER_FRAME.
how can i make this work so that i add that listener only when i want and remove it accordingly?
i dont want to have ENTER_FRAME on my neck all the time...
Slow Down ENTER_FRAME
I'm new to the whole Flash game, and I'm trying to slow down the ENTER_FRAME event... Now, I got it working but I was wondering if it's the best way?
Actionscript Code:
var scrollSpeed = 5;var scrollSpeedInc = 0;
myBtn.addEventListener(MouseEvent.ROLL_OVER, function(e:MouseEvent):void { myBtn.addEventListener(Event.ENTER_FRAME, startScroll);});myBtn.addEventListener(MouseEvent.ROLL_OUT, function(e:MouseEvent):void { myBtn.removeEventListener(Event.ENTER_FRAME, startScroll);}
function startScroll(e:Event):void { if (scrollSpeedInc < scrollSpeed) { scrollSpeedInc++; } else { // Scroll something. scrollSpeedInc = 0; }}
ENTER_FRAME Lags In CS4?
Hi all,
Apologies if this topic has already been posted but has anyone noticed a performance lag when using ENTER_FRAME in CS4? I had a very basic space invaders game created in Flash CS3 and it ran fine. When I took it into CS4 it was significantly slower. I stripped out everything but a few of the lines to change an Y property and it's still very slow, even with a frame rate of 60FPS. I've played around with the frame rate without success. Here's a snippet of the code...
stage.addEventListener(Event.ENTER_FRAME, loop);
function loop(myevent:Event) {
s1_mc.y+=2;
s2_mc.y+=2;
s3_mc.y+=2;
s4_mc.y+=2;
}
To me, these movie clips should move down the Stage quite fast at 60FPS but they actually drop quite slowly. It grinds even more when I throw in some hitTests. I don't have any other ENTER_FRAMEs going so I'm a little puzzled by this. I've also tested on Mac and PC with the same issue on both platforms.
Any feedback on this would be appreciated.
Gerald
GotoAndStop(); Not Running Along With ENTER_FRAME?
heya, theres probably a simple fix for this, but i dont get it.
the code is a mess and I guarantee some nooby items there, but it should all work, basically my button will do all its told in the function it runs, EXCEPT the jump to the next stage frame label? I think this is something to do with the enter_frame's i have going? any ideas?
Code:
select1.addEventListener(MouseEvent.CLICK , nStage2);
stage.addEventListener(Event.ENTER_FRAME , movement2);
stage.addEventListener(Event.ENTER_FRAME , movementb2);
function movementb2(event:Event):void
{
panpoint.distance = 115 - panpoint.mouseX
}
function movement2(event:Event):void
{
if (cityL1.x > 575) {
cityL1.x = 575;
} else if (cityL1.x <310) {
cityL1.x = 310;
}
if (cityL2.x > 575) {
cityL2.x = 575;
} else if (cityL2.x <310) {
cityL2.x = 310;
}
if (cityL3.x > 875) {
cityL3.x = 875;
} else if (cityL3.x <510) {
cityL3.x = 510;
}
var mod2a = cityL1.scaleX/105;
cityL1.x+=(panpoint.distance/10)*mod2a;
var mod2b = cityL2.scaleX/85;
cityL2.x+=(panpoint.distance/10)*mod2b;
var mod2c = cityL3.scaleX/65;
cityL3.x+=(panpoint.distance/5)*mod2c;
}
function nStage2(event:MouseEvent):void
{
stage.removeEventListener(Event.ENTER_FRAME , movement2);
stage.removeEventListener(Event.ENTER_FRAME , movementb2);
cityL1.mouseEnabled = false;
cityL2.mouseEnabled = false;
cityL3.mouseEnabled = false;
panpoint.mouseEnabled = false;
gotoAndStop("stage2");
trace ("clicked");
}
stop();
ENTER_FRAME Is Not On Line With Framerate?
i've got a problem, but dont know the cause.
i've got a class spaceship that has an object that handles his movement. this kinematic object updates the spaceShip's coordinates in a set interval.
then in the spaceship in an onEnterframe function everytime the spaceship exits the screen, it's coordinates are restored to the screen's boundaries. so that it does not exit.
but the problem is, that the space ship jumps in and out of the screen, because the kinematics object is taking care of its speed(pushing him out) and the spaceship object is trying to remain in the screen.
but i thought that the EnterFrame object is just before every frame update. so that would mean that everytime the screen is updated, the space ship is reset to the stage's boundaries, right?
this is the boundary checker:
PHP Code:
private function checkBoundaries():void { if (x > stage.width) { x = stage.width; } else if (x < 0) { x = 0; } if (y > stage.height) { y = stage.height; } else if (y < 0) { y = 0; } }
and:
PHP Code:
addEventListener(Event.ENTER_FRAME, checkBoundaries);
how come this doesn't work?
i can also just say:
PHP Code:
kine.myTimer.addEventListener(TimerEvent.TIMER, checkBoundaries);
but i just dont understand why this glitch is occurring
Is Tweenlite Faster Than ENTER_FRAME ?
I am trying to make a simple accordeon menu, but when I fix one problem, I find another one. This time, it seems that the tweens ars quicker than my ENTER_FRAME....
here is the code of my Main class Document (Main.as):
Code:
package {
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
public class Main extends Sprite {
private var _butArray:Array = new Array("but0", "but1", "but2");
private var _actualOverBut:Number;
public function Main()
{
for (var i:int = 0; i < _butArray.length; i++)
{
this[_butArray[i]].addEventListener(MouseEvent.ROLL_OVER, rollOver);
this[_butArray[i]].addEventListener(MouseEvent.ROLL_OUT, rollOut);
}
this.addEventListener(Event.ENTER_FRAME, replaceButtons);
}
private function rollOver(pEvt:MouseEvent):void
{
_actualOverBut = Number(pEvt.target.name.charAt(pEvt.target.name.length - 1));
pEvt.target.rollOverState(pEvt);
}
private function rollOut(pEvt:MouseEvent):void
{
pEvt.target.rollOutState(pEvt);
}
private function replaceButtons(pEvt:Event)
{
for (var i:int = 0; i < _butArray.length; i++)
{
if (_actualOverBut < i)
{
if (i != 0)
{
this[_butArray[i]].x = this[_butArray[i - 1]].x + this[_butArray[i - 1]].width + 1;
}
} else if (_actualOverBut > i)
{
if (i != _butArray.length - 1)
{
this[_butArray[i]].x = this[_butArray[i + 1]].x - this[_butArray[i]].width - 1;
}
}
}
}
}
}
and this is my Button class :
Code:
package {
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.MouseEvent;
import gs.TweenLite;
public class Button extends Sprite {
private var tDuration:Number;
private var originalX:Number;
private var originalY:Number;
private var targetX:Number;
private var targetY:Number;
private var originalWidth:Number;
private var originalHeight:Number;
private var targetWidth:Number;
private var targetHeight:Number;
public function Button()
{
originalWidth = this.width;
originalHeight = this.height;
targetWidth = originalWidth * 2;
targetHeight = originalHeight * 2;
originalX = this.x;
originalY = this.y;
targetX = originalX - ((targetWidth - originalWidth) / 2);
targetY = originalY;
tDuration = .3;
}
public function rollOverState(pEvt:MouseEvent):void
{
TweenLite.to(pEvt.target, tDuration, { x:targetX, y:targetY, width:targetWidth, height:targetHeight } );
}
public function rollOutState(pEvt:MouseEvent):void
{
TweenLite.to(pEvt.target, tDuration, { x:originalX, y:originalY, width:originalWidth, height:originalHeight } );
}
}
}
What I would to have as a result is the the buttons around the one that is rolled over keeps the 1 pixel bettwen each other....
Sorry, I can't upload my .FLA, but I can send by email if anyone interresting
Thank you
Problem With Reversing ENTER_FRAME
I'm posting my code:
Code:
iButton1.addEventListener(MouseEvent.ROLL_OVER, splitBox);
iButton1.addEventListener(MouseEvent.ROLL_OUT, closeBox);
function splitBox(evt:MouseEvent) {
iButton1.addEventListener(Event.ENTER_FRAME, slide);
}
function closeBox(evt:MouseEvent) {
iButton1.addEventListener(Event.ENTER_FRAME, back);
}
function slide(evt:Event):void {
Flap1_mc.rotation = -10;
Flap2_mc.rotation = 10;
Flap1_mc.x -= 5;
Flap2_mc.x += 5;
Flap1_mc.alpha = .7;
Flap2_mc.alpha = .7;
}
function back(evt:Event):void {
Flap1_mc.rotation = 0;
Flap2_mc.rotation = 0;
Flap1_mc.x = 265;
Flap2_mc.x = 281;
Flap1_mc.alpha = 1;
Flap2_mc.alpha = 1;
}
When I roll over my invisible button (iButton1), my movie clips Flap1_mc and Flap2_mc separate from each other side by side along the x-axis until I roll out.
My questions are:
1. How to reverse it. When I roll out, they go back to their original positions using enter frame so they don't just suddenly appear in their original position but move into original position along the x-axis. What am I missing?
2. I am unable to continue the function of splitting the movie clips when I roll out then roll over. When I roll over again, they don't continue splitting. Is my code in proper order?
Noob ENTER_FRAME Question
Hi, I've just started learning AS3 so I bought the book "Learning ActionScript 3.0". I copies one of the examples exactly as it was written in the book, yet I got the error: "1046: Type was not found or was not a compile-time constant: Event."
Here's the code (it tells me the error is on the line that says
"public function onLoop(evt:Event):void":
package
{
import flash.display.MovieClip;
import flash.display.Graphics;
import flash.display.Event;
public class Box extends MovieClip
{
public var color:uint = 0x000099;
public function Box()
{
//draw a shape at runtime
this.graphics.lineStyle(1, 0x000000);
this.graphics.beginFill(color);
this.graphics.drawRect(0, 0, 100, 100);
this.graphics.endFill();
this.addEventListener(Event.ENTER_FRAME, onLoop, false, 0, true);
}
public function onLoop(evt:Event):void //Error line
{
this.x += 5;
}
}
}
Makes no sense to me why it refuses to work.
ENTER_FRAME Return Values
I'm trying to return a value from a function but I keep getting this error: "Incorrect Number of Arguments. Expected 1." I think there should be a pretty easy solution to this one but I just don't know what it's asking for here. I assumed it wanted the name of the variable I was trying to return but that wasn't right. Here's the code. Also, is it possible to return more than one value from a single function?
Thanks,
Joe
Attach Code
function getGreenInfo(event:Event):Number {
var greenNumber:Number;
greenNumber = greenBar.currentFrame;
return greenNumber;
}
stage.addEventListener(Event.ENTER_FRAME, getGreenInfo);
trace(getGreenInfo());
Stopping ENTER_FRAME Motion
I have series of buttons that when clicked rotate a triangle object and begin to pulse. My problem is that I am having problems coming up with a way to stop the pulsing motion when another button is clicked. Currently when clicked the object does rotate and does pulse. When the next button is clicked it too rotates and pulses only the pulsing seems to multiply in pulsing speed. How can I resolve this problem.
Thanks.
Code attached
Attach Code
import fl.transitions.TweenEvent;
import fl.motion.easing.*
import fl.transitions.Tween;
import fl.transitions.easing.*;
import flash.events.Event;
var myXML:XML = new XML();
var musicXML:XML = new XML();
var xmlLoader:URLLoader = new URLLoader();
var easing:Number = 0.2;
var channel:String = new String();
var thisButton:String = new String();
var thisImage:String = new String();
var imageLoader:Loader = new Loader();
var current=Number;
var dropShadow:DropShadowFilter = new DropShadowFilter();
dropShadow.distance =5;
dropShadow.blurX=0;
dropShadow.blurY=75;
dropShadow.alpha=.6
dropShadow.angle=90;
dropShadow.color=0x03B5F7;
var angle:Number = 100;
var centerScale:Number =1;
var range:Number = .5;
var speed:Number = .5;
var xmotion:Number = 3;
var angle2:Number = 0;
var centerScale2:Number =0;
var range2:Number = 0;
var speed2:Number = 0;
var xmotion2:Number = 0;
xmlLoader.addEventListener(Event.COMPLETE, handleComplete);
xmlLoader.load(new URLRequest("radioText.xml"));
var top:header = new header();
top.x=0;
top.y=0;
addChild(top);
var bottom: lower = new lower();
bottom.x=0;
bottom.y=350;
addChild(bottom);
//////////////////////////////////////////////////////////
var genre:genreText = new genreText();
genre.x=420;
genre.y=75;
channel1(genre);
addChild(genre);
var genre2:genreText = new genreText();
genre2.x=420;
genre2.y=95;
channel2(genre2);
addChild(genre2);
var genre3:genreText = new genreText();
genre3.x=420;
genre3.y=115;
channel3(genre3);
addChild(genre3);
var genre4:genreText = new genreText();
genre4.x=420;
genre4.y=135;
channel4(genre4);
addChild(genre4);
var genre5:genreText = new genreText();
genre5.x=420;
genre5.y=155;
channel5(genre5);
addChild(genre5);
var genre6:genreText = new genreText();
genre6.x=420;
genre6.y=175;
channel6(genre6);
addChild(genre6);
var genre7:genreText = new genreText();
genre7.x=420;
genre7.y=195;
channel7(genre7);
addChild(genre7);
function loadImage(thisImage:String):void {
imageLoader.load(new URLRequest(thisImage));
imageLoader.x=15;
imageLoader.y=75;
addChild(imageLoader);
trace(thisImage);
}
function handleComplete(event:Event):void {
//Load in XML
myXML = new XML(event.target.data);
//ignore spaces
myXML.ignoreWhitespace;
trace("loaded");
top.filters = [dropShadow];
//Set the text boxes to proper data
genre.displayGenre_txt.text =myXML.theWham.musicType;
genre2.displayGenre_txt.text =myXML.justSpurs.musicType;
genre3.displayGenre_txt.text =myXML.discoFever.musicType;
genre4.displayGenre_txt.text =myXML.doggFather.musicType;
genre5.displayGenre_txt.text =myXML.topHits.musicType;
genre6.displayGenre_txt.text =myXML.punkNation.musicType;
genre7.displayGenre_txt.text =myXML.alternativeFuel.musicType;
thisImage =myXML.theWham.image;
loadImage(thisImage);
}
/*function active(): void {
if (current == 1){
pulse(genre);
stopPulse(genre2);
stopPulse(genre3);
stopPulse(genre4);
stopPulse(genre5);
stopPulse(genre6);
stopPulse(genre7);
trace(current);
}else if(current == 2){
pulse(genre2);
stopPulse(genre);
stopPulse(genre3);
stopPulse(genre4);
stopPulse(genre5);
stopPulse(genre6);
stopPulse(genre7);
trace(current);
}else if(current == 3){
pulse(genre3);
stopPulse(genre2);
stopPulse(genre);
stopPulse(genre4);
stopPulse(genre5);
stopPulse(genre6);
stopPulse(genre7);
trace(current);
}else if(current == 4){
pulse(genre4);
stopPulse(genre2);
stopPulse(genre3);
stopPulse(genre);
stopPulse(genre5);
stopPulse(genre6);
stopPulse(genre7);
}
else if(current == 5){
pulse(genre5);
stopPulse(genre2);
stopPulse(genre3);
stopPulse(genre4);
stopPulse(genre);
stopPulse(genre6);
stopPulse(genre7);
}
else if(current == 6){
pulse(genre6);
stopPulse(genre2);
stopPulse(genre3);
stopPulse(genre4);
stopPulse(genre5);
stopPulse(genre);
stopPulse(genre7);
}
else if(current == 7){
pulse(genre7);
stopPulse(genre2);
stopPulse(genre3);
stopPulse(genre4);
stopPulse(genre5);
stopPulse(genre6);
stopPulse(genre);
}
}*/
function pulse(channel):void {
channel.addEventListener(Event.ENTER_FRAME, pulse);
function pulse(event:Event):void {
channel.triangle_mc.scaleX = channel.triangle_mc.scaleY = centerScale + Math.sin(angle)*range;
angle += speed;
channel.triangle_mc.x= + xmotion;
}
}
/*function stopPulse(channel):void {
channel.addEventListener(Event.ENTER_FRAME, pulse);
function pulse(event:Event):void {
channel.triangle_mc.scaleX = channel.triangle_mc.scaleY = centerScale2 + Math.sin(angle2)*range2;
angle2 += speed2;
channel.triangle_mc.x= + xmotion2;
}
}*/
function rotate(channel): void {
var triRotate:Tween = new Tween(channel.triangle_mc,"rotation", Strong.easeOut, 0, 180, 1, true);
}
function channel1(channel):void{
channel.addEventListener(MouseEvent.CLICK, c1);
function c1(event:MouseEvent):void{
thisImage =myXML.theWham.image;
loadImage(thisImage);
rotate(channel);
pulse(channel);
current = 1;
//active();
}
}
function channel2(channel):void{
channel.addEventListener(MouseEvent.CLICK, c2);
function c2(event:MouseEvent):void{
thisImage =myXML.justSpurs.image;
loadImage(thisImage);
rotate(channel);
pulse(channel);
current = 2;
//active();
}
}
function channel3(channel):void{
channel.addEventListener(MouseEvent.CLICK, c3);
function c3(event:MouseEvent):void{
thisImage =myXML.discoFever.image;
loadImage(thisImage);
rotate(channel);
pulse(channel);
current = 3;
//active();
}
}
function channel4(channel):void{
channel.addEventListener(MouseEvent.CLICK, c4);
function c4(event:MouseEvent):void{
thisImage =myXML.doggFather.image;
loadImage(thisImage);
rotate(channel);
//pulse(channel);
current = 4;
//active();
}
}
function channel5(channel):void{
channel.addEventListener(MouseEvent.CLICK, c5);
function c5(event:MouseEvent):void{
thisImage =myXML.topHits.image;
loadImage(thisImage);
rotate(channel);
pulse(channel);
current = 5;
//active();
}
}
function channel6(channel):void{
channel.addEventListener(MouseEvent.CLICK, c6);
function c6(event:MouseEvent):void{
thisImage =myXML.punkNation.image;
loadImage(thisImage);
rotate(channel);
pulse(channel);
current = 6;
//active();
}
}
function channel7(channel):void{
channel.addEventListener(MouseEvent.CLICK, c7);
function c7(event:MouseEvent):void{
thisImage =myXML.alternativeFuel.image;
loadImage(thisImage);
rotate(channel);
pulse(channel);
current = 7;
//active();
}
}
Stopping A ENTER_FRAME Function
How can I make a on ENTER_FRAME function from constantly running?
Here is what I have
Code:
addEventListener(Event.ENTER_FRAME, onEnterFrame);
private function onEnterFrame(event:Event):void
{
var speed:Number = 6;
var ysize:Number = Tall - this.height;
var xsize:Number = Wide - this.width;
this.height += ysize / speed;
this.width += xsize / speed;
if (Math.abs (ysize) < 0.3 && Math.abs (xsize) < 0.3) {
this.height = Math.abs (ysize);
this.width = Math.abs (xsize);
trace("done");
}
}
I know if I used the same thing in AS2 all I needed to do is delete this.onEnterFrame.
Are there pre-defined classes in AS3 that would do the same thing.
Fading A Movieclip Using ENTER_FRAME
Hi there,
I'm sure this is really obvious but I am trying to fade out a mc using ENTER_FRAME but not getting anywhere, here is the code I have so far:
Code:
teaPotMC.alpha = 0;
teaPotMC.addEventListener(Event.ENTER_FRAME, beginPour);
function beginPour(evt:Event):void {
if(teaPotMC.alpha > 100){
teaPotMC.alpha += 10;
} else {
teaPotMC.removeEventListener(Event.ENTER_FRAME, beginPour);
}
}
the trouble is that when i set a trace going it seems to be increasing the alpha, but the actual mc does not set itself to 0 it stays at 100%
What am i doing wrong?
Cheers,
Bob
ENTER_FRAME's 1 Parameter Limit
Maybe I'm looking at it the wrong way but I seem to quite often want to have more parameters than just a single function to respond to an event listener... I read this:
http://www.darronschall.com/weblog/archives/000191.cfm
but that seems like a super advanced non-newbie friendly hack for something that seems like it would often be needed.
Code:
var myRect = new(rectangle)
stage.addChild(myRect)
moveRect(myRect, 'down', 10)
/*Here I'd want to make an encapsulated function that, with these parameters at least, would move the rectangle downward 10 times AT THE SPEED OF THE FRAME RATE (1 pixel each time). But once you bring frame rate into the picture, you have to use an ENTER_FRAME listener which only accepts ONE event parameter thus screwing up the parameter structure of the function you're trying to build */
I was able to make a movieclip on the stage move around in the shape of a square, but it is a long way that probably needs encapsulation. If you try to encapsulate though you run into stupid single-parameter-only event problems:
Code:
var myRect = new(rectangle);
//udlr stands for up down left or right
var udlr = 'd';
var counter = 0;
stage.addChild(myRect);
stage.addEventListener(Event.ENTER_FRAME, moveRect);
function moveRect(e) {
if (udlr == 'd') {
myRect.y +=1;
if (counter>=10) {
udlr = 'r';
counter = 0
}
}
if (udlr == 'r') {
myRect.x +=1;
if (counter>=10) {
udlr = 'u';
counter = 0
}
}
if (udlr == 'u') {
myRect.y -=1;
if (counter>=10) {
udlr = 'l';
counter = 0
}
}
if (udlr == 'l') {
myRect.x -=1;
if (counter>=10) {
udlr = 'd';
counter = 0
}
}
counter++
}
Multiple ENTER_FRAME, EventListeners?
Is it possible to have more than one EventListener using ENTER_FRAME? I have one on a child of the main stage and then one on a child off of that child. It seems like the one in the second child has been all messed up ever since I added one on the first child. I have a feeling it's an easy fix. Just can't figure out what it is. Any tips would be great!
Good OO Practice: ENTER_FRAME
I'm now creating a cheesy and cliched game, and I want to know what are the best practices surrounding the ENTER_FRAME event and listener. Should each object onstage (character, enemy, projectile) listen for the ENTER_FRAME to move them, or should they have a public updateScreen() method that a central class calls each time ENTER_FRAME is triggered? Here's my code now:
Code:
public class Projectile extends Sprite {
public function Projectile(xVel:Number, yVel:Number):void {
trace("Made Projectile!");
addEventListener(Event.ADDED_TO_STAGE, launch, false, 0, true);
}
private function launch(evt:Event):void {
trace("Launched!");
removeEventListener(Event.ADDED_TO_STAGE, launch, false);
addEventListener(Event.ENTER_FRAME, updateScreen, false, 0, true);
}
public function updateScreen(evt:Event):void {
// Move object and update view
}
}
}
I just need to know how the professionals do it. Thanks.
One ENTER_FRAME Vs Multiple ENTER_FRAMES
Ok so I have a gallery that rotates anywhere from 15-30 images around. Originally I added an enter_frame to every image and performed the movement calculations in there. Now I just add one global enter_frame that loops through an array and moves all the images. Sometimes I notice stuttering. I was wondering if there is a more efficient way to do this. I was even thinking about adding another enter_frame, one that could move say the first 15 or so images, and then the other enter_frame would move the rest, that way one enter_frame wouldn't have to do all the heavy processing because the other would share the load, now that I think about, was it more efficient to have an enter_frame on every image, it was just a thought that went through my mind and I wanted to throw it out there, I'm curious to see what everyone will say.
AS3 And Tweener Enter_Frame Events
I am relatively new to working in AS3 and Tweener, and I am having trouble making onComplete and delay functions work within Tweener when calling them from an Enter_Frame event. Example
line_mc.addEventListener(Event.ENTER_FRAME, intro);
function intro(event:Event):void
{
Tweener.addTween(event.target, {alpha:1, time:.2, delay:2, transition:"easeOutQuad", onComplete:lineOut});
}
function lineOut():void
{
line_mc.alpha = 0;
}
Any help would be greatly appreciated
Thanks
|