Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




Finding A Random Position Outside Of An Defined Area?



Hey guys, I could use a little help with some math.
Basically I am trying to find a random position to place a movieclip outside of my stage, but within a certain bounds.

I want it to be so the position is completely random and can have either a positive or negative value, and of course it must be a position with either the x or y out side of the stage, so that the movieclip is completely off stage, but inside the outter bounds.
I've tried to hack around, but could not think of a very clean solution that retained complete randomness within the defined area.

I also do not want to have to run a loop until I randomly come up with a set of points where atleast one of the dimension is outside the stage.

any help is much appreciated.



FlashKit > Flash Help > Flash ActionScript
Posted on: 09-18-2007, 06:37 AM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

Random Movement In Defined Area
I want to have about 15 verticle lines moving randomly along the X axis

Now I have modified the Kirupa random movement tutorial to this code:


ActionScript Code:
onClipEvent (load){//data you may want to change width =  300;speed =  Math.round(Math.random()*4)+1; //initial positions x =  this._x=Math.random()*width;x_new =  Math.random()*width;} onClipEvent (enterFrame)  { //x movement if (x_new>this._x)  { sign_x =  1; } else  { sign_x =  -1;} dx =  Math.abs(x_new-this._x); if ((dx>speed)  || (dx<-speed))  { this._x  += sign_x*speed; } else  { x_new =  Math.random()*width;} }


But I noticed the starting point of the verticle line is always in the same spot and is not confined to where I want it positioned....How would I define an exact stage for it be contained in?

Also it goes everywhere on the stage just not what is defined as the width in the begining of the code,



-Case

Random Movement In Defined Area
I want to have about 15 verticle lines moving randomly along the X axis

Now I have modified the Kirupa random movement tutorial to this code:


ActionScript Code:
onClipEvent (load){//data you may want to change width =  300;speed =  Math.round(Math.random()*4)+1; //initial positions x =  this._x=Math.random()*width;x_new =  Math.random()*width;} onClipEvent (enterFrame)  { //x movement if (x_new>this._x)  { sign_x =  1; } else  { sign_x =  -1;} dx =  Math.abs(x_new-this._x); if ((dx>speed)  || (dx<-speed))  { this._x  += sign_x*speed; } else  { x_new =  Math.random()*width;} }


But I noticed the starting point of the verticle line is always in the same spot and is not confined to where I want it positioned....How would I define an exact stage for it be contained in?

Also it goes everywhere on the stage just not what is defined as the width in the begining of the code,



-Case

Random Movieclip @ A Random Partly Defined Position
Ok I´ve searched this forum to death but i didn´t REALLY
find the answer to my question! I think it can´t be that
difficult but i´m new to action-script and so i gotta hope
u´ll know the answer :

I´ve got an movie. (uh yeah ^^) in this movie there are
many movieclips that contain animations. now i want these
mcs to appear randomly @ a random position of a few defined
positions.

I really got NO idea how to do this !*prayinforyahelp*

ok thx 8]

RANDOM Position, Within A Specified Area
I've tried to position 9 MCs on the stage randomly using this code on each MC:


Code:
onClipEvent (load) {
origY = this._y;
this._y = Math.random()*250;
}
This works fine, but i want to create restrictions so that the MCs fall within specific constraints, ie a certain height from the top and bottom of the screen.

Eventually once i get this code to work i would also like to make sure that when they are positioned on the stage there is no overlapping.

Each MC has been exported with AS linkage by calling it word1, word2, word3, etc... all the way up to word 9. so i am aware of the fact that i can use a for loop but sure how to get it working.

SOooooooo.... can anyone help me

1)randomly position MCs but with constraints?
2) prevent them from overlapping?

Oh and one more thing.... they must only be positioned along the y axis because i have already placed them on the stage & they are PERFECTLY aligned along the X axis!!

PLEASE HELP ME!!

Random Position Within A Fixed Area
Hi all,

I need to set the _x and _y properties of a movie clip which is in the form of a speech bubble randomly.

This I do using the script:


Code:
setProperty ("bubble", _x, random (375 - 145 + 1) + 145);
setProperty ("bubble", _y, random (225 - 75 + 1) + 75);
The dimension of the stage is 550 x 375

However how do I make sure that the movie clips edges DO NOT overlap or go beyond a frame which is 420 x 290 pixels.

