Trajectory And Firing A Slingshot
Hi folks, I am almost at the quitting stage with my latest project, I am trying to build a game where you fire eggs from a catapault/slingshot type device and hits verious random targets. the effect I want to achieve can be seen at the following link: (just the catapault effect) http://www.viralmania.com/games/pepsi_bucket/host.asp So far I have come up with a kind of working version (see attached files) but the trajectory is all wrong as the egg always fires to high and there is no way to simple fire the egg low to the ground (again see the pepsi link above). I also need the bucket to rotate depending on the direction the catapault is dragged in (though I have a pretty good idea how to do this.) So can ANYONE please help me with a script thats is very very similiar to the way the catapault in the pepsi game works? Kind Regards Drakash
KirupaForum > Flash > ActionScript 1.0/2.0
Posted on: 03-17-2006, 12:59 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Slingshot Trajectory And All That Trig Stuff
Hi folks,
I am almost at the quitting stage with my latest project,
I am trying to build a game where you fire eggs from a catapault/slingshot type device and hits verious random targets.
the effect I want to achieve can be seen at the following link: (just the catapault effect)
http://www.viralmania.com/games/pepsi_bucket/host.asp
So far I have come up with a kind of working version (see attached files) but the trajectory is all wrong as the egg always fires to high and there is no way to simple fire the egg low to the ground (again see the pepsi link above).
I also need the bucket to rotate depending on the direction the catapault is dragged in (though I have a pretty good idea how to do this.)
So can ANYONE please help me with a script thats is very very similiar to the way the catapault in the pepsi game works?
Kind Regards
Drakash
Slingshot
I tried to make a first person slingshot object, but I only got a really poor demonstration.
Can you please help.
I'm a total actionscript newb so just try your best.
Trajectory Problem
I am working on a game where you got a cannon on the bottom of the screen that rotates to reflect your mouse position. I got all the rotation working properly, but I would like to add a line coming out that projects the trajectory.
Currently I have the line coming out of the cannon, my problem is getting it to reach the end of the stage and getting to to bounce back to the other side of the stage and repeating until the line will be off the screen. Seems my math mind is getting rusty in my old age.
Here is the code I have on the sample script I am trying to work this out on.
code:
onClipEvent (mouseMove) {
Radians = Math.atan2((_root._xmouse-this._root.arrow._x), (_root._ymouse-_root.arrow._y));
TempTube = Math.round(Radians*180/Math.PI);
if (TempTube>0 && TempTube<110) {
TempTube = 110;
}
if (TempTube<0 && TempTube>-110) {
TempTube = -110;
}
_root.arrow._rotation = 180-TempTube;
_root.targetline_mc.clear();
angle = (180-this._rotation)*Math.PI/180;
xcomponent = Math.sin(angle)*500;
ycomponent = Math.cos(angle)*500;
_root.targetline_mc.lineStyle(1, 0xff0000, 100);
_root.targetline_mc.moveTo(this._x, this._y);
_root.targetline_mc.lineTo(this._x+xcomponent, this._y+ycomponent);
updateAfterEvent();
}
Also I have attached a sample FLA of what I am working on. Basically the script is attached to a simple arrow I made parked in the bottom center of the screen. Targetline_mc is an empty movie clip created in Frame 1.
This has been driving me crazy, I know its got to be something simple I am just overlooking. Thanks in advance for any help you can give me on this problem!
Basketball Trajectory
Hi!
It's me again
I'm trying to do a basketball game using Flash MX.
Now, I'm trying to find some way to make the ball fly to the basket, from any point on the ground, and make it "credible".
I attach an image... I don't know if it will be helpful!
How do you think it's the easiest way to do that? trying to simulate the real fisics (forces.. gravity... ouch!)? There is any easier way?
thx in advance!
Trajectory Tutorials
Hi Guys
I am looking to make a simple mini game based on something like this iceslide game. http://www.miniclip.com/games/ice-slide/en/
I have been doing a lot of hunting on the web for tutorials or sample starter code to create such a game but cant seem to find any tutorials on trajectory based games. There seems to be plenty of these games around but no tutorials. If anyone knows of any good places to look that would be great.
Many thanks
Trevor
AS2 - The Pain - Trajectory.
I hate math.... a LOT. My basics are really shocking and I dont even know/remember what simple math like sin/soc/tan is/does let alone do what I need to.
I need help with a proper simple working example on how to make a cannonball launch from a cannon(side view). Ive tried looking around but dont understand the formula and no one gives working examples. I googled "trajectory actionscript" and came up with pages of examples of the formula and dead sample links.
I would research this but I think the fact that I have the attention span of a fish when reading and have VERY limited time to create this game I need help.
Movement On Curved Trajectory
Hey all,
I'm making a little side-scrolling truck racing game. I want to add bumps and valleys instead of just flat terrain. My only problem is, how do I get the truck to follow the curved line. Sure if I gave the users the ability to control the _y position of the truck then it would work, but then they could choose to fly off the map. I need a way that will enable them to drive UP a curved line as well as DOWN while only holding the right arrow key. Any ideas?
Thanks
Simple Trajectory Method
Hi guys.
I have a movieclip which i'd like to make travel along based on the coordinates of 2 other movieclips. Let's say the mc I'd like to make travel is called ball_mc.
Now: I 'd like the ball_mc to travel based on the x : y ratio of two other mcs. Pretty standard trig, I'd have thought (and almost likely in the Math class; I just don't know where to look).
The angle between those two mcs becomes the angle I'd like ball_mc to travel along. Also bare in mind that the ball would start at either of those mcs exact location
Basically I need to know the ratio of the 2 mc's x : y so that I can plot my ball's location every few steps - from the 1st mc, up to the 2nd, and beyond (infinity) on the same trajectory. I need to know that angle AND how to calculate the ball_mc's next x and y coordinates based on a step incrementation of my choice.
My maths skills are poor and I don't know how to do it!
I really appreciate any help.
Sean
I Am Not Able To Achieve The Curve Trajectory
I am not able to achieve the trajectory (from bottom right to left-middle of page in an arc).Also I am not able to get the timing right.Now the animation is happening randomly.But the timing will have to be like this:
Around 5 seconds after the ordinary homepage loads, the bubble will drift onto the screen into the depicted position; hover there for around 10 seconds; and then drift back off-screen.
Any bubble image will do.
Bubble trajectory:
http://www.geocities.com/new_rid123/...trajectory.gif
I am not able to write the code.
I have got something in the form of a js file(bubble.js)
http://www.geocities.com/new_rid123/bubble/bubble.js
http://www.geocities.com/new_rid123/bubble/example.html
but the trajectory is wrong there-it has to be like I have drawn in Bubble trajectory:
Please help me in coding the wiggle effect and the trajectory
Create Dynamic Trajectory
I have an animation with an airplane that flies on the stage from one end to the other. I have made a curve trajectory using motion tween, but I would like to create a random dynamic trajectory. Any idea how can i do that ? Is is possible to create dynamic motion tween ?
Ball Flight Trajectory
Hi all
I want to create a golf ball flight animation. I have all the datas and formulas I need but I'm struggling on how to animate it.
// Data of an 8 Iron shot
var startX:Number = 0;
var startY:Number = 300;
var maxHeightX:Number = 88;
var maxHeightY:Number = 26;
var landingX:Number = 143.02;
var landingY:Number = 300
var endX:Number = 145;
var endY:Number = 300;
var velocityX:Number = 17;
var velocityY:Number = -18;
var time:Number = 0;
var timeOfFlight:Number = 5.67; //in seconds
var gravity:Number = -9.8+velocityX^2;
//I would also like to add the drag effect (friction)
var friction:Number = 0.3;
//I also have some more datas that could be helpfull
var launchAngle:Number = 33
var horizontalLandingAngle:Number = -7;
var verticalLandingAngle:Number = 82;
// now here is the formula to calculate the actual x and y during the animation..
// the Z is the is the initial direction let put that value to 1 form now.
var theX:Number = velocity * cos(z) * time;
var theY:Number = velocity * sin(z) * time + (gravity/2) * t^2;
I didn't find any GOOD exemples of what I try to achieve so far.
I need help to make the transition beetween the ascending and descending part of the anim. I'm sure that, from here it sould be quite simple, but not for me
Thanks for your time
Simple Tutorial On Trajectory?
I am having trouble making a missle gradually fall down.
Can someone direct me to some simple tuts on that? Or at least tell me what I am looking for. I've found some on gravity, but they are usually about things fall straight down. I found some good things on decay, but nothing that really helped.
I want to shoot something from a cannon and have it eventually start to fall. The few I have found were unnecessarily too difficult.
Elliptical Trajectory / Motion In As 2.0?
Hey guys, first of all, sorry if this was asked before, i did use the search option first (glanced a bit) and didn't find something related quick so decided to ask:
Does anyone know the correct way for creating an elliptical motion in flash 8? I googled for ellipse equations and stumbled upon these:
http://en.wikipedia.org/wiki/Ellipse
Lower on the page there's also some code (javascript) which generates points that can then be connected to form an ellipse. tried to replicate that in flash, but haven't succeeded. Also, i was wondering if there was another way i could generate an ellipse, which looks more like this http://www.rsc.org/ej/JM/2000/b002092n/b002092n-f4.gif, in the sense that it's "tilted".
I am trying to replicate a sort of solar system, but with elliptical trajectories, and would have liked to have the sun in an upper corner and the planets rotating around it in a sort of "tilted" ellipse.
I also tried to modify the Circular Movement tut also http://www.kirupa.com/developer/mx/circular.htm.
Sorry if the question is dumb or already answered in a previous post. Thanks in advance!
Ball With Perspective And Trajectory
Hi All
I'm looking for some source or tips on how to make a super simple (ha ha) soccer penalty shoot out type game, where you setup a ball to fire along the Z axis into perspective but with some kinda controllable force and trajectory.
I've seen this before- just can't remember where. Any pointers much appreciated.
Cheers
Sally
Flight Trajectory - Eary Question
Hi,
How would you calculate a flight trajectory of an object, based on it's rotation.
For example, if _rotation == 0 then it should fly upwards y -= 1 ; x -= 0
if _rotation == -45 then it should fly y -= 1 ; x -= 1
if _rotation == 45 then it should fly y -= 1 ; x += 1
if _rotation == -90 then it should fly y -= 0 ; x -= 1
if _rotation == 90 then it should fly y -= 0 ; x += 1 and so on.
Thanx!
Trajectory In Tile-based Game
ei peeps!
currently making a tile-based game, with a 45 degree angle perspective. I have some enemy movieclips on the board and i want them to throw a granade at any target square on the grid. Of course, granades have to follow a trajectory from start to finish. I know that i can use Math.sin and Math.cos to calculate a path, but i'm stump in trying to figure out, how to calculate the trajectory so that it would hit a target square especially since i'm viewing the grid at an angle.
any help would be very mush appreciated.
Making Simple Parabola Trajectory
A very simple equation for a parabola could be
y = x^2
How come this works:
onClipEvent(enterFrame){
this._y= Math.pow(this._x,2)-5;
this._x ++;
trace ("Y: "+ this._y + " X:" + this._x);
}
But this doesn't work.....
onClipEvent(enterFrame){
this._y=(this._x)^2;
this._x ++;
trace ("Y: "+ this._y + " X:" + this._x);
}
Using the carrot squares something and ignores negative results?
Making A MovieClip Follow A Trajectory?
The title says exactly what my goal is...
My problem is in both determining the trajectory as well as making the MovieClip follow it.
According to my research (high school physics was a while ago) the following are the mathematical equations for trajectory...
x = velocity * time * cos(angle)
y = velocity * time * sin(angle) - 1/2(9.8 * (time * time))
First of all... if those arent correct please let me know...
Secondly.. how exactly can I translate this into ActionScript code? I know the following...
time = 2((0.0 - velocity) / 9.8) (again please correct errors)
and I know the starting co-ordinates of the MovieClip as well as the ending co-ordinates (the mouse's co-ordinates when clicked)
The questions that remain to me are:
(A) What will the velocity be in ActionScript terms? The movie's frame rate? Or the speed at which I set the MovieClip to move as pixels/frame? Or something else?
(B) What is time in an ActionScript sense?
(C) Where should the ActionScript reside in my movie in order to make the MovieClip follow the path? In an onEnterFrame() function?
(D) Is anyone out there experienced with this sort of problem and can they offer me any insight into solving it?
Cheers.
Launch Object With Realistic Trajectory
Hi. I want to create a side-scrolling game that essentially has something like a cannon that will launch balls across the screen, in an attempt to hit a target. The user needs to be able to customize the angle and power of the trajectory, and the balls need to fly through the air as though under the influence of gravity..
Anyone know where I should start?
Thanks.
Making A MovieClip Follow A Trajectory?
The title says exactly what my goal is...
My problem is in both determining the trajectory as well as making the MovieClip follow it.
According to my research (high school physics was a while ago) the following are the mathematical equations for trajectory...
x = velocity * time * cos(angle)
y = velocity * time * sin(angle) - 1/2(9.8 * (time * time))
First of all... if those arent correct please let me know...
Secondly.. how exactly can I translate this into ActionScript code? I know the following...
time = 2((0.0 - velocity) / 9.8) (again please correct errors)
and I know the starting co-ordinates of the MovieClip as well as the ending co-ordinates (the mouse's co-ordinates when clicked)
The questions that remain to me are:
(A) What will the velocity be in ActionScript terms? The movie's frame rate? Or the speed at which I set the MovieClip to move as pixels/frame? Or something else?
(B) What is time in an ActionScript sense?
(C) Where should the ActionScript reside in my movie in order to make the MovieClip follow the path? In an onEnterFrame() function?
(D) Is anyone out there experienced with this sort of problem and can they offer me any insight into solving it?
Cheers.
Firing Name
hi!
It s nice. Here i have firing name just go through it and give feed back. How is it ?
rajesh
Firing A Bullet
i have a crosshair target that i can move about my screen with the cursor keys.
What i want is for when i press the space bar i want a bullet movieClip, that is located at the bottom of the screen in the middle, to fired towards the target crosshair.
I cant quite figure how i am going to move the bullet's x and y cordinates so that it goes exactly towards the target when the space bar is pressed
so far i have
=======================================
if (Key.isDown(Key.SPACE)){
bulletTargetX = getProperty(_root.cross.target, _x);
bulletTargetY = getProperty(_root.cross.target, _y);
NowX=getProperty(_root.ship, _x);
Nowy=getProperty(_root.ship, _y);
=======================================
this sets the target x and y coordinates for my bullet. The bullet will be fired from variable positions NowX and NowY.
The above code is within an onClipEvent (enterFrame)
any suggestions
thanks in advance
gilesb
External Swf's Not Firing
I've got a movie that calls external swf's to be loaded. It works when I try it on my computer (in the Flash viewer) but when I upload to the server the external swf's aren't fired.
Everything is uploaded (all swf's are on the server in the root directory) and the buttons work (locally in the viewer anyway)
Any suggestions; this is killing me.
View my site
When you click on "About me" in the bottom right, it fires an external MC (about.swf) When you click on one of the buttons in about.swf it should fire another swf based on what button is pressed. I know it works because I can play it on my machine, but not on the server. Here's my code for the first button (information):
on (release) {
unloadMovie ("Aboutme.swf");
unloadMovie ("Skills.swf");
unloadMovie ("Education.swf");
unloadMovie ("History.swf");
unloadMovie ("inspirations.swf");
loadMovie ("information.swf",_root.holder);
}
//where holder is the empty movie clip I'm trying to load into
OnUnload Not Firing
I have some movie clips in a frame that use intervals to randomly update them selves. As intervals are a horrible pain in the neck if they try to run when the clip is no longer there these clips have an onUnload event that clears the intervals. This works fine when I simply navigate to another frame with gotoAndStop().
However when I log off I have to send a call to the backend and wait for a response. I then use gotoAndStop to go to the log in frame. When I do this the onunload events do not fire and the intervals fire and make the whole screen go white.
Why aren't these onUnload events firing? Can anyone help?
Thanks
Firing Spaceship Gun
Does anyone know how to make a spaceship fire when your press Space Bar? If anybody knows the actionscript for it and where you would put it, please tell me. Thanks!
Firing From A Tank?
I have been on and off using flash in the past few weeks and have mostly been following the great tutorials from this site. I have started a tank game ( you look from above and the tanks move in all directions). Up to now it has been more of a racing game but I really want to have those tanks shoot at each other in a 2 player game. The problem is as follows:
I have the tank as a MovieClip that can move but it is the rocket/missile that I can't make work. I have been looking round and the only tutorial is that of a unilateral movement with the missile moving along the y axis.
I wonder if the isn't a way for the missile ( hidden at start under the tank) that can take the tank's orientation and just move along that orientation ( or copy of it). I am too newbie like to know what all the actions are in Flash.
So any body have an idea, I'll keep on trying but may be stuck shortly.
THX, SebOr
Firing From A Tank?
I have been on and off using flash in the past few weeks and have mostly been following the great tutorials from this site. I have started a tank game ( you look from above and the tanks move in all directions). Up to now it has been more of a racing game but I really want to have those tanks shoot at each other in a 2 player game. The problem is as follows:
I have the tank as a MovieClip that can move but it is the rocket/missile that I can't make work. I have been looking round and the only tutorial is that of a unilateral movement with the missile moving along the y axis.
I wonder if the isn't a way for the missile ( hidden at start under the tank) that can take the tank's orientation and just move along that orientation ( or copy of it). I am too newbie like to know what all the actions are in Flash.
So any body have an idea, I'll keep on trying but may be stuck shortly.
THX, SebOr
Laser Firing Help
I am making a flash game, but I have a problem.
The controls are as follows:
Up Arrow: Rotate upwards
Down arrow: Rotate downwards
Right arrow: Accelerate
Left arrow: Decellerate
CTRL: Boost
Space: Fire
When my ship fires, I want it to fire out of the ship, not just move to the right of the screen.
Also, my boundries are not working correctly
The MCs are below:
Ship= XWinga
Boundries: land
Laser= laser
The instances are named the same as their MCs are named.
Code for the Xwing:
code: onClipEvent(load)
{
speed =0 ;
_root.laser._visible=false;
laserCounter=1;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.SPACE)) {
laserCounter++;
_root.laser.duplicateMovieClip( "laser"+laserCounter, laserCounter );
_root["laser"+laserCounter]._visible=true;
}
if (Key.isDown(Key.RIGHT)) {
speed += .3;
}
else if (Key.isDown(Key.LEFT)) {
speed -= .3;
}
// Wee!
if (Key.isDown(Key.UP)) {
_rotation -= 2;
}
if (Key.isDown(Key.DOWN)) {
_rotation += 2;
}
if (Key.isDown (Key.CONTROL)) {
speed += 1;
}
speed *= .99;
x = Math.sin(_rotation*(Math.PI/180))*speed;
y = Math.cos(_rotation*(Math.PI/180))*speed*-1;
if (!_root.top.hitTest(_x+x, _y+y, true)) {
_x += x;
_y += y;
} else {
speed *= -25;
}
}
Code for laser:
code: onClipEvent (load) {
laserMoveSpeed=20;
this._y=_root.XWinga._y;
this._x=_root.XWinga._x+80;
this._rotation=_root.XWinga._rotation;
}
onClipEvent (enterFrame) {
this._y=_root.XWinga._y;
this._rotation=_root.Xwinga._y;
this._x+=laserMoveSpeed;
if (this._x>600){
if (this._y>450) {
this.removeMovieClip();
}
}
}
Any help would be greatly appreceated.
*added AS tags for clarity:
http://www.flashkit.com/board/showth...hreadid=584396
gparis
[F8] Help Firing Bullets
Hey guys, I'm having some trouble getting my ship to fire its bullets in my game. I'm following a tutorial given to me by my tutor and I think I've followed it perfectly so I don't understand what's going on. The files are attached.
Can anyone help?
Thanks
Pete
Bullet Firing
bullet firing mechanisms problem
Ok, I am going to do a bit of a side project until my lazy friend gets over here to work on the starship game. So, it's a simple stick figure side scrolling game. You have a character on the left, you have smaller people coming from the right. You ned to shoot them in order to make them go away. Yet they shoot back at you. so here's my questions:
1. How to get the bullet to fire from your character's gun when you press a button? i tried the tutorial but it didn't work for MX.
2, to get the enemies to fire at random, how would I go abot this.
Thanks in advance!
Later,
FF
Function Firing On Its Own
First time using AS 3.0 and I'm running into a problem with something that seems extremely simple... I tried following an example of how to create a Play button and I inserted the following code into the first keyframe of my movie:
Code:
stop();
function startMovie(event:MouseEvent):void
{
this.play();
}
playButton.addEventListener(MouseEvent.CLICK, startMovie);
For some reason the startMovie function is firing on it's own even when the playButton isn't clicked.
If I remove the event listener the movie stops at the first frame and displays the playButton. When I put the event listener back, as soon as the movie starts it passes the first frame and continues to play the movie.
Anyone know what's wrong?
Thanks in advance,
Tommy
Mouse_out Not Firing
So i have a simple button implemented via an MC. I have event handlers registered for the MOUSE_OUT and MOUSE_OVER events such that a little animation plays when the mouse hovers over and when the mouse exits my button. My initial problem was that the MOUSE_OUT event would sometimes fail to fire, leaving the MC in the MOUSE_OVER state. I did some searching and found that you could look at the target.toString of the event, and if the current target isn't the MC then play the same frames from the MC as you would on MOUSE_OUT. This solved the MOUSE_OUT failed to fire problem, but caused a new one. Now my MOUSE_OVER animation doesn't play properly, it just skips to the last frame. It looks to me that my code to check for if the current target has changed is firing before my MOUSE_OVER animation has completed, causing it to skip to its end prematurely. Anyhow, here's my code so far:
addEventListener(MouseEvent.MOUSE_OUT, myMouseOut);
addEventListener(MouseEvent.MOUSE_OVER, myMouseOver);
function myMouseOver(event:MouseEvent):void {
gotoAndPlay(2);
if (event.target.toString() != "TABBUTTON_MC_1)"){
gotoAndPlay(21);
}
}
function myMouseOut(event:MouseEvent):void {
gotoAndPlay(21);
}
Firing A Projectile HELP
I have made a turret which rotates using the mouse as a targeting reticle. I'm having trouble with clicking the mouse and a projectile firing from the turret and stopping where the mouse was clicked. Any help welcome.
OnLoadComplete Not Firing...
Hi:
I´m trying to build a photo slide that "auto-advances" using an interval. So when I call the interval to show the next pic, I check if the next one is loaded.
When testing it locally, the onComplete (also tried onInit) work fine, but when testing on the server, the onLoadComplete doesn´t fire. I know the pic is loaded (I use web speed simulator and can see that the jpg is loaded), but the event doesn´t fire.
Any help would be greatly appreciated, I´m stuck.
Here´s part of the code.
Code:
var imgLoader = new MovieClipLoader();
var imgNum = 0;
// la defino ahora, porque al añadirle clips y fotos se jode el alto y no se centran
var master_alto=this._height
function loadImg(){
imgNum = my_secc.numfotos;
//trace(imgNum);
//Create the instance name for the movieclip to hold the image
imgMcName = "img" + imgCurLoad + "_mc";
if(imgCurLoad <= imgNum){
this.createEmptyMovieClip(imgMcName, this.getNextHighestDepth());
eval(imgMcName)._alpha =0;
imgLoader.loadClip(folder+"/" + imgCurLoad + ".jpg",imgMcName);
}
}
imgLoader.onLoadComplete = function(target_mc:MovieClip){
traceAlert("target_mc "+target_mc)
traceAlert("photo number loaded "+imgMcName.substr(3,1));
if(imgCurLoad == 1){
eval(imgMcName)._alpha = 100;
imgSelected = imgCurLoad;
//this is the interval that shows the next pic. It hides the previous and fades in the next one
auto_foto=setInterval(pict_av,Number((fotodelay+fade_largo)*1000))
}
//Incriment imgCur for the next load, and start the process again
imgCurLoad++;
loadImg();
}
OnEnterFrame Only Firing Once
The following is on the _root timeline:
ActionScript Code:
var container:MovieClip = this.createEmptyMovieClip("container", this.getNextHighestDepth());
for (var a in imagePaths) {
var fallingImage:MovieClip = imagesContainer.createEmptyMovieClip("img" + a, imagesContainer.getNextHighestDepth());
fallingImage._x = Math.random() * Stage.width;
fallingImage._y = (Math.random() * 80) - 160;
fallingImage.loadMovie(imagePaths[a]);
fallingImage._xscale = fallingImage._yscale = 25;
fallingImage.onEnterFrame = function() {
this._y += 5;
trace(this);
}
}
The movieclips are loading the images as requested and they're appearing on the stage. But the onEnterFrame handler is firing only one time for each movieclip generated in the loop. In it, the _y values of the mcs update as they should, the trace works properly, but the handler never fires again, therefore, the _y value isn't updating (and the mcs aren't "falling") as they should. It shouldn't be a scope issue. At least I don't think it is.
Why isn't this working right? I've never had this happen before and I can't make sense of it.
MC's Firing Towards The User
Hello,
I'm struggling with some code for a game I am making. I want a movieclip to move across the screen and for that movieclip to shoot an arrow at the player. Where the movieclip shoots from should be random and I want the arrow to come towards the centre to the screen and not have any horizontal movement (which I keep getting when it fires from the moving MC).
Can anyone help me out at all with any of the code I need here as it's starting to drive me nuts!?
Thanks very much,
Pnub
AddEventListener Not Firing?
Hi,
I am trying to programatically add the rollover and rollout event to my button instance specifically using the addEventListner as I have multiple buttons that I wish to fire the same events, however I simply can't get them to fire... any suggestions as to what I am doing wrong?
btn_United_Kingdom.addEventListener("rollOver", listenerObjRollOver);
btn_United_Kingdom.addEventListener("rollOut", listenerObjRollOut);
listenerObjRollOver = new Object();
listenerObjRollOver.rollOver = function(eventObject){
trace("rollOver");
}
listenerObjRollOut = new Object();
listenerObjRollOut.rollOut = function(eventObject){
trace("rollOut");
}
DispatchEvent() Not Firing
Not sure why the dispatchEvent() isn't firing when the loadSound method fails. It works when the file successfully load, but doesn't if there is a URL error. I'll post some code first and then give my thoughts.
ActionScript Code:
//
// *******SUPER CLASS OF MUSIC CONTROLS********
//
import net.foo.utils.Delegate;
import mx.events.EventDispatcher;
class net.foo.sound.Music
{
private var sound:Sound;
// add method references so compiler doesn't complain
public var addEventListener:Function;
public var dispatchEvent:Function;
// static properties for dispatching events
public static var META_DATA:String = "metaData";
public static var LOAD:String = "load";
public function Music(file:String, duration:Number)
{
EventDispatcher.initialize(this);
sound = new Sound();
sound.onID3 = Delegate.create(this, onMetaData);
sound.onLoad = Delegate.create(this, onLoad);
sound.loadSound(file, true);
if (duration != undefined) this.duration = duration;
}
private function onLoad(success:Boolean):Void
{
trace("Music.onLoad called");
if (success)
{
if (duration == undefined ) duration = sound.duration;
this.dispatchEvent( {type:LOAD, target:this} );
}
else
{
this.dispatchEvent( {type:LOAD, target:this} );
trace("FAILED TO LOAD");
}
}
}
ActionScript Code:
// set up the control for the music playback
music.killAll();
music = new MusicControls(this.url, guide1_mc, scrub1_mc, time_txt);
music._duration = this.time;
music.controls(play_btn, pause_btn, forward_btn, undefined);
music.controlVolume(scrub2_mc, guide2_mc);
music.soundComplete();
music.buffer(waiting_mc);
music.addEventListener(Music.LOAD, onMusicLoad);
My thinking is that the EventDispatcher doesn't have time to initialize when the loadSound produces a URL error, and therefore never fires. All of the traces fire as expected.
OnLoadInit Not Firing?
I have a simple image loader, everything is working fine EXEPT onLoadInit. Any Clues?
PHP Code:
var imgLoader = new MovieClipLoader();
this.onLoadStart = function(movieMC) {
trace("load has begun on "+movieMC);
}
this.onLoadProgress = function(movieMC, loadedBytes, totalBytes) {
trace("progress");
// stuff happens
}
this.onLoadComplete = function(movieMC) {
trace("complete");
// stuff happens
}
this.onLoadInit = function(movieMC) {
trace("init");
// nothing %@*%& happens!!!
}
On (release) Not Firing
I know someone recently asked a similar question, but I do not believe my problem is an issue of scope.
I have a button symbol. I have place the following code in the ActionScript of the button:
on (release) {
trace("Hit me, baby, one more time! ");
}
This never fires. The button exists for the duration of the program, but this never fires, no matter when or how many times I click on the button.
I am using CS3, recently installed and updated.
Thanks in advance for any insights you may have.
AddTarget Not Firing
I dynamically create a MovieClip dragMC in a Class. In the same Class I then want to animate this MovieClip. (The script is an adaption from the Copy Motion to ActionScript3 Command). There is no error message; it's just that nothing happens to the MovieClip.
If I paste the script simply into the main timeline and put a MovieClip named dragMC on the stage, it works fine...
Any suggestions?
Attach Code
import fl.motion.AnimatorFactory;
import fl.motion.MotionBase;
import flash.filters.*;
import flash.geom.Point;
var __motion_FlipCard:MotionBase;
if(__motion_FlipCard == null) {
import fl.motion.Motion;
__motion_FlipCard = new Motion();
__motion_FlipCard.duration = 20;
// Call overrideTargetTransform to prevent the scale, skew,
// or rotation values from being made relative to the target
// object's original transform.
// __motion_FlipCard.overrideTargetTransform();
// The following calls to addPropertyArray assign data values
// for each tweened property. There is one value in the Array
// for every frame in the tween, or fewer if the last value
// remains the same for the rest of the frames.
__motion_FlipCard.addPropertyArray("x", [0,-2.23077,-4.46154,-6.69231,-8.92308,-3.06155,2.79999,8.66153,12.6869,16.7123,20.7377,24.7631,28.7885,21.0702,13.352,5.63367,-2.08461,1.61026,5.30513,9]);
__motion_FlipCard.addPropertyArray("y", [0,3.67307,7.34615,11.0192,14.6923,15.9128,17.1333,18.3538,14.4023,10.4507,6.49922,2.54769,-1.40384,-4.74325,-8.08267,-11.4221,-14.7615,-8.841,-2.9205,3]);
__motion_FlipCard.addPropertyArray("scaleX", [1.000000,0.977230,0.954459,0.931689,0.908918,0.886148,0.863377,0.840607,0.794632,0.748657,0.702683,0.656708,0.610733,0.568451,0.526169,0.483887,0.441605]);
__motion_FlipCard.addPropertyArray("scaleY", [1.000000,0.975069,0.950139,0.925208,0.900277,0.875346,0.850416,0.825485,0.773904,0.722323,0.670743,0.619162,0.567581,0.528824,0.490067,0.451309,0.412552]);
__motion_FlipCard.addPropertyArray("skewX", [0,0.000109672,0.000219345,0.000329017,0.00043869,0.000548362,0.000658035,0.000767707,0.00087738,0.000987052,0.00109672,0.0012064,0.00131607,0.00142574,0.00153541,0.00164509,0.00175476]);
__motion_FlipCard.addPropertyArray("skewY", [0,0.0943986,0.188797,0.283196,0.377595,0.471994,0.566392,0.660791,0.75519,0.849588,0.943987,1.03839,1.13278,1.22718,1.32158,1.41598,1.51038]);
__motion_FlipCard.addPropertyArray("rotationConcat", [0,-3.74992,-7.49985,-11.2498,-14.9997,-19.9404,-24.8812,-29.8219,-32.8203,-35.8186,-38.817,-41.8153,-44.8137,-48.5748,-52.3358,-56.0969,-59.858]);
__motion_FlipCard.addPropertyArray("blendMode", ["normal"]);
__motion_FlipCard.addPropertyArray("alphaMultiplier", [0.800000,0.800000,0.800000,0.800000,0.800000,0.733333,0.666667,0.600000,0.560000,0.520000,0.480000,0.440000,0.400000,0.350000,0.300000,0.250000,0.200000,0.133333,0.066667,0.000000]);
// Create an AnimatorFactory instance, which will manage
// targets for its corresponding Motion.
var __animFactory_FlipCard:AnimatorFactory = new AnimatorFactory(__motion_FlipCard);
__animFactory_FlipCard.transformationPoint = new Point(0.500000, 0.500000);
// Call the addTarget function on the AnimatorFactory
// instance to target a DisplayObject with this Motion.
// The second parameter is the number of times the animation
// will play - the default value of 0 means it will loop.
__animFactory_FlipCard.addTarget(dragMC, 0);
} // end if
Bug Firing Thingy
Hi!
i was wondering how i could make some other bugs coming from other side, random and when they are hit with max 3 bullets they explode?
could you help me with that?
Arrow Firing
I want to make this a game eventually, but I'm not that far yet. Right now it just fires the arrows. I tried to make them fly realistically so the arrows follow parabolic flight paths. I'd appreciate any game ideas or any suggestions for how to make it better.
(and I know the arrow should rotate around the center, but now the registration point is at the tail, not a huge problem, but on some of the steeper angles it messes up the rotating a bit. I'm just too tired and lazy to fix it now.)
click and drag to set power and angle and release to fire. click path and it will trace the path of the arrows you fire.
http://img440.imageshack.us/my.php?i...wengineyk2.swf
Firing Pop Ups From Pop Ups In Flash
Hi i have a website that is running via a full screen pop up window which initially gets fired of by a splash screen. I now need a button withing the full screen to pop up another window to a specific size. Problem is, it uses the same window and i loose my original page to load the new page.
Heres the coding i am using, is there anything i can do?
[code]on (release) {getURL("javascript:NewWindow=window.open('webpage .html','newWin','width=360,height=500,left=0,top=0 ,toolbar=No,location=No,scrollbars=No,status=No,re sizable=No,fullscreen=No'); NewWindow.focus(); void(0);");
}
[code]
Do i need to change wording in the coding?
Please help me out if you can!
Thank you!
FullscreenEvent Not Firing?
Hey all,
I have the following:
A document class, extending from a custom class, extending from MovieClip. In my document class, I assign a handler to the FullScreenEvent like so:
Code:
addEventListener(FullScreenEvent.FULL_SCREEN, function(e) { toggle_fullscreen(); });
Also, I've set up a SimpleButton to call that same function, toggle_fullscreen, when clicked.
Here's the catch:
When I click the button, my app goes fullscreen. When I press Esc, the app goes back to normal but the FullScreenEvent doesn't get fired, so I can't catch it to re-align the elements on my stage.
I've also tried to add the event listener to the stage object of my document class, but that doesn't work either.
Any ideas?
Firing Lasers
hey guys,
im making a space shooter game in as3 and im really stuck on making the lasers fire in the direction that the ship is facing. if anyone can help me id really appreciate it. this is the code i got so far
function fireLaser(event:Event):void{
var laser:Laser = new Laser();
laser.x = spaceShip.x;
laser.y = spaceShip.y;
laser.rotation = spaceShip.rotation;
addChild(laser);
laser.addEventListener(Event.ENTER_FRAME, moveLaser);
}
function moveLaser(event:Event):void{
event.target.y -=5;
if(event.target.y <= -10){
event.target.removeEventListener(Event.ENTER_FRAME , moveLaser);
removeChild(MovieClip(event.target));
}
}
thanks
Loop Not Firing
I'm having an odd issue. In the authoring environment this code works perfectly. Because I've built deeplinking abilities into the site, I have to upload it to a testing environment on a ftp first to actually be able to use those links. When I do this, the for statement doesn't fire. Everything else does though. So when the site tries to navigate there has been no deep link assigned and nothing happens. The navigation menu however still works. If I click a link, the for statement works fine. It seems to only happen when the site initially loads. On the initial load, the for statement gets skipped. I have no idea why its doing this. Any help?
Code:
function handleSWFAddress(e:SWFAddressEvent) {
var pageValue:String = e.value;
if (pageValue == '/') {
pageValue = '/home/';
}
for (var i:int=0; i < buttons.length; i++) {
var btn:MovieClip=buttons[i];
if (pageValue != btn.deepLink) {
enableBtnProps(btn);
TweenMax.to(btn, 0.25,{tint:0xffffff});
} else {
disableBtnProps(btn);
TweenMax.to(btn, 0.25,{tint:0x5ca7ba});
whichCat.deepLink = btn.deepLink;
whichCat.src = btn.src;
whichCat.name = btn.name;
}
}
fadeLoader();
SWFAddress.setTitle('The Window People '+whichCat.deepLink);
}
Bug Firing Thingy
Hi!
i was wondering how i could make some other bugs coming from other side, random and when they are hit with max 3 bullets they explode?
could you help me with that?
|