Isn't There A Find In Array Function?
Hi, do I have to loop and evaluate every element in an array to find something in it?
Rather than with some languages you can just
<if(find(string,array) gt 0 )>
M@)
FlashKit > Flash Help > Flash ActionScript
Posted on: 10-22-2002, 02:10 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Isn't There A Find In Array Function?
Hi, do I have to loop and evaluate every element in an array to find something in it?
Rather than with some languages you can just
<if(find(string,array) gt 0 )>
M@)
How Do I Find Out The Size Of An Array?
I am filling an array using .split() and I need to know how many things were loaded into the array. How can I check this number? Most languages have something like ubound(array) or something. Thanks in advance.
Find String Value In Array?
Hey, everyone. A quick question regarding arrays and strings. (Flash 5)
I have an array that holds three values: my_array("one","two","thr") which correspond to movie clips on my stage with the same instance names. Then I have buttons that sets a variable "selected" equal to _root.one, _root.two or _root.thr. Now I have a function that takes "selected" and manipulates it. This all works fine so far.
My problem occurs because after "selected" performs its actions, I want to remove the corresponding value from the array. So first I have converted the movieclip object "selected" into a string using remove1 = String(selected), then I slice out the _root. using remove2 = remove1.slice(7,-1) so now remove2 is equal to a string "one" "two" or "thr".
How do I remove this string value from the array? Is there a way to search the array values for this string and return its index? Any help is appreciated.
Thanks!
japangreg
To Find A Value Inside An Array
In Director I used getPOs() wich returned 0 if there was no such value or returned a number showing the position of the value in the array.
In FlashMX do I have to browse trough the array using for{} or what?
Is ActionScript less powerfull than lingo or is it just a different logic, because I find myself dealing with problems wich were very easily solved in Director
Thanks
Fernando
[F8] Find Next Array Item
This is probably an easy question.. If I have an array like "apples, oranges, pears, plums" and I want to find what comes after or before an item, how do I do it? For example, how would I create a button that would tell me the item that comes after (or before) "pears"?
Finding the index number of an item is easy, but how can I use it to find out what item has a higher (or lower) index number?
//find index number of "pears"
myArray = new Array('apples', 'oranges', 'pears', 'plums');
for (var i in myArray) {
if (myArray[i] == 'pears') {
arrayNum=i
break;
}
}
thanks!
Sebastian
How To Find The Name Of Selected Array?
Hi,
I have several arrays, the first of which is populated with the names of the rest of the arrays.
A function randomly selects one out of this list and then randomly selects something from THAT array.
The problem comes when I want to find out which array it selected in the first case. Basically I neeed it to perform another function if Array1 is chosen but when I try to query which array that was it just prints out all the entries.
I tried "ArrayVariable._name" but that is "undefined".
So its
ListOfArrays {
-Array1 - {values}
-Array2 - {values}
-Array3 - {values}
}
(if that makes any sense)
Whatever I try it skips stright through to listing the values. I need to find the value of ListOfArrays that was randomly selected.
Something tells me it's simple and overlooked.. hopefully I wont have to revert ListOfArrays to holding simple values then use a switch/case to turn that value into a refernce to the chosen array. That seems unecessarily messy.
Any help appreciated.
How To Find Key Of Associative Array?
Hello,
Does anyone know of an easy way to find the key value of of an associative array? This seems like it should be simple but I'm drawing a blank.
For example: I have an array that holds things like:
example_arr["CHILD1"] = "First Child";
example_arr["CHILD2"] = "Second Child";
...etc
If I know the value of the key then I can reference it like so:
example_arr[""CHILD1"]
However, I wont always know the key, hence lies the problem
Thanks!
Tommy
Find Two Numbers In An Array That Sum To A Particular Value
So, while working on my Dictionary/Hashtable tutorial, I decided to create a more interesting example that many of you may have encountered. Basically, given a huge list of numbers, the goal is to find two numbers from that list that sum up to a particular value.
I provide an example and a more elaborate description in this link. The code for it is:
Code:
//Declaring a Dictionary
Dictionary<int, int> numberHash = new Dictionary<int, int>();
//Collection of Integers
int[] values = { 144, 29, 46, 55, 33, 64, 174, 144, 168, 129, 73, 186, 24, 163, 3, 165, 160, 79, 39, 3, 81, 175, 183, 175, 15, 150, 177, 191, 29, 106, 104, 56, 58, 85, 172, 72, 119, 192, 134, 11, 10, 54, 34, 27, 194, 182, 71, 183, 132, 147, 23, 78, 70, 13, 144, 93, 104, 177, 181, 62, 155, 26, 50, 172, 158, 17, 139, 156, 105, 26, 162, 15, 65, 30, 174, 62, 175, 182, 121, 56, 23, 77, 179, 161, 168, 36, 25, 46, 137, 178, 51, 21, 65, 41, 78, 71, 196, 142, 78, 33, 130, 81, 55, 15, 131, 145, 135, 99, 116, 104, 20, 6, 22, 201, 135, 29, 148, 71, 110, 20, 104, 89, 105, 1, 10, 9, 53, 92, 75, 112, 161, 106, 196, 60, 163, 102, 109, 182, 148, 56, 88, 47, 151, 22, 119, 97, 163, 77, 126, 16, 151, 112, 143, 15, 76, 133, 124, 49, 114, 36, 183, 64, 4, 129, 201, 197, 161, 46, 103, 36, 58, 2, 78, 199, 113, 97, 53, 149, 60, 78, 63, 50, 152, 150, 140, 113, 101, 85, 80, 123, 186, 78, 95, 105, 195, 74, 121, 44, 40, 94, 149, 34, 74, 78, 28, 166, 126, 132, 51, 15, 200, 147, 77, 170, 171, 67, 67, 52, 57, 198, 186, 152, 69, 43, 194, 12, 37, 157, 144, 128, 153, 168, 130, 121, 186, 200, 195, 192, 162, 180, 95, 94, 24, 39, 37, 131, 177, 103, 106, 62, 28, 110, 145, 67, 99, 98, 137, 56, 26, 10, 56, 152, 36, 195, 150, 3, 87, 193, 16, 128, 186, 67, 122, 196, 162, 24, 56, 12, 2, 160, 190, 84, 17, 13, 112, 11, 200, 177, 120, 26, 33, 23, 11, 176, 7, 160, 49, 177, 92, 186, 176, 161, 175, 92, 30, 172, 186, 142, 145, 76, 44, 15, 171, 56, 158, 3, 9, 172, 92, 54, 101, 197, 158, 191, 102, 157, 32, 193, 156, 164, 74, 10, 106, 91, 176, 32, 132, 69, 197, 188, 184, 109, 5, 160, 200, 116, 55, 93, 143, 26, 82, 140, 52, 176, 120, 198, 178, 125, 122, 201, 44, 56, 96, 96, 29, 175, 156, 113, 17, 18, 70, 158, 159, 193, 162, 153, 40, 67, 170, 177, 182, 40, 78, 192, 173, 151, 55, 110, 142, 155, 56, 1, 134, 134, 50, 189, 105, 158, 34, 51, 17, 98, 131, 158, 89, 57, 158, 82, 112, 95, 149, 78, 60, 31, 144, 27, 94, 4, 45, 88, 152, 157, 82, 188, 73, 67, 198, 199, 198, 123, 201, 20, 171, 8, 115, 66, 144, 190, 126, 108, 5, 12, 14, 147, 35, 52, 139, 108, 57, 2, 128, 54, 157, 145, 75, 34, 26, 63, 201, 124, 198, 42, 109, 153, 177, 47, 173, 150, 3, 143, 198, 167, 110, 66, 20, 151, 147, 115, 108, 191, 142, 123, 169, 17, 127, 197, 86, 39, 144, 10, 165, 36, 151, 179, 185, 75, 39, 86, 194, 3 };
//Value to Guess
Random randomNum = new Random();
int x = randomNum.Next(10, 200);
//Trying to find two numbers that, when added, equal the sum
for (int i = 0; i < values.Length; i++)
{
int currValue = values[i];
if (!numberHash.ContainsKey(currValue)) {
int diffValue = x - currValue;
numberHash.Add(currValue, diffValue);
if (numberHash.ContainsKey(diffValue)) {
Console.WriteLine("Two values that add up to {0} are {1} and {2}", x, currValue, diffValue);
break;
}
}
}
As you can see, the code behind it is fairly simple. The ideas behind it have applications beyond this particular example, for there are many useful things you can do when storing/retriving data is really fast.
Just copy and paste that into a main method in VS2005 or another IDE and find out which two numbers in the array sum up to a value determined during runtime. You can also choose to run the attached file after extracting it. Whatever works
Cheers!
Kirupa
How To Find The Closest Value In An Array
All I'm trying to do is find a value in an array that's closest to the value of my variable...
So if the value of myVar = 50;
..and the array holds the values 25, 100, 150, etc.
I want to write a function that will be able to find the array element that's closest to myVar, which would be the first element in the array (myArray[0]), since 25 would be the closest value to 50.
If anyone out there has any ideas, I'd really appreciate it...
Find Highest Value In An Array
Can anyone tell me if there is a way to find the highest number in an array?
numbersArr(314,2613,221,103,77);
is there a way to loop though this, compare all the numbers to each other and find the highest value while keeping the array in order?
Thank you
How To Find A Function
I'm looking at a particular frame that calls a function in _root. I want to look at that function to see how it works. How do I search all frames, all layers to find where that function is? Is there anywhere that all ActionScript is viewable in one place, without having to select individual frames or browse the library?
Can't Find Function Although It's There
I'm trying to put together a space invaders game using a different class for the invaders, cannon, and bullets, as well as a InvGame document class.
In the bullet script I have a function which checks for collisions with possible targets. If the bullet is heading downwards then it will have the cannon as a target, if it's heading upwards then the invaders will be targets. It was working fine until I tried to get it to check for the cannon, then it's giving errors saying it can't find the imHit() function in the cannon script.
I've attached code below.
The cannon instance on the main timeline is called "myCannon".
Error I'm getting is
TypeError: Error #1006: imHit is not a function.
at Bullet/checkForCollision()
at Bullet/moveBul()
I know it must be how I'm defining myCannon within the Bullet code but I'm not sure how else to do it?
Any help would be much appreciated!
Attach Code
// code in Bullet.as in Bullet class
private function checkForCollision():void
// get list of possible targets
var targetList:Array;
if (direction == -1) {
// shooting upwards, targets are invaders
targetList = MovieClip(parent).getInvaders();
} else {
// shooting downwards, target is cannon
targetList = [MovieClip(parent).myCannon];
}
// loop through the array checking if there is a hit
for (var i:int=0;i<targetList.length;i++) {
if (this.hitTestObject(targetList[i])) {
// hit! tell the target
targetList[i].imHit();
// move the bullet off the screen
this.y = offscreen;
// make it inactive
shooting = false;
// return to the list of available bullets
MovieClip(parent).addBullet(this);
// finish the test for collisions
return;
}
}
}
// in the Cannon.as file, in the Cannon class:
public function imHit():void {
trace ("I've been hit!");
}
Prototype - Find String In Array?
I have a multidimensional array
arrMenu=new Array()
arrMenu.header="header"
arrMenu[0]=new Array()
arrMenu[0].header="header0"
arrMenu[0][0]=new Array()
arrMenu[0][0].header="header0-0"
arrMenu[0][1]=new Array()
arrMenu[0][1].header="header0-1"
arrMenu[1]=new Array()
arrMenu[1].header="header1"
arrMenu[1][0]=new Array()
arrMenu[1][0].header="header1-0"
arrMenu[1][1]=new Array()
arrMenu[1][1].header="header1-1"
arrMenu[1][2]=new Array()
arrMenu[1][2].header="header1-2"
I wish to have my prototype search for a string and return an array of indexes.
E.g. if I search for "header1-1" the prototype should return
arrMenuPos=[1,1]
I am having trouble looping through a multidimensional array
Any help out there?
Regards
Podenphant
*******
Array.prototype.stringInArray = function (str){
??????? uaaargh
}
*******
Find The Number Of Entries In 2D Array?
Hi, I know I can use 'length function' to find total entries of an array. But anyone know how to find the total entries for a 2D array?
Example:
In 1D array => I can use: MyArray.length;
But in 2D array??
Thanks..
Help With Array. Can't Find What's Wrong With The Script
Hey! I can't find what's wrong with this script. The way it should work: You click a button and it loads a random URL, the URL are dynamically loaded into an array form an external file. Any ideas?
Code:
btStart.onPress = function() {
dataHolder = new Object();
loadVariables('urllist.txt', dataHolder);
myArray = dataHolder.myValues.split(',');
for (i=0; i<myArray.length; i++) {
myURLarray.push(myArray[i]);
}
var nRandom:Number;
var sRandomURL:String;
function getRandomURL():String {
nRandom = Math.floor(Math.random()*myURLarray.length);
sRandomURL = myURLarray[nRandom];
return sRandomURL;
}
this.getURL(getRandomURL());
};
[F8] How Do I Find The Index (key) Of A Specific Value In An Array?
Hello All,
Is there a way to retrieve a specific element's index key if you only know the value of the element?
Usually, you give Flash an index ([0], [1], [2]...) and it gives you the value of the element at that position. I would like to do the inverse, because I know what the values of the array will be... however, they could be in any order.
Example:
myArray_array("Chris", "Mike", "Fred", "Jen", "Susan")
I want to remove "Fred" from the array; however, I don't know Fred's index key... and he could be anywhere in the array. Also, after removing "Fred", I do NOT want the array to contain an "undefined" or "empty" element where "Fred" used to be:
BAD:
myArray_array("Chris", "Mike", undefined, "Jen", "Susan")
GOOD:
myArray_array("Chris", "Mike", "Jen", "Susan")
Thanks!
Find Unique Items In Array
Hey party people,
I'm working on a project where I have an array of coordinate points (4 of them) and a menu system that, when clicked, rearranges the boxes so that they all move around. The problem is that the values I pull out of the array are not always unique so some of the items end up not moving (or sometimes it ends up moving two to the same spot because the last one didn't move and one of them moved to a spot that is already occupied).
Here is the code I was using which for the most part works, except as mentioned, sometimes the check for the last one in the loop sees that the conditional is not equal so it doesn't do anything because there is no other values to loop through and it just leaves it in that spot. i'm not sure how to fix this so any help would be greatly appreciated.
ActionScript Code:
private function checkCoordinates($item:MenuItem, $coords:Array):Void { var numItems:Number = $coords.length; for (var i:Number = 0; i < numItems; i++) { if (($item._x != $coords[i].x) && ($item._y != $coords[i].y)) { var ret:Array = $coords.splice(i, 1); var pt:Point = ret[0]; $item.moveTo(pt, 0); break; } } }
thanks to anyone who attempts to help, it's greatly appreciated.
Find Largest Integer In Array
I've got an array:
ActionScript Code:
//for instancedistances[24,30,3];
How can I find the largest integer in it? Basically want to use it as "top score" kind of thing.
How To Find Out What Number In An Array A Particular Element Is?
Essentially I need the MC to know whereabouts in the Array it is
Say you pick a movieclip at random, and assign in a function, how do you find out what number in the Array it is and remove it from the array?
For example...
Code:
for(a=0; a<arrayInQuestion.length; a++) {
if(arrayInQuestion[a]!=this) {
if(dist>50) {
arrayInQuestion.splice(this, 1)
}
}
}
But of course, "this" doesn't work, so I need to find out what number "this" is
Of course, it would be easy to remove the MC that I am checking "this" for distance with, it would just be splicing array[a], but it's "this" that I am just not sure how to splice.
Cheers,
Joe
1 Function Cant Find Variables.
hi, please help,
got this code in the only frame of a menu item:
Code:
var goto:Number=0;
function name(t:String,f:Number=0):void {
trace(goto);//debug
goto=f;
visible=true;
Words.text=t;
Words.autoSize="center";
}
function clicked():void {
trace(goto);//debug
//this.parent.gotoAndStop(goto);
}
now, the clicked function can trace "goto" the name function (which i called on the frame of the parent) cannot trace, therefore change "goto".
this is in flash cs3 only,
maybe the problem will be fixes if i make it an external as file?
EDIT: i think i found the problem,
maybe, the function gets called (by the parent)
before the init code is called (parent before children)
true?
[CS3] Cant Find Where Function Is Being Triggered
Hi guys,
This is a bit of a strange one because what i am trying to do seems to be already done in my project/fla.
On my website i have background images that get loaded randomly when every a user visits my site.
I was looking to making this a bit cooler with the background images continuing to change as the user browses the site.
Ok so here's the problem.
The function that i have in place at the moment seems to continually trigger and i have no idea why. I have it set to only trigger once when the site loads up.
Is there anyway to see where the trigger for the function is coming from?
I never have used the flash debugger and i am thinking that in here i might find where i will find where the trigger is coming from.
Can someone advise?
Thanks
Flash Cannot Find A Function
Hi guys!
I'm having the weirdest problem..
I have a function that starts another function
for example i have
code: function one() {
two();
}
function two() {
//do stuff
}
function three() {
two();
}
function one runs great.
function two runs too.
but im getting an error with function three:
TypeError: Error #1010: A term is undefined and has no properties.
I'm completely clueless about what in the world could cause this
And yes I'm using Flash IDE instead of classes
I can post you the whole script too if need be..
Thanks,
Martin.
AMFPHP -> Can't Find Function
Hi there fellow remoters.
im having this really strange error with a remoting job im doing.
Basically, I have a flash file that [through AMFPHP] talks to PHP [version 5.0.2]
The service/php class is called Login, and there are a series of methods/php functions that operate 100% A-Ok, however, yesterday I added two additional methods, which through a PHP debugging session work fine, no errors, no echo's or output what so ever, it just returns an array [and trust me, theres nothing special in the methods, just get info from the DB, turn it into an array, spit it back to flash]
So, in effect, I have a php class that operates fine when I call it from php, however, when I call it from flash, it will only find some of the methods [in this case, 3 out of 5 functions can be found]
FYI - NC Debugger returns this error:
DebugId: 2
EventType: "Status"
MovieUrl: "file:///X|/job/041124_v4/_Site/_swf/Toolkits.swf"
Protocol: "http"
Source: "Client"
Time: 1114128467625
Date (object #1)
....."Fri Apr 22 10:07:47 GMT+1000 2005"
Status (object #2)
.....code: 256
.....description: "Function getUserAccess does not exist in class Object id #7."
.....details: "E:job 41124_v4\_Site\_runwayflashservicesapp Executive.php"
.....level: "User Error"
.....line: 260
Any Ideas?
I can give you more code if you like !!!
Cheers !!!
Function To Find And Area
Hi friends,
Write a function to find and area of rectangle. Inputs, which will be given to the function will be rectangle's width and height.
plz help me how i do.
thanx
flash4lover
Cant Find Where Function Is Being Triggered
Hi guys,
This is a bit of a strange one because what i am trying to do seems to be already done in my project/fla.
On my website i have background images that get loaded randomly when every a user visits my site.
I was looking to making this a bit cooler with the background images continuing to change as the user browses the site.
Ok so here's the problem.
The function that i have in place at the moment seems to continually trigger and i have no idea why. I have it set to only trigger once when the site loads up.
Is there anyway to see where the trigger for the function is coming from?
I never have used the flash debugger and i am thinking that in here i might find where i will find where the trigger is coming from.
Can someone advise?
Thanks
Problem W/ Targetting A Mc In An Array (cant Find The Level)
Firstly, thanks to the people that helped me out with this problem so far. It's really appreciated!
My main movie is set up much like a praystation tutorial, it is an array that links clips together horizontally with buttons on top that jump/slide the movie back and forth. Within each mc that is loaded into the array, there's a few for the subsection.
I have the subsection parts set up so when you hit the nav on the subsection, it loads a movie on top of the previous one (about_mc.swapdepths(mydepth++); within the MC (thats located within the main movie)
on my main timeline I have a variable-
_global.mydepth = 10;
the first main button has this script-
_level0.content_mc.section_0.sectioncontent_mc.abo ut_mc.swapDepths(mydepth);about_mc.gotoAndPlay(2);
When I had everything on the 10th level, I could target each clip and from the main time line, but since now it is loading a new movie (++) above the top level, I cant figure out a way to target the clips. What I want to happen is have each subsection reset itself to the beginning when the user hits the top button that slides the array over to a new section.
I have uploaded my current movies, maybe someone can help me out. It's for my portfolio.
www.quintessence-media.com/main.html
www.quintessence-media.com/topnavbar.fla
www.quintessence-media.com/section_0.fla
thanks in advance.
HELP: Find Position Of Word In Assoc Array
Hi all,
I'm trying to make a function that searchs an assoc array for a word and then returns its position in the array, but so far it's not working. Any know what I'm doing wrong?
ActionScript Code:
var aNames:Array = new Array({fname:"John", lname:"Smith"}, {fname:"Jake", lname:"Lane"}, {fname:"Owen", lname:"Bridge"});
//
trace("Word is at pos: "+wordPos(aNames, fname, "Owen"));
//
function wordPos(array, assoc, word) {
for (i=0; i<array.length; i++) {
if (array[i].assoc == word) {
return i;
}
}
}
Find Frame Label Within Function.
Hi,
I'm trying to make a function that when called will check to see if the current frame is either "preopen", "open", "preclose" or "close". If preopen gotoandpaly "open" and so on,
problem is I don't know how to make this function check the name of the current frame so that the nested function will work.
I figured something like:
function checkFrame() {
var frame = _currentframe;
if(frame == "preopen") {
gotoAndPlay("open");
}else{
if(frame == "preclose") {
gotAndPlay("close")
}
}
but it don't work any ideas/help would be gratefully recieved.
Cheers
Find & Replace Function Broken Or Something?..?
I noticed some time ago that when trying to run find & replace on actionscript didn't work find any of these:
}
if that's all I put in the 'find' window. So that was irritating. NOW I can't even get it to find multiple lines!!!!! What the heck is the deal???
If I want to find and replace code now - I have to do it one line at a time!! which doesn't work right because it just leaves empty lines in the code that I can't find & replace either....!!. What the heck!?
How Can I Find Out To Which Function An OnRelease Points To?
Hi,
i'm creating this program where i am searching for all the 'onRelease' functions that are defined on the mc's in a certain swf.
So i wrote a simple porgram to check this :
ActionScript Code:
for (var props in current_mc)
{
if (props == "onRelease") storeOnRelease(current_mc[props], current_mc);
}
this works fine, but then in the storeOnrelease function i try to get the properties of those functions, which doesn't work...
ActionScript Code:
function storeOnRelease(func:Function, movie_mc:MovieClip)
{
trace("found onRelease " + func + " on " + movie_mc);
for (var props in func)
{
trace("prop " + props + " on onRelease of " + movie_mc + " = " + func[props]);
}
}
The first traceworks, but the second trace (in the 'for in' loop) doesn't show anything, so it's like there are no properties defined on that function??
Does anyone know how i could get the name of the function that is going to be executed when someone presses the mc with the onRelease?
thanks!
Calling A Function With An Array Variable As Arguments Is Resetting Array?
I'm going to post the full code of the two functions, disregard the "fluff" unrelated to the two functions as it is all working flawless, I've tested this HEAVILY and cannot understand why it keeps setting the entire array to undefined!
Any help would be grateful.
ActionScript Code:
// processReplace Function function processReplace(transferFiles) { var processArray:Array = transferFiles.slice(); var fileName:String = new String(); var filesArray:Array = new Array(); var replaceArray:Array = new Array(); var exists:String = new String(); var error:String = new String(); var promptResult:String = new String(); // Check for (i=0; i<processArray.length; i++) { // This is where it bugs up <b>exists = processSearch(transferFiles[i][1]);</b> if (exists == "replace") { replaceArray.push(processArray[i]); } else { filesArray.push(processArray[i]); } } // Prompt if (replaceArray.length>0) { error = "Replace "+replaceArray.length+" item(s):
"; for (i=0; i<replaceArray.length; i++) { error += " - "+replaceArray[i][1]+"
"; } promptResult = mSystem.messageBox(error, "Replace Existing Files?", 4); } // Action if (promptResult == "NO") { transferFiles = filesArray; } else if (promptResult == "YES") { transferFiles = filesArray.concat(replaceArray); } processTransfer(transferFiles); }
The processSearch
ActionScript Code:
// == processSearch Function function processSearch(sentInfo) { for (i=0; i<_global.boxFiles.length; i++) { if (_global.boxFiles[i] == sentInfo[1]) { return "replace"; break; } } }
Basically it's supposed to check to see if the file exists and return as true if it does and add it to a replace array, then the replace array is processed into a single string and put into a dialog box through the flash wrapper prompting them to "replace the files or not".
It makes the replace array just fine, it actually even has the right "count" in it but it's setting all the "filenames" to undefined because of the exists = processSearch function.
I even tried to make a new array and run the search just from that one and set the values from the old one and it's still failing.
Is it because of the "break" or can anyone figure it out? Iknow it's hard because you can't use the code
ANY Solution ideas are welcome, even if you think it's dumb
Thanks!
Filling Function Arguments With Array Items, Function.call()
HI!
I have this code but I cannot work out how to fill in function parameters based on an array and it's length, see line 7
ActionScript Code:
import com.robertpenner.easing.Cubic;MovieClip.prototype.framesTimeout = function(func:Function, frames:Number, args:Array) { var t:Number = 0; var mc:MovieClip = this.createEmptyMovieClip(String(new Date().getTime()), this.getNextHighestDepth()); mc.onEnterFrame = function() { if (t == frames) { func.call(this._parent,args); delete this.onEnterFrame; this.removeMovieClip(); } else { t++; } };};MovieClip.prototype.movex = function(x:Number, frames:Number) { trace(x+" "+frames) delete this.movex.onEnterFrame; this.movex.removeMovieClip(); if (!frames) { frames = 20; } var t:Number = 0; var sx:Number = this._x; var ax:Number = x-this._x; var mc:MovieClip = this.createEmptyMovieClip("movex", this.getNextHighestDepth()); mc.onEnterFrame = function() { if (t == frames) { delete this.onEnterFrame; this.removeMovieClip(); } else { t++; this._parent._x = Cubic.easeOut(t, sx, ax, frames); } };};MovieClip.prototype.otherfunction = function(param1, param2, param3, param4){ trace(param1+" "+param2+" "+param3+" "+param4)}mc.framesTimeout(movex, 50, [100, 50]) mc.framesTimeout(otherfunction, 200, ["asd", 1, 2, 55])
Is it possible to call a function and fill in the parameters based on an array and it's lenth?
Which Function Do I Use To Find The Width/height/etc Of Objects?
Say for example that I've already set up an object with an instance name and everything, and I may change the size of it while I'm working on my project. I need the radius of the object for a certain effect I'm doing without having to manually changing it every time I change the size of the object.
What function do I use to find the width/height or whatever I would need in this case?
Function To Find Variables Data Type?
Is there a way to find a variable's data type?
I've created a QuickSort routine for an associative array. Right now it's just sorting alphabetically. I send it a 'column name' and it sorts by that 'column'. I want to find by the variable name(this is all in a class file) what that variables type is so that I can handle numbers and dates.
Function To Find Lowest Unoccupied Depth.
Ugh, I'm sorry for asking because I KNOW I've seen this function here before!!!!! I've tried so many searches though but I guess I don't know exactly what to ask... So if anyone can help me I need a function to find the lowest available depth for use in attach movies and such. And I also wanted to ask if running a function like this a lot would be too intensive to be practical. Thanks if anyone can help.
Function To Find Lowest Unoccupied Depth.
Ugh, I'm sorry for asking because I KNOW I've seen this function here before!!!!! I've tried so many searches though but I guess I don't know exactly what to ask... So if anyone can help me I need a function to find the lowest available depth for use in attach movies and such. And I also wanted to ask if running a function like this a lot would be too intensive to be practical. Thanks if anyone can help.
Filling Array - Passing Array In Function
hello
I'm trying to fill an array then pass it to a function i'm tying to do it that way
but it giving me strange results when I trace things (try it and you'll see):
Code:
////////////////// fiiling the array /////////////////
for (i=1; i<=numberof_player;i++){
pos_array = new Array(numberof_player)
pos_array [i]= i
trace("in array"+pos_array [i])
}
////////////////// pasing array in function //////////////////////
function rolldice( pos_array:Array){
trace(pos_array) /// gives 4,undefined,undefined,undefined,4
}
///////////////////////////////////////////////////////////////////
maybe i'm stupid
Thanks
T
Cosine Function To Find Angle Of Robots Arm For My Game. EASY?
Ok heres the deal...
I am making a megaman style game. I am currently making a Boss. The boss has an arm that needs to rotate to point at your charactor, to shoot his gun. Right now I have a script I wrote that gets the diference in X's for sideB of the triangle and Distant in Y's for sideC and the pathagoreon therom to get sideA. All the sides are correct.
Now for the rotation, I am finding angle A (opposite of sideA) which is the hypotinues.
The function for cosine is: A = acos(b2 + c2 - a2) / (2bc)....Heres my code. Please tell me what I did wrong for the angela. Thanks in advance.
::SCRIPT::
onClipEvent (enterFrame) {
_root.sideb = _root.pos2._x - _root.robotout._x;
_root.sidec = _root.pos2._y - _root.robotout._y;
_root.sidea = math.sqrt(_root.sideb*_root.sideb + _root.sidec*_root.sidec);
_root.anglea = Math.acos((_root.sideb*_root.sideb + _root.sidec*_root.sidec - _root.sidea*_root.sidea) / (2*_root.sideb*_root.sidec));
this._rotation = _root.anglea;
}
Can't Find Mistake In Re-write Of Draw Function. No Error Msg, Just Doesn't Work
Hey there, I am trying to convert some code into something easier to re-use without a ridicualous amount of math and excess coding. I also want to be able to tell the mc (when necessary), when this function finishes --> go do ----- ;
the code progressively draws out an outline of a shape (i.e. a square or rect)
here is the my re-write that doesn't work:
Code:
MovieClip.prototype.drawShape = function(x, y, w, h, speed, stroke, color, alpha) {
var v1:MovieClip = this;
v1.points = [ [x, y], [x+w, y], [x+w, y+h], [x, y+h] ];
v1.time = 0;
v1.style = [stroke, color, alpha];
var seg = Math.min(Math.floor(v1.time*v1.points.length), v1.points.length-1);
var nextseg = (seg<v1.points.length-1) ? seg+1 : 0;
var segtime = (v1.time-seg/v1.points.length)*v1.points.length;
v1.onEnterFrame = function() {
var v1:MovieClip = this;
// increment, test for completion
if ((v1.time += v1.speed)>=1) {
v1.time = 1;
v1.onEnterFrame = null;
// this is where i need some sort of check or to set some var, so I can perform
// other actions with the clip, such as tweening to a different location or size
}
// or start drawing
v1.clear();
v1.lineStyle.apply(v1, v1.style);
for (var i = 0; i<=seg; i++) {
if (!i) {
v1.moveTo.apply(v1, v1.points[0]);
} else {
v1.lineTo.apply(v1, v1.points[i]);
}
}
v1.lineTo(v1.points[seg][0]+(v1.points[nextseg][0]-v1.points[seg][0])*segtime, v1.points[seg][1]+(v1.points[nextseg][1]-v1.points[seg][1])*segtime);
};
};
// draw a square
this.createEmptyMovieClip('mc', 1);
mc.drawShape(50, 50, 150, 20, .02, .25, 0xFFFFFF, 100);
//mc.drawShape(x, y, w, h, speed, stroke, color, alpha);
and this was the original code i had, which worked.. i just found it a pain in the *ss to have to code in all the xpos ypos values to position the clip where i wanted. I want to be able to draw the shape within the mc, and then move it around and tween it an do whatever i need with limited frustration. I also want to be able to draw within clips that already exist.
here is the old code i tried to rewrite (i don't know where or when i got this from, i found it in my files randomly)
Code:
drawShape = function () {
// variables
var seg = Math.min(Math.floor(this.time*this.points.length), this.points.length-1);
var nextseg = (seg<this.points.length-1) ? seg+1 : 0;
var segtime = (this.time-seg/this.points.length)*this.points.length;
// increment, test for completion
if ((this.time += this.speed)>=1) {
this.time = 1;
delete this.onEnterFrame;
}
// draw
this.clear();
this.lineStyle.apply(this, this.style);
for (var i = 0; i<=seg; i++) {
if (!i) {
this.moveTo.apply(this, this.points[0]);
} else {
this.lineTo.apply(this, this.points[i]);
}
}
this.lineTo(this.points[seg][0]+(this.points[nextseg][0]-this.points[seg][0])*segtime, this.points[seg][1]+(this.points[nextseg][1]-this.points[seg][1])*segtime);
};
// draw a square
this.createEmptyMovieClip('mc', 1);
mc.time = 0;
mc.speed = .03;
mc.style = [.25, 0xE2F7D4, 100];
mc.points = [
// [x, y]
[370, 220],
[430, 220],
[430, 280],
[370, 280]
];
mc.onEnterFrame = drawShape;
what am i doing wrong?... anyone see any reason it's not working?...
any help is appreciated...
PHP Array -> Flash Array In Function
I'm retrieving an array from PHP, bringing it into Flash, converting it to a Flash array, then passing the array values to functions in order to control playback of multiple timelines.
The PHP array consists of time values in milliseconds, and mouth positions for a character's lip-synch. For example, &time1=0.015962&mouth1=eat&time2=etc...
I want my first function to extract the first array value for time and the first array value for mouth position, and pass it to another function that reads the time, does a calculation to determine how long to pause before executing the original function again, thus leaving the mouth position passed to it and moving along to the next array value.
My problem is this: how can I write the array references into the function so that it knows each time which successive array value to extract? Do I need to pass a total number of array values initially, then trade a "current value" between the two functions (time and mouth position) to make sure the array value being retrieved is correct?
Any help is appreciated,
Mike
Array Or Function?
Hi
Small problem, I hope
In my game I have 210 buttons that can be clicked on, however they can only be used once.
Is the best way to do it to use a function or an array that is called from each button?
And if anyone has an example handy, that would be much appreciated.
Thanks in advance
Array/function
How can I write an array to store the btn names and then a function that I can use to enabled=0 a set of btns when a loadMovie(); call is made. I have 10 butts that I want to disable. All with names btn1, btn2, btn3, etc
¿function Array?
Hola.
I am attempting to call my button onPress functions through an array. I am having no luck. Is it possible? Here is my script thus far:
code:
arrows = new Array("left_mc", "right_mc", "up_mc", "down_mc");
arrowFuncs = new Array("leftFunk();", "rightFunk();", "upFunk();", "downFunk();");
leftFunk = function () {
trace("this is left");
};
rightFunk = function () {
trace("this is right");
};
upFunk = function () {
trace("this is up");
};
downFunk = function () {
trace("this is down");
};
for (i=0; i<arrows.length; i++) {
btn = eval(arrows[i]);
btn.i = i;
btn.onPress = function() {
trace(arrowFuncs[this.i]);
eval(arrowFuncs[this.i]);
};
}
In this version of the script the correct function name is onPress traced, but the trace inside the called funtion is not.... that might not make much sense. Let me know if this is gibberish... or if you have an answer, comment, rude spiteful attack, link to the full version of the Rubber Johnny vid or whatever you come up with.
Thanks in advance,
1M.
ARRAY : Function
Hello!
A quick one this morning!
I have many textfields that contain prices.
I need to convert them to US currency when a button is clicked...
A made an array of my feilds:
Quote:
var itemPrice = new Array();
itemPrice[0] = a0_prix_txt;
itemPrice[1] = a1_prix_txt;
My function:
Quote:
function us() {
itemPrice[0].text = (itemPrice[0].text)*0.897737;
itemPrice[1].text = (itemPrice[1].text)*0.897737;
}
Obviously, I have undreds of items... Is there a way I could build a function that would be applied to all the items in my array at the same time without having to write every item as a line in my function?
Exemple
Quote:
function us() {
itemPrice[ALL ITEMS].text = (itemPrice[0].text)*0.897737;
}
Thanks in advance!
Marc
Montréal, CANADA
Array And Function Help
Greetings - I need array help. I have a page with the potential for 56 distinct buttons that would each load unique external content. While all 56 may never be used, I want an array that contains placeholders for all of them so any could be put into play. There are a number of lines of code that would apply to any button clicked. So I'm looking for the efficient way to apply that code to any active button.
For simplicity sake, a sample array is below and the code that would apply to any button. Each button also has code for loading unique content.
Code:
var navButton:Array = new Array();
navButton[0] = "btnOne";
navButton[1] = "btnTwo";
navButton[2] = "btnThree";
navButton[3] = "btnFour";
navButton[4] = "btnFive";
navButton[5] = "btnSix";
navButton[6] = "btnSeven";
navButton[7] = "btnEight";
navButton[8] = "btnNine";
navButton[9] = "btnTen";
//code below applies to any button.
//button fade functions
function fFadeUp() {
this.onEnterFrame = function() {
this._alpha<100 ? this._alpha += 10 : this.onEnterFrame = "";
}
}
function fFadeDown() {
this.onEnterFrame = function() {
(this._alpha>0 && this.bSelected==false) ? this._alpha -= 10 : this.onEnterFrame = "";
}
}
/*button 1 with code applied individually that I think can be turned into
functions for reuse by all buttons. My first attempt at that failed.*/
btnOne._alpha = 0;
btnOne.bSelected = false
btnOne.onRollOver = fFadeUp;
btnOne.onRollOut = fFadeDown;
/* more code that probably can be written differently to be used by each
button*/
btnOne.onRelease = function() {
this.bSelected = true;
this.enabled = false;
pastBtn.enabled = true;
pastBtn._alpha = 15;
pastBtn.bSelected = false;
pastBtn = this;
container_mc.loadMovie("movOne.swf"); //this will change for each button
}
Thank you for your continued help.
|