A detailed explanation is appreciated...commented if possible

Thank you

Duplicate Movies In Defined Area
Hi all,

I am wanting to duplicate the same movie or image in a defined area on the screen. I am populating a Map of the US randomly with dots that are an attempt to display cities popping up all over the map.

Any ideas on how to do this easily? Everything I have tried thus far has been a bit messy.

Thanks in advance!

Printing A Defined Area In Flash
Hi,

I have an area on the left hand side of my page that i would like to print. ONLY this part as the stuff on the right would just be a waste of ink. Is there a way in flash to make a button within flash that when pressed will print out my defined area??

Thanks in advance

Movie Clip In Defined Area?
Hey Ya'll,

I'm creating a whole page in flash, pretty typical, but I want to include a slideshow in the lower portion of the larger file. I figured a movie clip is the easiest way to do this, but how can I define the size of the canvas for the movie clip? I don't want it to take over my entire canvas while it's playing, or else it won't look cohesive.

The site, in it's beta version is at www.miamiphidelt.com/beta.html. Check it out, the "slideshow" would go below the bottom blue line.

Thanks for your help in advance,

=Nate

Trigger From Click In A Defined Area?
Is it possible to use actionscript to say
if mouse up in x10, y10,x100,y100 do this

sort of like how you define a drag area, I want to register a click in a certain area without having a button there

thanks
mark

Can I Load And External Url Into A Pre-defined Area Of My Movie?
can i load and external url into a pre-defined area of my movie?
I don't want to use a frameset. I want the site to be all flash.
So, instead of loading another site into a frame, I want to load it (via a button click) into an area that i can define the x and y, alpha, etc.
the site is http://www.laffinsdesign.com/lead3 and I want the sites to open up where the book is instead of popping up wherever.
Thanks, RJ.

Constraining Movement To A Defined Area On The Stage
Hello,

I am making an interactive promo for a college brief and included into that I wanted to have a game of space invaders.

