[F8] Performing Action Just Once On Value Change
here's my code.
Code:
if(playerDist <= 50){
trace("ATTACK");
}
if(playerDist > 50 && playerDist < 100)
{
var moveX = this.moveDist * (thetaX*-1 / playerDist);
var moveY = this.moveDist * (thetaY*-1 / playerDist);
this._x -= moveX;
this._y -= moveY;
}
if(playerDist >= 100)
{
if (this.moveDist >= targetDist) {
this._x = this.currentDest.x;
this._y = this.currentDest.y;
this.assignNextDest();
}
else
{
var moveX = this.moveDist * (deltaX*-1 / targetDist);
var moveY = this.moveDist * (deltaY*-1 / targetDist);
this._x -= moveX;
this._y -= moveY;
}
}
This code is being run in an onEnterFrame and playerDist is simply a variable containing the distance between the enemy and the player. I want this.assignNextDest() to run once and only once every time playerDist goes from being less than 100 to being greater than or equal to 100.
FlashKit > Flash Help > Flash ActionScript
Posted on: 06-17-2007, 02:37 AM
View Complete Forum Thread with Replies
Sponsored Links:
Performing An Action For Every 3% Loaded...
My code is below.....I have a "count" variable initialized in the first keyframe, set to 1. I have 32 squares on my screen. Every 3%, I want one of them to randomly popup.
I have 1 pop up when the streaming is at 4.9KB/s and 3 pop up when its set to 20KB/s. Thats all. Does my if statement look correct? Thanks, I can explain more if my task isn't clear.
onClipEvent(load) {
array2 = new Array();
for (r=1;r<=4;r++) {
for (c=1;c<=8;c++) {
array2.push("a"+String(r)+String(c));
}
}
}
onClipEvent(enterFrame) {
total_bytes = _root.getBytesTotal();
loaded_bytes = _root.getBytesLoaded();
myNum = Math.floor(Math.random()*array2.length);
square = array2.splice(myNum, 1);
if (((loaded_bytes/total_bytes)*100) >= (3*_root.count)) {
_root[square]._alpha = 100;
_root.count++;
}
if (count == 32) {
_root.play();
}
}
View Replies !
View Related
Animate Out Before Performing Action
hello!
so i'm somewhat new at this and am trying to figure out how to create a scene that stops and then on button click, will animate out before performing another action.
i found the following script but am not sure how to use it, can anyone out there help me out.
thanks in advance.
stop();
function slideOutThenJump(targ_mc, targ_x, seconds, label) {
trace("Called slideOut");
// How far away is the target X position?
var diff = targ_x-targ_mc._x;
// How many pixels per second to animate for 'seconds' seconds?
// Assumes a setInterval of 66ms
pxPerInt = Math.ceil((diff/seconds)/15);
_global.animInterval = setInterval(anim, 66, targ_mc, targ_x, pxPerInt, label);
}
function anim(targ_mc, targ_x, pxPerInt, label) {
targ_mc._x += pxPerInt;
if (targ_mc._x>=targ_x) {
clearInterval(_global.animInterval);
_root.gotoAndStop(label);
}
}
slideOutThenJump(_root.test_mc, 200, 1, "myLab");
View Replies !
View Related
Performing An Action When Mouse Is Still
I am using flash mx2004 and I am trying to think if there is a way to perform an action when the user's mouse is still.
I want the program to play music when the mouse is moving, but stop it when the mouse is still.
To play the sound I use:
_root.pos=0;
_global.myMusic = new Sound();
myMusic.loadSound("song"+curtrack+".mp3", true);
myMusic.start((_root.pos),1000);
To stop I use:
_root.pos=myMusic.position;
myMusic.stop();
Is there an easy way to do this?
Thanks
View Replies !
View Related
Dragging An Object Then Performing An Action
Hi guys,
Im having some trouble trying to get this code written correctly. Basically im trying to drag an object and when it hits the target then go to a specific frame depending on the current frame. Else if currently on a different frame go to another specified frame instead. Confusing i know but if you have a look at these two attempts below you will get a better idea what im trying to do:
----------------------------------------------------------------
on (press) {
startDrag("/record1");
}
on (release, dragOut) {
stopDrag();
if (getProperty("/record1", _droptarget) eq "/target1") {
tellTarget ("_root") {
_root._currentframe==1
gotoAndPlay(33);
}
}
else if (getProperty("/record1", _droptarget) eq "/target1") {
tellTarget ("_root") {
_root._currentframe==10
gotoAndPlay(11);
}
}
----------------------------------------------------------------
----------------------------------------------------------------
on (press) {
startDrag("/record1");
}
on (release, dragOut) {
stopDrag();
if (_root._currentframe==1){
(getProperty("/record1", _droptarget) eq "/target1")
tellTarget ("_root") {
gotoAndPlay(33);
}
}
else if (_root._currentframe==10){
(getProperty("/record1", _droptarget) eq "/target1")
tellTarget ("_root") {
gotoAndPlay(11);
}
}
----------------------------------------------------------------
Anyone any ideas?
Thanks.
View Replies !
View Related
Dragging An Object Then Performing An Action
Hi guys,
Im having some trouble trying to get this code written correctly. Basically im trying to drag an object and when it hits the target then go to a specific frame depending on the current frame. Else if currently on a different frame go to another specified frame instead. Confusing i know but if you have a look at these two attempts below you will get a better idea what im trying to do:
----------------------------------------------------------------
on (press) {
startDrag("/record1");
}
on (release, dragOut) {
stopDrag();
if (getProperty("/record1", _droptarget) eq "/target1") {
tellTarget ("_root") {
_root._currentframe==1
gotoAndPlay(33);
}
}
else if (getProperty("/record1", _droptarget) eq "/target1") {
tellTarget ("_root") {
_root._currentframe==10
gotoAndPlay(11);
}
}
----------------------------------------------------------------
----------------------------------------------------------------
on (press) {
startDrag("/record1");
}
on (release, dragOut) {
stopDrag();
if (_root._currentframe==1){
(getProperty("/record1", _droptarget) eq "/target1")
tellTarget ("_root") {
gotoAndPlay(33);
}
}
else if (_root._currentframe==10){
(getProperty("/record1", _droptarget) eq "/target1")
tellTarget ("_root") {
gotoAndPlay(11);
}
}
----------------------------------------------------------------
Anyone any ideas?
Thanks.
View Replies !
View Related
Key.ENTER Performing Action In More Than One Layer
Ok in Layer (5) i have this relevant code:
Code:
//IF ENTER KEY...GO TO btnSend
k = new Object();
k.onKeyDown = function() {
if (Key.getCode() == Key.ENTER && txtSubmit.text != "") {
sendIt();
}
};
Key.addListener(k);
And on layer (10) i have the following:
Code:
//IF ENTER KEY...trace example
k2 = new Object();
k2.onKeyDown = function()
{
if (Key.getCode() == Key.ENTER && txtSubmit.text != "")
{
trace("working");
}
};
Key.addListener(k2);
When i hit ENTER on layer 10... the action sendIt() from layer (5) is performed...
What i may be doing wrong ?
View Replies !
View Related
Checking For Dynamic Text And Performing Action
Hi I need some help with this code.
I have this button, who's text is loaded dynamically, the button text is inside an mc, I need for the dynamic text's mc to be invisible when no dynamic text is loaded and visible when text is loaded.
Currently the button on its visible state sits on frame label "on" and I've created another frame labeled "off", I just don't know how to put together the action to make the frame switch to "off" when no dynamic text is loaded to make the button invisible.
any help would be appreciated.
View Replies !
View Related
Playing An "outro" Then Performing An Action
Hello all,
I'm having a problem figuring out something which I'm assuming is pretty simple.
Basically, I have some navigation. Each navigation item has it's own area in the main timeline which contains a movie clip with the actual content. That movie clip has an "intro" and an "outro". When you click on one of the sections respective buttons, I'd like it to play the active section's "outro" and then once that is done, go to the that sections area on the main timeline and play the "intro" (essentially the first frame).
I've uploaded an test fla to:
http://www.houser02.com/test.fla
Can anyone be of any help?
Thanks in advance!
Brandon House
View Replies !
View Related
Change Action
Hi... how i can transform this
#include "lmc_tween_as1.as"
$tweenManager.broadcastEvents = true;
btn1.onPress = function(){
window_mc.resizeTo(100 + random(200), 100 + random(200), 1, "easeoutelastic")
}
in an frame action...
because this work with a button and this must to start in the first frame, not with the button... thanks...
View Replies !
View Related
Action Script To Change The Fps
Hi all this my first time here... i got a problem, i dont really know how to change the fps in the middle of the movie....it must be able to make it faster and also slower....is there actually a possibilityof creating this??=Þ
View Replies !
View Related
Action Panel Change
I usually work in MX but because i'm working with someone elses source files, I've been forced to upgrade to 2004 prof. On the outside, it didn't seems much different but when I try and create some basic actionscript, I see it's changed big style. I only know basic commands so I always used to create my AS in normal mode as I don't do enough to remember the syntax. I always used the drop down menus and text input fields but they now seem to have been removed – can this be true? I only upgraded because I was forced to, is there no way to get the new actions panel to work the way of the old i.e. in normal mode rather than expert?
Pulling my hair out…
View Replies !
View Related
Change Action In A Button
Is there a way to change the default action in the button?
This is what i have:
ActionScript Code:
on(press){
getURL(this.link, _self);
}
on(rollOver){
this._parent.gotoAndPlay("o");
}
on(rollOut){
this._parent.gotoAndPlay("t");
}
when a person clicks on it it goes to a new page, now what i need this button to do isa change to this.
ActionScript Code:
on(press){
getURL(this.link, _self);
}
on(rollOver){
this._parent.gotoAndPlay("o");
}
on(rollOut){
this._parent.gotoAndPlay("o");
}
is there a way to do this?
my function is this in Frame 1
ActionScript Code:
function secondFrame(myPath, myParent) {
if (myParent.page == myPath._name) {
myPath.gotoAndPlay("o");
myPath.button._visible = true;
myParent.headers.gotoAndPlay(myPath._name);
}
}
View Replies !
View Related
Action Script To Change The FPS
Hi all this my first time here... i got a problem, i dont really know how to change the fps in the middle of the movie....it must be able to make it faster and also slower....is there actually a possibility of creating this?? 10q
View Replies !
View Related
Action Script To Change The FPS
Hi all this my first time here... i got a problem, i dont really know how to change the fps in the middle of the movie....it must be able to make it faster and also slower....is there actually a possibility of creating this?? 10q
View Replies !
View Related
Action Script To Change Font?
I'm working on an update of a large flash file with thousands of texts. One of the things I have to is to change the font and font sizes. I am a newbie to AS. Can one write action scripts to replace font/font size in the entire flash file globally?
Any info is appreciated.
View Replies !
View Related
Can I Change The Action Of A Button After 5th Click
hi,
I have a button that makes my movie goto frame(a) and play but I want the button make my movie go to frame(b) after 5th click on this button and play.
I mean in first 4 click I want it to do some action but after 4th click it has to change its mission,is it possible(I guess so) and how?
thanks for your time.
-----------------------------
http://www.mehmetsaygin.com
View Replies !
View Related
Change Button's Action When In Different Movie
I want to change a button's ("forwardButton")action from different movie. My problem is that the button is embedded inside another movie symbol (labeled "mButton"). My code is not working. Please tell me if the code should be something else.
_level100.mButton.forwardButton.onRelease = function():Void{
// do what u want
}
View Replies !
View Related
Change Action Script From Browser
hello y want to put a swf in a html page
the swf has a buton whith geturl to send variables,
and y want when the page is on again it show another scene ("end scene"),
and if y go to other htlm page (all whith the same swf file) from
a html link in the page go to the link whith the sme swf but if
the swf is in the "end scene" keep this scene.
Is for a cms and only have a index.php (whit a html inside)for the template.
View Replies !
View Related
.:: Performing Currentframe Check... But HOW? ::..
OK, here's what i want to do
on (press) {
if (_currentframe=3) {
stop();
} else {
tellTarget ("object") {
gotoAndPlay(16);
target = "3";
}
}
}
I'll check currentmovie frame - if it's 3 then i want to do nothing
if if's other than to i want it to tellTarget "object" to play frame 16 and then in the frame 16 there's a command
_root.gotoAndStop(target);
so it goes back to _root and plays frame (variable target) 3 (defined in button above).
It works OK, unless I add this if/else sentence... then it doesn't.
So basicaly, what I want to achive is to perfom a check if the current frame = target frame if yes - I want to do nothing.
View Replies !
View Related
Performing Mathematical Operations
Can someone explain to me how I can set up an an application so that when a person types "3" in one text box and types "4" in another box, I can get another box to automatically give me what they add up to...
I understand if I have three text boxes... giving var names of "a","b", and "c" I could do...
a=2*3
b=3+4
c=a+b
However that is me typing in the value of "a" and "b".
How can I do it so another person can type in the two values so "C" can calculate the value?
View Replies !
View Related
XML Performing Actionscript Link
Hello,
I've been searching around for a way to have one or two words of my dynamic XML perform an on release, loadMovie action, is this possible?
I've seen ways to have the entire child load a movie, but I just want a couple words to do this.
What I had before was some text, with a link that grabbed an external SWF and loaded it into a blank movieclip, but now I converted everything to XML and obviously can't get this to work. Any ideas? I can get HTML to work fine from my XML file, but can't get a portion of the text to perform an Actionscript link.
Any help would be much appreciated!
View Replies !
View Related
Performing Basic Calculations
hi
im using remoting to retrieve data from a database. ive managed to retrieve data into a text box. below is a part of the code:
this.name_txt.htmlText = "<b>"+rs.getItemAt(i).Name+"</b>"
what i want to do is get the number which appears in the name_txt box and perform a simple calualation on it (i.e /2) and then output this new calculation into another text box. only problem is, ive been trying to do this and i dont know how to write the code to do this, im sure its fairly easy but ive tried and nothing comes up. any help is appreciated. thanks!!
View Replies !
View Related
* Operator Not Performing For Scrubber
hey guys...i am making a scub bar for a video player. Right now, all is fine, except the actual scrub script. When i press the loadBar (dynamically scaling as video loads) the video stops. the crazy thing is on the 3rd line, if i change the operator to "/" it works like i want it to, only mirror image (move the pointer left, the scubber goes right). What's up with that * operator?
Code:
loadBar.onPress = function() {
progressBar.onEnterFrame = scrubIt;
};
loadBar.onRelease = loadBar.onReleaseOutside=function () {
progressBar.onEnterFrame = checkPlayhead;
};
function scrubIt() {
var distance = (_root._xmouse-loadBar._x)/loadBar._width;
newVidPlace = Math.floor(stStreamer.duration * distance);
stStreamer.seek(newVidPlace);
progressBar._xscale = (stStreamer.time/stStreamer.duration)*100;
}
View Replies !
View Related
Performing Two Actions At The Same Time
I have a button that when rolled over should make two movie clips play, but nothing is happening.
I'm using this code in a timeline frame:
Code:
button1_mc.onRollOver = function ()
{
info_box_appears_mc.gotoAndPlay(1);
button1_mc.gotoAndPlay(1);
}
There are no syntax errors, and it seems like it should work, but it does not.
View Replies !
View Related
Performing An External Operation
Hi All
Thanks in advance for any help.
Is it possible to have a button in a SWF that changes a users WINDOWS DESKTOP background? If so how? Lets say there are ten images the user can choose from, and they just click on it to install as a windows background.
Regards
Art
View Replies !
View Related
XML Performing Actionscript Link
Hello,
I've been searching around for a way to have one or two words of my dynamic XML perform an on release, loadMovie action, is this possible?
I've seen ways to have the entire child load a movie, but I just want a couple words to do this.
What I had before was some text, with a link that grabbed an external SWF and loaded it into a blank movieclip, but now I converted everything to XML and obviously can't get this to work. Any ideas? I can get HTML to work fine from my XML file, but can't get a portion of the text to perform an Actionscript link.
Any help would be much appreciated!
View Replies !
View Related
Change The Perspective Of A MovieClip With Action Script?
Hello is there anyway that i can change the perspective of a movie clip that contains an avi sequence. i would like to do this without editing each frame. if you want to know what i am trying to say take a look at my site(i would like to place a movie clip on the right wall in the shape of its perspective, but i do not want to edit each frame of that movie clip. can action script make one action that can save me all that time?):
http://www.jwm-studio.com/studio_new.html
View Replies !
View Related
Not Able To Change Scenes From Button Action Script
Hi all,
I have a button that I have downloaded from the flashkit site. It has been done as a movie symbol with a button symbol linked in to one of the layers on the movie button.
Hope that is not too confusing?
I am trying to make the button move to a new scene after "button release" but the area where the drop down box for all the different scenes is grey and wont let me selest it.
Any ideas what to do?
The button I downloaded was "button2-volkan_d-2231"
Regards,
Anthony...
View Replies !
View Related
Change Behavoir Of A Symbol Using Action Script
does anyone know how to change the behavior of a symol using action script?
for instance, lets say you have a button - that you don't want to be a button a various points of your movie. is there a way to change it's behavoir from a button to a graphic.
i realize you coould do it by using duplicate symbols with different behaviors - dispersed over different frames - but i'm really looking for a way, if possible, to do it with actionscript.
View Replies !
View Related
Simple Button Action - Frame Change..
I didn't quite know how to title this thread.
I have this button and I have this movie-clip which consists of two frames. I want the button to check which frame my movie-clip is at and when clicked to go to the other frame. Any help will be really appreciated.
Penlix
View Replies !
View Related
[F8] Change Action From Radio Btn To Graphic Button?
Hello,
I have downloaded a slideshow script and i think it is great.. se attachement.
But I woul like to do 1 modification and since I am new to flash I can´t get it right. Is it possible to instead of the radiobuttons use two graphic buttons like play and pause?
ok attachement seem to big.. so here is a link to the script im trying to modify
http://www.actionscript.org/showMovie.php?id=941
Regards // J
View Replies !
View Related
[F8] Using Action Script To Change The Size Of A Movie
I have the following code. It is meant to resize the movie clip on the stage depending on how many elements (thumbnails) are in the xml file, but my problem is that it does not resize untill the next frame after the script. Can i make the box start as the new dimensions? otherwise there is an instant of the wrong size box and it looks bad.
code:
Code:
var xf:XML = new XML();
xf.ignoreWhite = true;
var urls:Array = new Array();
var arrlength:Number;
xf.onLoad = function() {
var images:Array = this.firstChild.childNodes;
for (i=0; i<images.length; i++) {
urls.push(images[i].attributes.url);
}
arrlength = images.length;
};
xf.load("imagedata.xml");
this._width = arrlength * 35;
View Replies !
View Related
Action Script To Change Mc Position Around Canvas
Hi,
I´m trying to make a Mc to move around the canvas according to the mouse position. The Mc follows the mouse on the _y coordinates.
Now I want to make it change position on the _x coordinates according to the mouse.
It´s working fine on the _xmouse position, but I´m not getting it to work in the _ymouse position. I´d like the Mc change position when the mouse is over a determined are on the stage.
Could anyone help?
This is the code I´m using
Code:
onClipEvent (load) {
this._x = 750;
//set original x
this._y = 420;
//set original y
divider = 5;
//speed
numx = this._x;
//numx is destination x
numy = this._y;
//numy is destination y
}
onClipEvent (enterFrame) {
if (_ymouse>700) {
numx = 732;
//set destination x
} else {
numx = 760;
//set destination x
}
}
onClipEvent (enterFrame) {
if (_xmouse>-230) {
numx = 732;
//set destination x
} else {
numx = 760;
//set destination x
}
x = numx-_x;
//setup variable named x
this._x += x/divider;
//see the x transition
//y=numy-_y; //setup variable named y
//this._y+=y/divider; //see the y transition
}
onClipEvent (load) {
_y = 0;
speed = 5;
}
onClipEvent (enterFrame) {
endY = _root._ymouse;
_y += (endY-_y)/speed;
}
View Replies !
View Related
Action Script To Change Mc Position Around Canvas
Hi,
I´m trying to make a Mc to move around the canvas according to the mouse position. The Mc follows the mouse on the _y coordinates.
Now I want to make it change position on the _x coordinates according to the mouse.
It´s working fine on the _xmouse position, but I´m not getting it to work in the _ymouse position. I´d like the Mc change position when the mouse is over a determined are on the stage.
Could anyone help?
This is the code I´m using
Code:
onClipEvent (load) {
this._x = 750;
//set original x
this._y = 420;
//set original y
divider = 5;
//speed
numx = this._x;
//numx is destination x
numy = this._y;
//numy is destination y
}
onClipEvent (enterFrame) {
if (_ymouse>700) {
numx = 732;
//set destination x
} else {
numx = 760;
//set destination x
}
}
onClipEvent (enterFrame) {
if (_xmouse>-230) {
numx = 732;
//set destination x
} else {
numx = 760;
//set destination x
}
x = numx-_x;
//setup variable named x
this._x += x/divider;
//see the x transition
//y=numy-_y; //setup variable named y
//this._y+=y/divider; //see the y transition
}
onClipEvent (load) {
_y = 0;
speed = 5;
}
onClipEvent (enterFrame) {
endY = _root._ymouse;
_y += (endY-_y)/speed;
}
View Replies !
View Related
Performing A Sub Sort On A Multidimensional Array
Hi everyone,
I was wondering if you could help me please.
I have the following multidimensional array:
Code:
var bestSize:Array = new Array();
bestSize.push( { counter: small, order: "1", productSize: "S" } );
bestSize.push( { counter: medium, order: "2", productSize: "M" } );
bestSize.push( { counter: large, order: "3", productSize: "L" } );
bestSize.push( { counter: xlarge, order: "4", productSize: "XL" } );
bestSize.push( { counter: xxlarge, order: "5", productSize: "XXL" } );
I want to first of all sort the array in descending order on "counter". I then want to perform a sub sort on "order" to arrange the values in ascending order. I can peform the first sort by doing...
Code:
bestSize.sortOn("counter", Array.DESCENDING)
...or by creating the following function...
Code:
function sortBySizeCounter(counterValue1, counterValue2)
{
var a, b;
a = counterValue1["counter"]
b = counterValue2["counter"]
if (a > b)
{
return -1;
}
else if (b > a)
{
return 1;
}
else
{
return 0
}
}
bestSize.sort(sortBySizeCounter);
I would like to know if somebody could suggest a way in which I could perform the required sub sort.
I am fairly new to ActionScript so apologise if this sounds like a dumb question.
Thank you in advance for your help with this.
Kind Regards,
Joe
View Replies !
View Related
Performing A Sub Sort On A Multidimensional Array
Hi everyone,
I was wondering if you could help me please.
I have the following multidimensional array:
Code:
var bestSize:Array = new Array();
bestSize.push( { counter: small, order: "1", productSize: "S" } );
bestSize.push( { counter: medium, order: "2", productSize: "M" } );
bestSize.push( { counter: large, order: "3", productSize: "L" } );
bestSize.push( { counter: xlarge, order: "4", productSize: "XL" } );
bestSize.push( { counter: xxlarge, order: "5", productSize: "XXL" } );
I want to first of all sort the array in descending order on "counter". I then want to perform a sub sort on "order" to arrange the values in ascending order. I can peform the first sort by doing...
Code:
bestSize.sortOn("counter", Array.DESCENDING)
...or by creating the following function...
Code:
function sortBySizeCounter(counterValue1, counterValue2)
{
var a, b;
a = counterValue1["counter"]
b = counterValue2["counter"]
if (a > b)
{
return -1;
}
else if (b > a)
{
return 1;
}
else
{
return 0
}
}
bestSize.sort(sortBySizeCounter);
I would like to know if somebody could suggest a way in which I could perform the required sub sort.
I am fairly new to ActionScript so apologise if this sounds like a dumb question.
Thank you in advance for your help with this.
Kind Regards,
Joe
View Replies !
View Related
Button Instance Not Performing Correctly
i have a button that when it is held down for over 2 seconds it will jump to a frame, and jump to a different frame if just pressed and not held down. I have the code working, I am trying to apply it to an instance of another button(named fwd1). If i drop the actionscript in the first frame of my actions layer it works, but not just for the frames where the button instance is defined as fwd1, but all frames of the button that aren't given an instance name. If I give the button an instance name other that fwd1 somewhere on the timeline, then the button wont work on any frame past that point, even if i setup a keyframe and add the fwd1 instance to the button somewhere farther down the timeline. Isn't the point of button instance names to allow you to code them differently on different frames but not have to create a different button?? Should I just create a new button??
thank you for any insight into this matter..
View Replies !
View Related
|