I have downloaded the source file from Neave who very kindly offers it (http://www.neave.com/games/invaders/) which I will attach, in the hope to modify it.

I have a basic understanding of actionscript but what I'm not how to do is constrain the game within a defined area on the stage (i.e I want it to appear within a console window.

I'm sure this is going to be the first of many problems but any help is much appreciated!

Thanks

Display Movie When You Click In A Defined Area
i'm writing to see if anyone can advise on this objective....


i basickly want to create something where if i click on a piece of art, a small color pallete appears where ever mouse is.....and when i click on a color in the pallete the piece of art changes to that color......


make sense?

i already know some parts of this, i just dont know how to get the pallete to appear on clivk where the mouse cursor is......i know i can create a tell target area......which will define the area right? but how do i get the mouse to bring the pallete up.....at a specific area.....

Loading External Htm Files Into A Defined Area
I'm wondering if it's ppssible to load rather lengthy external htm pages into a defined area of a Flash site... Basically, I need to see if I can have large htm files load within a small space embedded within a Flash site at the click of a button. As it is now, the htm pages come up in a separate browser, but if I can contain it all, that'll be ideal.

I have preceise text formatting in the htm pages, so if it's possible to load these, that's what I'm curious about.

Any ideas? Thanks.

Loading An HTML Page Into A Defined Area In Flash?
any way to load an html file into a flash movie so that it will display in a defined area (like using a dynamic text field or something as an area where the page will show?) I've got a whole website im converting into flash and I tried redoingt the pages to Flash's LIMITED HTML... Not happening...

Thanks,

-Avenger

Finding Max Y Of MC In Certain Area
Is there any way to Find the max y of a Mc in a certain area? Such as the max y of a mc where another mc hits it?

Slowdown Script With Defined End Position
Code:
onClipEvent(load) {
this._x = 100;
endPosx = 250;
}
onClipEvent(enterFrame) {
movex = (endPosx - this._x)/2;
this._x += movex;
}
I like this action... it moves an mc with a speed that decreases till it stops. So, it slows down.

Question: Does somebody know how i can define an endPosx so that the mc als ends on that position

In the action i gave, endPosx is set as 250, but the mc doenst really end at xposition 250

Greetz
Bouga

Enlarge From Undefined To Defined Position
Is it possible to have a movie of a small ball for example which moves around the screen. Then, when a button is pressed, it tweens from its position at the point the button was clicked to an enlarged state which is predefined, say 200% larger at a position of x200, y100?

I guess you'd need to 'capture' the x, y, coordinates and size of the small ball somehow and say something like 'when this button is clicked, go from the captured x, y, to my defined x, y?? Is that right?

Thanks

Hittest -- Drag To Defined Y Position
Hi ,


i got 4 movie's on main (category0_mc, category1_mc, category2_mc and category3_mc) the _y position of these 4 movie's is variable.....

i want it so that when i start drag "categorie0_mc" you only can drag to (category1_mc, category2_mc and category3_mc) and when release "categorie0_mc" change _y position with the other categorie movie

i searched and find some things, but not usefull for me..

if somebody could point me to a tutorial or give a hint :d

thanks

Swap Cursor And Go To Defined X And Y Position
Deh! This was harder than I thought (or could it be my lack of knowledge in AS ) Anyhow, problem: I want my cursor to swap with a costum cursor, go to an defined x and y position from its original position (maby wait a sec.. if possible) an then go back to where ever my original cursor position may be. Did I get that right haha. A sample is in the begining of this http://www.istanbulmodern.org/en/f_index.html

I posted a fla with cursor and position. I really hope someone out there could help me (screaming from th bottom of a swedih well, and they're deep)

Thanks on forehand

Hittest -- Drag To Defined Y Position
Hi ,


i got 4 movie's on main (category0_mc, category1_mc, category2_mc and category3_mc) the _y position of these 4 movie's is variable.....

i want it so that when i start drag "categorie0_mc" you only can drag to (category1_mc, category2_mc and category3_mc) and when release "categorie0_mc" change _y position with the other categorie movie

i searched and find some things, but not usefull for me..

if somebody could point me to a tutorial or give a hint :d

thanks

Finding Objects Within Area
Hey guys,

I need a method of finding all the objects over the top of another object...

I realise I could use hitTest to check if something is intersecting, but I can't use it to find the names of the said objects.
I also realise I could just cycle through all the objects on the stage and calculate it that way, but considering there's over 300 objects that could 'possibly' be covering this particular object, thats a lot to calculate, and i'd like it to be snappy...

Any ideas? Is there something already avaliable that i've been missing?

Cheers in advance for your help...

Geometry: Finding Area Of Triangle
I'm trying to find the area of a triangle given the lengths of the sides; I'm using Heron's formula, which is:

To get the half perimeter first:
s = (a+b+c)/2 -where a, b, c are the lengths of the sides

Then to get the area:
"Then you multiply this number (s) by three other numbers - the semi-
perimeter minus each of the three sides in turn - and take the square
root of the result" --from Dr.Math

A = sqrt(s(s-a)(s-b)(s-c))

But how would you express this formula into actionscript??? I've got something working, see below, but I believe I'm getting the wrong answer, it comes out too low.

Here's what I have so far:


Code:
var a:Number = Math.sqrt(Math.pow((point1._x - point2._x), 2)+Math.pow((point1._y - point2._y), 2));
var b:Number = Math.sqrt(Math.pow((point2._x - point3._x), 2)+Math.pow((point2._y - point3._y), 2));
var z:Number = Math.sqrt(Math.pow((point3._x - point1._x), 2)+Math.pow((point3._y - point1._y), 2));

trace("a is: "+ a);
trace("b is: "+ b);
trace("z is: "+ z);

s = (a+b+z)/2; // to get the perimeter...
trace("s is: "+s);

// I know this is convoluted is hell, but I want to make sure everything is calculated
// to what I think the proper order is...
p=s-a;
q=s-b;
r=s-z;
m=s*p;
n=m*q;
o=q*r;
trace("o is: "+o);
triArea = Math.sqrt(o);
trace(triArea);
But I get a really small number at the end of this which is why I think what I've done is incorrect. Any advice? Thanks!!

Finding The Frame Position
i had made a dynimic text.

on entering into the movie i want the framenumbers to be displayed in the dynimic text area.

for example

if the frame is playing the frame 5 then in the text area it should be displayed as "5/120" (120-the total number of frames.)

on every frame move the frame number should displayed dynamicaly.


help me out in this

from
aristotle

Finding The Array Position Of A Value
I have defined an array as follows:

listRA[0] = "first";
listRA[1] = "second";
listRA[2] = "third";

daValue = "second";

Is there any way to determine which member of listRA == daValue? Or do I have to search it out with a For loop?

I haven't found anything else, and I know other languages have functions to discover the value.

Thanks,
Paul

Finding Cursor Scroll Position
whats the easiest way to find the current cursor position of a text box? i know there is TextField.bottomScroll etc..

i have a text box which autosize is set to true (so it expands as more text is typed). When the user uses the arrow key to go back up the text, i'd like to find the current line number it is on.

Any ideas,

Thank you,

DD

Finding The Position Of An Array Index
i was wondering if you have an array value, can you find what number it is in the array's order. For example,

letters=new Array("a","b","c","d");
cnumber=letters.position["c"]
trace(cnumber);

so that cnumber=2. How would I go about doing something like this?

-Brendan

Help Finding Line Position Of Character
I have a flash app that cycles through different paragraphs of a text field and selects them. To find the paragraphs I find the character position of the first and last characters within the field. What I'm wondering is if there is a way to find out what line number a particular character in a text field is on so that I can adjust the text field to automatically set a scroll position to a line with that first character. Currently as I select pargraphs in my text field, the selected text goes beyond the viewable area of the text field.

If you want an example take a page or so of text with paragraph pages and paste it into the big text frame on this page. Once you hit "commit" it will find the paragraphs and you can use Next and Prev to scroll through them. (its a very rough alpha version utility to generate XML)

Any help is appreciated!

Finding Out Position Of Elements In An Array?
Hi,
a short question, how do you find out in which position a certain value is in an array?

thanks in advance,
polar

Help Finding Line Position Of Character
I have a flash app that cycles through different paragraphs of a text field and selects them. To find the paragraphs I find the character position of the first and last characters within the field. What I'm wondering is if there is a way to find out what line number a particular character in a text field is on so that I can adjust the text field to automatically set a scroll position to a line with that first character. Currently as I select pargraphs in my text field, the selected text goes beyond the viewable area of the text field.

If you want an example take a page or so of text with paragraph pages and paste it into the big text frame on this page. Once you hit "commit" it will find the paragraphs and you can use Next and Prev to scroll through them. (its a very rough alpha version utility to generate XML)

Any help is appreciated!

Finding An Objects _x And _y According To Its Position On Stage
Hey I was wondering if anyone knows how to find a target objects _x and _y value according to the stage... while that object is located within another movie...

i've tried something similar to this


Code:
with(_root){trace(this._x)}
but it doesn't seem to work...

Exact Position Finding Method
Hmm.. ok this is pretty basic but I have bean wondering for some time and was afraid to ask...

How could I find the exact position for a attachMovie that should align with the background?

and does these positions sometime change when published? I mean I have to consider somekinda html and/or java config when publishing......right?

Finding Position Of Text In A Textfield
If I want to position a movieclip symbol behind a word in a textfield, how do I do it? I mean if the text in the textfield changes fonts/or sizes and the text reflows, I need the movieclip to be positioned behind the word/words regardless of where the words fall.

Is this possible?

Any advice or help would be greatly appreciated.

Jase

Finding POSITION In Array - Not Just Boolean
I'm trying to find the possition of an elemtent within an array.

I'm currently work around this. It a button attatched in relation to the amount of items in an xml file:

this.onRelease = function() {

for (var k=0; k<array_length; k++){

checkARRAY = (_root.Nav_array[k])

//search through the array and get the possition of the currently clicked item

if(checkARRAY=this){

number_in_array.text = k

}else {

trace("not found")

}
}
}

What i'm trying to do is tell find the position of the currently selected item in the array so i can move the _y value of the items infront of it. Its a menu - all the other items would move down once i clicked the top item. I'm trying to make it all dynamic [from XML] so i can't refer to the items in the array without looping through it [i think].

If anyones got any ideas - it would be awesome!!

User Defined Random Amount
i want to have an input amount that a user can put it to define how much random there is.

Code:
on (release){
var i:Number = Math.ceil(Math.random()*//i want this to be whatever the user enters in the input box\);
gotoAndStop(i);
}
any help would be appreciated

Grid With Random Defined Rotation
Hey,

I have made a grid that loads great but I want to add a little flavor by having two events occur:

I want the grid boxes (all duplicates of an mc named "sq") to rotate either 90, 180, 270 or 360 degrees. The thing is I have written a script to make them rotate 90 degrees with each new duplicate but I realized that doesn't look as good as what I'm going for. That code is here:


Code:
gridx = 31;
gridy = 31;
num = 0;
for (var i = 0; i<20; i++) {
for (var j = 0; j<8; j++) {
sq.duplicateMovieClip("sq"+num, num);
mc = this["sq"+num];
setProperty("mc", _rotation, n);
n = n+90;
mc._x = gridx*i;
mc._y = gridy*j+130;
num++;
}
}
I am trying to get them to randomly change their _rotation to one of the four numbers. I tried an array but got confused how to apply it to a property and gave up.

Ok, that's effect one. The second is that when they get duplicated into the grid, if there was a way to make them duplicate out of order and one after another (instead of duplicating all at one time). I looked at some setinterval stuff but nothing seemed to be directed to what I was looking for.

Any help is greatly appreciated!

Grid With Random Defined Rotation
Hey,

I have made a grid that loads great but I want to add a little flavor by having two events occur:

I want the grid boxes (all duplicates of an mc named "sq") to rotate either 90, 180, 270 or 360 degrees. The thing is I have written a script to make them rotate 90 degrees with each new duplicate but I realized that doesn't look as good as what I'm going for. That code is here:


Code:
gridx = 31;
gridy = 31;
num = 0;
for (var i = 0; i<20; i++) {
for (var j = 0; j<8; j++) {
sq.duplicateMovieClip("sq"+num, num);
mc = this["sq"+num];
setProperty("mc", _rotation, n);
n = n+90;
mc._x = gridx*i;
mc._y = gridy*j+130;
num++;
}
}
I am trying to get them to randomly change their _rotation to one of the four numbers. I tried an array but got confused how to apply it to a property and gave up.

Ok, that's effect one. The second is that when they get duplicated into the grid, if there was a way to make them duplicate out of order and one after another (instead of duplicating all at one time). I looked at some setinterval stuff but nothing seemed to be directed to what I was looking for.

Any help is greatly appreciated!

Finding Position Of Line Wrap In TextField
I'm using Flash MX 2004 Professional.

I have a multiline word-wrapped TextField of fixed font type and size (varying BOLD/ITALICS attributes) and all other formats set to default.

I need to find out the position in the text where the lines wrap, i.e. where a long sentence goes to the next line in the display. The _width and _height of this TextField is dynamic, so I require a fast and efficient method to doing this.

Currently, I precalculate the width of each character (bold and not bold) for the font and size I use. Then accumulate the width of the string til the width of the TextField is reached, then assume the line wraps at the start of the current word.

This method isn't very accurate somehow... my calculations tend to be different by one or two characters sometimes. I know its the rules of line wrapping that I'm guessing at, thats causing the discrepencies... wonder how we can very accurately determine how the lines wrap? (many special cases like "-", spaces, super long words etc...)

Anyone knows of better ways to do this? Very much appreciated.

Finding Index Or Position Of Certain Attributes In Xml File?
Hi,

I've been getting to grips with xml and as3 but cant figure this out....

If I retrieve the value in a node from the number of the node, how do i then find the number of the node from the value. (confused?)

this is my code:


Code:

var hx:XML =
<hmv>
<level> <area> Music </area>
<subject> <area> Radio </area>
<content>Live Stream </content>
<content>Archive</content>
</subject>

<subject> <area> Library </area>
<content>Brian Ferry</content>
<content>Harvey GoldSmith</content>
<content>The Levellers</content>
<content>The Kooks</content>
<content>SugaBabes</content>
<content>Take That</content>
</subject>
</level>
</hmv>

trace(hx.level[0].child("area"));

var neededVal:String = hx.level[0].child("area");

///// this gives me the result "Music"


How do i then get the number 0 back from putting in the name Music?

should be relatively simple, i'm sure i just haven't been able to find this explained in any tutorials and its quite a difficult subject to search for.

any help greatly appreciated,

thanks

Finding Y Position Of Dynamic Text Field...
Hi all,

I need some help with my flash, i'm making a simple movie that display testimonial quotes randomly into a dynamic text field.

basically each quote is place into an array, the dynamic text field then reads a random quote each time it it loaded.

I have a separate MC, bottom_mc, that i need to be placed below the last line of text(loaded from array), if i could find out the Y position for the last line (make sense)

is it possible to find out the Y position of the text field (bottom corner), then i can simple put

onClipEnterFrame {
bottom_mc._y = position of last line/bottom corner
}

I've attached my flash file to take a look. is it possible to count the number of characters in a dynamic text field? then i could roughly work out how many line the quote would be on...??

cheers, any help or point in right direction is cool. sorry if it don't make much sense, but if you take a look at the zip it may help explain.

will

Finding Numerical Position Of Items In An Array
What i want to do is to populate a text field with the numerical position of an item in an array. Here's what I've got so far:

an array- call it bArray - which holds references to three button mc's:
ActionScript Code:
bArray=new Array[btn1, btn2, btn3]



Then I have a for loop which feeds a variable that numbers each button, and includes rollOver and rollOff functions:
ActionScript Code:
for(var i=0; i<bArray.length; i++){
pos=i+1;
//numberText is a text field in the btn movie clip.
bArray[i].numberText.text=pos;
[i]//bPos=bArray
bArray[i].onRollOver=rollOverButton;
bArray[i].onRollOut=rollOutButton;
}



Okay, not a problem. But now what I want is this- when you click a button, a text field in another movie clip displays the number of the button just clicked. And I can't figure out how to derive that value from the array.

Anyone have any helpful clues?

[F8] Mouse Position / Area
Hi All

Please can you help? I've done it before but forgot how and can't find anything! I would like a piece of script that say when the mouse is in a certain area to do something. Like rolling over a button but not on a button... so I can have for example, an animation play when the mouse is in a particular area on the stage.

Thanks in advance!

Freezing Mouse Position Outside Of Hit Area
This script causes the slider MC to follow my mouse when its in the hitTest area named vertMC. It works but when you exit the hit area I want the mouse to stay where it was right before you exited. So I just want it to freeze until you enter the hitTest area again, then it shoudl pick up where it left off.
heres the script:


stop();
if (vertMC.hitTest(_root._xmouse, _root._ymouse, true)) {
slider.onEnterFrame = function() {
var yMouse = _root._ymouse;
if(Math.abs(xMouse - this._x) < 1) {
this._y = yMouse;
} else {
this._y -= (this._y-yMouse) / 4;
}
}
} else {
slider.onEnterFrame = function() {


}
}

[F8] Random Load Finding A No Existent File
I'm using this code to load a choice of 5 random images and text:

function loadRandom(clipname)
{
choice = Math.round(Math.random()*5);
switch (choice) {
case 1 :
clipname.loadMovie("images/icon01.jpg");
iconQuote.quote = "<html>text1</html>";

break;
case 2 :
clipname.loadMovie("images/icon02.jpg");
iconQuote.quote = "<html>text2</html>";

break;
case 3 :
clipname.loadMovie("images/icon03.jpg");
iconQuote.quote = "<html>text3</html>";

break;
case 4 :
clipname.loadMovie("images/icon04.jpg");
iconQuote.quote = "<html>text4</html>";

break;
case 5 :
clipname.loadMovie("images/icon05.jpg");
iconQuote.quote = "<html>text5</html>";

break;

}
}

it works fine until it tries to load an image and text that is not there. (returns a blank). Is there something wrong with the maths!

cheers
Rat

Stage Position In Flash Working Area
I've been working with a movie here at work for a while now. I took it home on the weekend to do some more work on it, and now, back at work, the Stage is aligned all the way to the top-left for the (stupidly limited) Flash working area.

I had some linked items on a Guide layer that were to the left of the Stage, and I can't get at them at all now - not even when I click on their keyframe in the Timeline and manually move them with the cursor keys!

How can I center the Stage in the Flash working area again?? How did this happen??

Constraining Relative Mouse Position Action To Area
I've scoured several places online for an answer to this, but I only find posts asking the same question without any answers. I would appreciate any guidance on this.

I've successfully implemented a looping MC slider (w/ buttons) that eases horizontally according to mouse position. The problem is, I can't get the slider to stop moving when the mouse is outside of the slider MC area. My slider MC is loaded into a layer above my main movie, and I would like to retain the functionality of the links on the main timeline without the distraction of the moving horizontal slider. In any event, I can't even find a way to constrain the relative mouse action at all.

Here is the basic AS I am using:

Code:
panel.onRollOver = panelOver;

function panelOver() {
this.onEnterFrame = scrollPanel;
delete this.onRollOver;
}

var b = stroke.getBounds(_root);

function scrollPanel() {
if(_xmouse<b.xMin || _xmouse>b.xMax || _ymouse<b.yMin || _ymouse>b.yMax) {
this.onRollOver = panelOver;
delete this.onEnterFrame;
}

if(panel._x >= -121) {
panel._x = -1825;
}

if(panel._x <= -1847) {
panel._x = -140;
}

var xdist = _xmouse - 250;

panel._x += Math.round(-xdist / 10);
}

Finding The "coords" (x,y) Position Of An Item In A Multidimensional Array
Is there a relatively easy way of finding the x,y position of an item in a multidimensional grid array?

I have this grid structure for drawing a map for a game. Number 2 is going to be the starting point of the player. How would i find the x,y position of that number in the array?

It's currently at 2,2 within the array.. but i want it to be dynamic.


ActionScript Code:
map[0]  = new Array(1,1,1,1,1,1,1,1,1,1)    map[1]  = new Array(1,0,0,0,0,1,0,0,0,1)    map[2]  = new Array(1,0,2,0,1,0,0,0,1,1)    map[3]  = new Array(1,0,0,1,1,1,0,1,1,1)    map[4]  = new Array(1,0,0,0,1,0,0,0,1,1)    map[5]  = new Array(1,0,0,0,0,0,0,0,0,1)    map[6]  = new Array(1,1,1,1,0,1,1,1,1,1)    map[7]  = new Array(1,0,0,0,0,0,0,0,0,1)    map[8]  = new Array(1,0,0,0,0,0,0,0,0,1)    map[9]  = new Array(1,1,1,1,1,1,1,1,0,1)


This is the code i have to draw the map.


ActionScript Code:
function drawIt(theMap) {    var pos = 0;    diameter = 72;    xOffset = 20;    yOffset = 15;    for (var y = 0; y<diameter; y++) {        for (var x = 0; x<diameter; x++) {            pos = x+(y*diameter);            if (theMap[y][x] == 0) {                _root.attachMovie("myTile2", "tile_"+pos, pos, {_x:x*diameter+xOffset, _y:y*diameter+yOffset});            } else if (theMap[y][x] == 1) {                _root.attachMovie("myTile", "tile_"+pos, pos, {_x:x*diameter+xOffset, _y:y*diameter+yOffset});            } else if (theMap[y][x] == 2) {                _root.attachMovie("sprite", "sprite", 2, {_x:x*diameter+xOffset+35, _y:y*diameter+yOffset+35});            }        }    }}

[CS4 AS2] Random X And Y, Within A Certain Area
Hey peoples
Im looking for some help with my actionscript. Ive just recently been trying out some stuff and I currently have an image spawning at a random location on stage and changing to a random position every 2 seconds or so.

Now because my registration point is set to the middle it sometimes goes to a position where i cant see the top,left etc of the image. Now i want to restrict the x and y values of my random x-y so it always shows the whole image.

My random code now pretty much looks like this. This code sits within a function with a timer etc that all works well its just about restricting it atm

Code:
stagewidth=550;
stageheight=400;
image._x = Math.random()*stagewidth;
image._y = Math.random()*stageheight;


Now i want to like say restrict my random x and y of my image to be for example say x between 40-500 and my y values between 30-380.

Im kind of clueless here being new to actionscript. Any help much appreciated.

Greetings Jinx

Finding Global "_y"position Of A Nested MC
Hi all,

I have an MC "a1" that I'm duplicating and arraying downward a variable number of times ("numb"). The MC is inside a parent MC ("little") which is inside the MC ("big"). My problem is how to determine the Y position on the screen of the last or lowest duplicated MC (in the example: a22). The code below shows its y position relative to its parent MC. Is LocalToGlobal the way to go?

numb=22;
ypos=eval("_root.big.little.a"+numb);
lowest=(getProperty (ypos, _y ));

thanks in advance

Copyright © 2005-08 www.BigResource.com, All rights reserved