Detect HitTest With Name From An Array
Hi there!
I'm stuck in my programming, i.e. I'm trying to create a little game with a movable shooter and bandits/aliens that slowly moves towards the shooter (like the old arcade game). Well, my question is how I can detect a hit (hitTarget) between the shots and the bandits. The bandits are created and named in a for loop: _root.bandit.duplicateMovieClip("int_bandit"+ i, i);
In the loop I have created an array where I put the variable i which is a number based on the same variable that is in the for loop --> for (i=0; i<2; i++).
From the shot MovieClip I want to detect the hit and have tried something like:
if (hitTest(_root["int_bandit"+ _root.my_array[i]])) { trace("HIT"); } where the idea is to add any number from the array to the MovieClip name "int_bandit", with the outcome of, for example, "int_bandit0".
What am I missing?
Thanks
//MickeJa
FlashKit > Flash Help > Flash ActionScript
Posted on: 02-21-2002, 09:40 AM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Need HitTest To Detect Non-Hit
I've been slowly working away on my first AS3 game in my free time and I've been attempting to add event listeners to the game that detect whether a movieclip is overlapping another or not overlapping --and I'm totally stuck. The hitTestObject is not properly detecting when it's not hitting a box.
I'm attempting something similar to Mazoonist's example posted on THIS THREAD. (on the 2nd page)
Here's the code, which lives in a document class (or download the source HERE)
ActionScript Code:
package
{
import flash.display.MovieClip;
import flash.events.*;
import flash.ui.Keyboard;
import flash.events.KeyboardEvent;
public class Example2 extends MovieClip
{
private var xpower:Number = 5;
private var ypower:Number = 5;
private var rightArrow:Boolean;
private var leftArrow:Boolean;
private var upArrow:Boolean;
private var downArrow:Boolean;
public function Example2()
{
init();
}
public function init()
{
stage.addEventListener(Event.ENTER_FRAME, moveBall);
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
stage.addEventListener(KeyboardEvent.KEY_UP, keyReleased);
}
private function moveBall(event:Event)
{
////////////Key Movement
if (rightArrow) {
ball.x += xpower;
}
if (leftArrow) {
ball.x -= xpower;
}
if (upArrow) {
ball.y -= ypower;
}
if (downArrow) {
ball.y += ypower;
}
////////////Energy Box Hit
var i:int = 0;
for (i = 0; i < 3; i++){
var energyMc = energyHits["hit_mc"+i];
if(ball.energyDetect.hitTestObject(energyMc))
{
trace("overlapping");
stage.removeEventListener(Event.ENTER_FRAME, moveBallNoHit);
stage.addEventListener(Event.ENTER_FRAME, moveBall);
}
}
}
private function moveBallNoHit(event:Event)
{
////////////Key Movement
if (rightArrow) {
ball.x += xpower;
}
if (leftArrow) {
ball.x -= xpower;
}
if (upArrow) {
ball.y -= ypower;
}
if (downArrow) {
ball.y += ypower;
}
////////////Energy Box Hit
var i:int = 0;
for (i = 0; i < 3; i++){
var energyMc = energyHits["hit_mc"+i];
if(!ball.energyDetect.hitTestObject(energyMc))
{
trace("not overlapping");
stage.removeEventListener(Event.ENTER_FRAME, moveBall);
stage.addEventListener(Event.ENTER_FRAME, moveBallNoHit);
}
}
}
/////////////////////////////Keyboard Events
public function keyPressed(event:KeyboardEvent) {
if(event.keyCode == Keyboard.RIGHT) {
rightArrow = true;
}
if(event.keyCode == Keyboard.LEFT) {
leftArrow = true;
}
if(event.keyCode == Keyboard.UP) {
upArrow = true;
}
if(event.keyCode == Keyboard.DOWN) {
downArrow = true;
}
}
public function keyReleased(event:KeyboardEvent) {
if(event.keyCode == Keyboard.RIGHT) {
rightArrow = false;
}
if(event.keyCode == Keyboard.LEFT) {
leftArrow = false;
}
if(event.keyCode == Keyboard.UP) {
upArrow = false;
}
if(event.keyCode == Keyboard.DOWN) {
downArrow = false;
}
}
}
}
I've also tried putting the hit and non-hit if statements in the same function--the result is when the ball hits the box, it recognizes the hit 1 time and then goes back to thinking it's not hitting.
Any help would be so greatly appreciated!
Detect A HitTest On Movies With No Name
Is there any way to detect a hitTest within two movies that don't have their own name. i.e. if this.hitTest(another movie)
don't ask why it has to be this way...it just does
Detect HitTest But At Which Level?
I have a "dress the doll" file where i put all the clothes on one layer. When i publish the file, the hitTest goes into effect on the bottom layer instead of the top layer. So picture this, a row of shirts that are slightlly layered. When i click on the one on the top and drag it, it drags the one below it becuse they are over lapping. How do i make a more advanced hitTest that takes that into consideration?
Help Using Hittest Shapeflag To Detect A Moving MC
Hi! There:
I am trying to detect collision of 2 MCs using hittest.
However, one of the MC has an irregular shape and is moving. I know I can use shapeflag to specify a (x,y) point, however what should I do if the MC is changing its position al the time?
There are two MCs here, ball and paddle
I put all the script in the MC ball's on ClipEvent
onClipEvent (load) {
startDrag ("", true);
}
onClipEvent (enterFrame) {
if (this, hittest(_root.paddle._x+15, _root.paddle._y+23, true)) {
setProperty ("", _width, "150");
} else {
setProperty ("", _width, "100");
}
}
This works if the MC stays still, and assume the (x.y) is the center of the image, how should I modify the code so that (x,y) will stay relevant with the moving paddle?
Truly appreciate if anyone can shed some light on this for me.
^_^
Thanks,
Sasa
Detect HitTest..without Movie Clip?
Is it possible to check if a define _x/_y of a mc is touching the defined _x/_y of another mc?
Basically, here is what I want to do. I have AI computers, and I want them to jump, if there is a higher platform in front of them. but i dont want to create an mc in front and back of them to trigger when it hits a platform, because that would stretch the comp mc's area, and I just want to keep it as it is. i realize i could create mcs through actionscript on the _root that follow the mc, however I know there must be a better way to do this...
HitTest Detect Random Duplicated Instance
I've got this code on my frame:
if (_root.count <= 20) {
duplicateMovieClip("_root.clip", "clip"+_root.count, _root.count);
_root["clip"+_root.count]._x = random(500)+50;
_root["clip"+_root.count]._y = random(1)+20;
}
And I need to figure out how to have the hitTest see the randomly generated instances of this duplicated mc.
I can get the hitTest to see the first instance (called "clip"), but then it doesn't see all the rest.
Here's the code I have on the hitTestMC:
onClipEvent (enterFrame) {
if (_root.chime1, hitTest(_root.clip)) {
_root.chime1.gotoAndPlay("play1");
}
}
thanks for looking
Detect Array?
Pardon my idiocy, but there aren't many code examples dealing with detecting arrays in actionscript. Is this proper syntax for detecting whether a variable doesn't exist and that it's not an array?
if ((!attributes) || (attributes.length != "")) {
code
}
How To Detect Multiple Same Items In An Array..
hello, first time here.. want to ask a question which i have been thinking for quite sometime ..
say i have an array be it of any length ..
var Myarray= new array("apple", "pear", "apple","orange", "apple","pear" )
how shld i write a function that will detect and group similar items into each individual unqiue counter,
item "apple" :3
item "pear" : 2
item "orange":1
also does anyone here have resources(books or website) for problem solving for actionscript.. problems like the one on top.. ? I really need to learn to improve in different approaches in solving a scripting problem.
Cant Detect A Click On Buttons In An Array
Ive got a problem with a hittest that isnt working.
Here is a link to my FLA.
Im testing a hit on a button added dynamicaly. I can access the mc's properties but my hittest wont work.
First this is where I add the buttons and store the linkages in an array:
ActionScript Code:
MenuWheelClass.prototype.MenuWheel_MakeButtons = function() {
for(var i=0;i<this.NumBttns;i++){
//Add the buttons
this.mc = new Object;
this.mc = this._clip.attachMovie(this.BttnClips[i],"Bttn" + (i+1), i+2);
this.mc._x = Math.cos(Math.PI/180*(this.BttnPositions[i]-90))*this.BttnRadius;
this.mc._y = Math.sin(Math.PI/180*(this.BttnPositions[i]-90))*this.BttnRadius;
this.mc._rotation = this.BttnPositions[i]-90;
this.mc.onPress = this.MenuWheel_onClick;
//Add to list for further reference
this.CurButtons.push(this.mc);
}
};
and this is where the hittest is:
ActionScript Code:
MenuWheelClass.prototype.MenuWheel_MouseIsOverBttn = function ( )
{
// checks if the mouse is over any of the items
// reset the current item just in case the mouse is not over anything
this.CurrentBttnIndex = undefined;
// loop through all the items in the menu
for (var j = 0; j < this.CurButtons.length; j++)
{
//This works
trace("this.CurButtons[j]._name = " + this.CurButtons[j]._name);
//and so does this
trace("this._clip.Bttn1._name = " + this._clip.Bttn1._name);
// check if the mouse is over the item
//CANT MAKE THIS HITTEST WORK!!!
if (this.CurButtons[j].hitTest(_root._xmouse, _root._ymouse, true)) {
trace("hittest " + this.CurButtons[j]._name);
this.CurrentBttnIndex = j;
return true;
}
}
}
and maybe I should mention that this is all part of a smartclip (or if you prefer, a component).
If anyone has any insight into my problem I would be thankful for it.
Hittest Array?
i have an array that attatches movie clips for a game with floor and wall like this:
Code:
// arrays for level.... 0 == wall, 1 == floor//
M0 = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
M1 = new Array(0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0);
M2 = new Array(0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0);
M3 = new Array(0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0);
M4 = new Array(0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0);
M5 = new Array(0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0);
M6 = new Array(0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0);
M7 = new Array(0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0);
M8 = new Array(0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0);
M9 = new Array(0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0);
M10 = new Array(0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0);
M11 = new Array(0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0);
M12 = new Array(0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0);
M13 = new Array(0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0);
M14 = new Array(0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0);
M15 = new Array(0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0);
M16 = new Array(0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0);
M17 = new Array(0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0);
M18 = new Array(0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0);
M19 = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
n1 = 0;
n2 = 0;
n3 = 0;
// go through arrays and attach wall/floor movie clips as needed//
while (n1<28) {
while (n2<28) {
if (eval("M" add n1)[n2] == 0) {
// wall
attachMovie("wall", "wall" add n1 add "-" add n2, n3);
eval("wall" add n1 add "-" add n2).nn = "wall" add n1 add "-" add n2 add "/" add n3;
eval("wall" add n1 add "-" add n2)._x = (n2*20);
eval("wall" add n1 add "-" add n2)._y = (n1*20);
}
if (eval("M" add n1)[n2] == 1) {
// floor
attachMovie("floor", "floor" add n1 add "-" add n2, n3);
eval("floor" add n1 add "-" add n2).nn = "floor" add n1 add "-" add n2 add "/" add n3;
eval("floor" add n1 add "-" add n2)._x = (n2*20);
eval("floor" add n1 add "-" add n2)._y = (n1*20);
}
n3++;
n2++;
}
n2 = 0;
n1++;
}
and i need a way of hittesting with the walls????? as this is for a bomberman game
the instance names of the movies are like wall0-0/0 or floor10-12/292
the numbers are n1 add "-" add n2 add "/" add n3
n3 is the depth
[Edited by Veryevil on 10-26-2001 at 04:26 PM]
Hittest Array
In all my games that deal with projectiles and shooting stuff i have an array for all the enemies in existence and each projectile is constantly checking for a hittest with the enemies in the array.
Heres some code
Code:
function enemykill(sname) {
for (x=0; x<_root.eTracker.enemyArray.length; x++) {
name = _root.eTracker.enemyArray[x].name;
if (_root[sname].hitTest(_root[name])) {
_root[name].removeMovieClip();
_root.eTracker.enemyArray.splice(x, 1);
_root[sname].removeMovieClip();
}
}
}
where sname is the projectile name.
I tried to make a classic airplane shooter type game but this technique slows the computer down way to much to have a good amount of enemies, is there a more efficient way to do this?
Array HitTest
Hi all,
I'm trying to set up a piece of code that will detect when an array of movieclips are all hitTesting another set of movieclips. Here's my code:
ActionScript Code:
dragSet=new Array("no1","no2","no3")
onEnterFrame= function(){
for (i in dragSet){
if((place1.hitTest(_root.myMC[dragSet[i]])) && (place2.hitTest(_root.myMC[dragSet[i]])) && (place3.hitTest(_root.myMC[dragSet[i]]))){
_parent.goButton._visible=true
}
}
}
This isn't working. Can anyone help by telling me why? I've been scouring forums but getting nowhere.
Thanks again. Rally appreciate you all looking at this!
P.s Would be good if people used their titles in posts to summarise the problem they have. Sometimes people just put 'Help!'.
Help With An Array And A HitTest
i'm create a remake of the asteroids game, and i'm trying to get the small asteroids to appear when a big one is shot.
what i have is the big ones in an array, so i can uniquely identify them, and thus my hitTest works. i then created another array to put the smaller ones in, but i am unsure of how i could just get them to be on the stage when a big one is shot. at the present time, my smaller asteroids are on the stage at the start of the file.
any help would be grealty apprciated.
HitTest On An Array
I can not get a hitTest on Array
Code:
var depth:Number;
var ballArray:Array = new Array();
for (i=0; i<10; i++) {
depth = this.getNextHighestDepth();
var dots:MovieClip = attachMovie("ball", "ball"+depth, depth);
dots._x = Math.floor(Math.random()*Stage.width);
dots._y = Math.floor(Math.random()*Stage.height);
ballArray.push(["ball"+depth]);
trace(ballArray);
}
dragger_mc.onPress = function() {
this.startDrag();
this.onEnterFrame = function() {
for (var i:Number = 0; i<ballArray.length; i++) {
if (this.hitTest(ballArray[i])) {
trace("hit");
}
}
};
};
if i trace ballArray I get the Array but i do not get a trace of a "hit"
my next stage is to removeMovieClip ball+ and to delete its namesake from the Array any help much appreciated ...
"hitTest" Refuses To Detect My Collisions
I beleive all of my code is 100% correct yet i'm still running into strange problems with collision detection, let me try to explain.
I have one character movieclip, that moves in 4 directions when arrowkeys are pressed.
One dynamic text box which acts as a simple scorecount
One other movieclip which acts as a coin/pickup for the main character (has two frames, one with the coin, and one without (so it gives the impression of the character collecting the coin once collision is detected.
Yet everytime I test the movie and run into the coin with my character, the character walks right through it, and no collision is detected, or so it seems, this the code I wrote into the coin's action panel.
onClipEvent (load) {
this.stop();
}
onClipEvent (enterFrame) {
if (this.hitTest(_root.character)) { (if coin collides with char, coin goes to frame 2 + adds 1 to score count)
this.gotoAndStop(2);
_root.score +=1;
}
}
This alone should work am I right?
HitTest-Array Question.
I currently use this code:
code: onClipEvent (enterFrame) {
if (_parent.hittest.hitTest(_parent._parent.ground)) {
_parent._y = _parent._parent.ground._y-42; // places the hero correctly ontop of the ground, otherwise he stands inside the ground.
_parent.gotoAndStop("stand");
}
}
I want to hitTest against more ground MCs. So I guess I name all the ground MCs to ground1, ground2 etc and use a code like this:
code: onClipEvent (enterFrame) {
for (var i = 0; i<10; i++) {
if (_parent.hittest.hitTest(_parent._parent["ground"+i])) {
_parent.gotoAndStop("stand");
}
}
}
But how do I apply a ._y-42 to that?
HitTest Inside Array
Hi forum,
I have a class called Ghost as an actionscript file. In my flash file I created an array and populate the array using push. On enterFrame I get my ghost instances to move calling a function inside the class - and that works. Now to do a hitTest between the moving ghosts is the hard bit. I obviously try to avoid that the ghost hits himself, but I think I 'm not referencing correctly to the instances in the array?
Here is the part of the code:
// Create array to hold movie clips ghosts.
var ghostArray:Array = new Array();
//
// Loop to push 5 ghosts into array and display.
for (var i:Number = 0; i <= 4; i++) {
ghostArray.push(new Ghost())
}
// Constantly move the ghosts.
this.onEnterFrame = function() {
// Loop to get all elemenst in array.
for (var j:Number = 0; j < _root.ghostArray.length; j++) {
// Call function to move the objects.
ghostArray[j].move();
}
for(i:Number = 0; i < _root.ghostArray.length; i++) {
//
if (this != _root.ghostArray && this.hitTest(_root.ghostArray)) {
trace("collision between ghost");
}
}
}
Can anybody help? Very much appreciated.
otti
Array Hittest Problem
OK, so I have an array of enemy instance names produced using the push(); and pop(); method and i have code so that when an attached bullet hits any of the ones in that array (uses a for loop), it removes the bullet, but I can't figure out how to get it to remove the enemy it hit. Is there a way to find out which enemy movieclip it hit and return that instance name so i can put it in a variable and remove it? Thanks.
HitTest On Object Within The Same Array
I have enemy ships appear four at a time, however sometimes they appear on top of each other, how can I make a hitTest that will determine if objects within the same array are hitting each other, this is the way I do my hitTest:
ActionScript Code:
for (var enemyNum:int=enemies.length - 1; enemyNum >= 0; enemyNum--) {
for (var laserNum:int=lasers.length - 1; laserNum >= 0; laserNum--) {
if (enemies[enemyNum].hitTestObject(lasers[laserNum])) {
however this doesn't work because the objects will end up hitting themselves
Movieclip & Array With HitTest, Not Working
Ok, my problem is that I have a grassfield named: "grass1". I put it an array named:"grass" with the index of 0. I want to use the array in a hitTest to make the guy stop. I know how to do the stop functions, but I don't think I am doing the array right. Here is all of my code so far:
Code:
movespeed = 10;
bg = new Array(_root.bg0);
objects = new Array(_root.bg0.grass0, _root.bg0.grass1);//My grass array
_root.guy.onEnterFrame = function() {
if (Key.isDown(37)) {
this._x -= movespeed;
}
if (Key.isDown(39)) {
this._x += movespeed;
}
if (Key.isDown(38)) {
this._y -= movespeed;
}
if (Key.isDown(40)) {
this._y += movespeed;
}
if (grass[0].hitTest(this)) {//This is the hitTest I am having troubles with
this._x -= movespeed;
}
};
Now, how can I get the hitTest to work properly with the array?
Hittest An Array And Removing A Child
Ok in my asteroids game when the ship hits a rock I want the ship to be removed and it to go to frame 3 but I cant get it to work.
here is the code I am using
PHP Code:
stop();
//create an array to hold all the rocks
var rockArray:Array = new Array();
//var startTime:int = int(timer);
var rockTimeGap:int = 5;
var timeElapsed:int = 0;
var i:int;
//create the ship and add to the stage
var newShip:Ship = new Ship();
addChild(newShip);
//places the ship in the middle of the stage
newShip.x = stage.stageWidth/2;
newShip.y = stage.stageHeight/2;
//create a rock and add it to the stage
var newRock:Rock = new Rock();
addChild(newRock);
//place it at a random x and y position
newRock.x = Math.random() * stage.stageWidth;
newRock.y = Math.random() * stage.stageHeight;
//make the rocks x and y scale random
newRock.scaleX = Math.random();
newRock.scaleY = Math.random();
// make the x and y direction and speed of the rock a random number between -5 and 5
newRock.xDirection = Math.random()*10-5;
newRock.yDirection = Math.random()*10-5;
// make the direction and speed of the rock random number between -10 and 10
newRock.rotationDirection = Math.random()*20-10;
//add a new rock to the end of the array
rockArray.push(newRock);
//event listener for the keyboard that allows a key to be pressed down
stage.addEventListener(KeyboardEvent.KEY_DOWN,moveShip);
function moveShip(event:KeyboardEvent):void {
//when an arrow key is down then the Ship will move
if (event.keyCode==(Keyboard.RIGHT)) {
newShip.rotation += 15;
trace(newShip.rotation);
} else
if (event.keyCode==(Keyboard.LEFT)) {
newShip.rotation -= 15;
trace(newShip.rotation);
} else
if (event.keyCode==(Keyboard.UP)) {
newShip.y -= 5;
} else
if (event.keyCode==(Keyboard.DOWN)) {
newShip.y += 5;
}
//if ship moves off bottom of the stage then place it at top of the stage
if (newShip.y >= stage.stageHeight) {
newShip.y = 0;
//else if the ship moves off top of the stage then place it at bottom of the stage
} else
if (newShip.y <= 0){
newShip.y=stage.stageHeight;
//else if the ship moves off Right side of the stage then place it at left side of the stage
} else
if (newShip.x >= stage.stageWidth) {
newShip.x = 0;
//else if the ship moves off lef side of the stage then place it at right side of the stage
} else
if (newShip.x <= 0) {
newShip.x=stage.stageWidth;
}
}
//create a timer for the rocks that will fire every 5 seconds
var rockTimer:Timer = new Timer(5000);
//create a timer that will fire every seconds
var timer:Timer = new Timer(1000);
//event listener for the rock Timer and Timer
rockTimer.addEventListener(TimerEvent.TIMER, onTimer);
timer.addEventListener(TimerEvent.TIMER, timedFunction);
//start the rock timer and the timer
rockTimer.start();
timer.start();
function timedFunction(eventArgs:TimerEvent)
{
//display the score in the timer textbox
score_txt.text =(" Score: "+( timer.currentCount + 1));
}
//create a rock when the rock Timer fires and add it to the stage
function onTimer(evt:TimerEvent):void{
var newRock:Rock = new Rock();
addChild(newRock);
//place it at a random x and y position
newRock.x = Math.random() * stage.stageWidth;
newRock.y = Math.random() * stage.stageHeight;
//make the rock scale random
newRock.scaleX = Math.random();
newRock.scaleY = Math.random();
// make the x and y direction and speed of the rock a random number between -5 and 5
newRock.xDirection = Math.random()*10-5;
newRock.yDirection = Math.random()*10-5;
// make the direction and speed of the rock random number between -10 and 10
newRock.rotationDirection = Math.random()*20-10;
//add a new rock to the end of the array and add to the rock count
rockArray.push(newRock);
}
rockArray[i].addEventListener(Event.ENTER_FRAME,handlerocks);
function handlerocks(event:Event):void {
for (var i:int = 0; i< rockArray.length; i++) {
rockArray[i].x += rockArray[i].xDirection;
rockArray[i].y += rockArray[i].yDirection;
rockArray[i].rotation += rockArray[i].rotationDirection;
if (newShip.hitTestObject(rockArray[i])) {
rockTimer.removeEventListener(TimerEvent.TIMER, onTimer);
rockArray[i].removeEventListener(Event.ENTER_FRAME,handlerocks);
stage.removeEventListener(KeyboardEvent.KEY_DOWN,moveShip);
removeChild(newShip);
gotoAndStop("3");
}
if (rockArray[i].y >= stage.stageHeight) {
rockArray[i].y = 0;
} else if (rockArray[i].y <= 0) {
rockArray[i].y=stage.stageHeight;
} else if (rockArray[i].x >= stage.stageWidth) {
rockArray[i].x = 0;
} else if (rockArray[i].x <= 0) {
rockArray[i].x=stage.stageWidth;
}
}
}
Also here is the fla files. The Flash asteroids game fla file is my game and the The Roid_start file is a flie I was given as a starting point. I then had to take that Roid_star file and add in more code to make it into a asteroids game.
Selecting An Entire Array For HitTest
Hi
Is there a way i can do something like this that actually works?
Say there is four blocks on the stage and i want a hitTest to select them all in one line of script.
PHP Code:
var myarray:Array = [block1, block2, block3, block4];
onEnterFrame = function () {
if (ball.hitTest(myarray)) {
gotoAndStop(2);
}
};
Triggering Array Items Using HitTest?
Hello again,
I've built an array of movieclips - all of them sitting static on the stage.
I'm trying to trigger the clips to play as they are hit by an invisible/alpha 0 bar which sweeps across the stage... kind of like a mexican wave?
I'm still a bit crappy with arrays - here's my code:
Can somebody please tell me what I'm doing wrong?
Code:
var target_mc:Array = new Array();
for (var i:Number = 1; i <= 30; i++)
{
target_mc.push("b" + i);
}
onEnterFrame = function() {
if (trigger_mc.hitTest(target_mc[i])) {
target_mc.gotoAndPlay(1);
}
}
HitTest An Array And Remove Child
ok here is my game. I have a some rocks that are in an array and they appear every 5 seconds on the stage and they move around. I have a ship that can move around the stage. What I want to happen is when the ship hits a rock the ship will be removed and it will go to and play frame 3, gme over frame. I have put the hitTest code in and the remove child and gotoAndPlay but the ship gets removed as soon as the game begins and it goes to frame 3 and I get errors in the output window.
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display:isplayObjectContainer/removeChild()
at AsteroidsGame_fla::MainTimeline/handleRocks()
Here is the code I have
ActionScript Code:
stop();
//create an array to hold all the rocks
var rockArray:Array = new Array();
var startTime:int = int(timer);
var rockTimeGap:int = 5;
var timeElapsed:int = 0;
var i:int;
//create the ship and add to the stage
var newShip:Ship = new Ship();
addChild(newShip);
//places the ship in the middle of the stage
newShip.x = stage.stageWidth/2;
newShip.y = stage.stageHeight/2;
//create a rock and add it to the stage
var newRock:rock = new rock();
addChild(newRock);
//place it at a random x and y position
newRock.x = Math.random() * stage.stageWidth;
newRock.y = Math.random() * stage.stageHeight;
//make the rocks x and y scale random
newRock.scaleX = Math.random();
newRock.scaleY = Math.random();
// make the x and y direction and speed of the rock a random number between -5 and 5
newRock.xDirection = Math.random()*10-5;
newRock.yDirection = Math.random()*10-5;
// make the direction and speed of the rock random number between -10 and 10
newRock.rotationDirection = Math.random()*20-10;
//add a new rock to the end of the array
rockArray.push(newRock);
//event listener for the keyboard that allows a key to be pressed down
stage.addEventListener(KeyboardEvent.KEY_DOWN,moveShip);
function moveShip(event:KeyboardEvent):void {
//when an arrow key is down then the Ship will move
if (event.keyCode==(Keyboard.RIGHT)) {
newShip.rotation += 15;
trace(newShip.rotation);
} else
if (event.keyCode==(Keyboard.LEFT)) {
newShip.rotation -= 15;
trace(newShip.rotation);
} else
if (event.keyCode==(Keyboard.UP)) {
newShip.y -= 5;
} else
if (event.keyCode==(Keyboard.DOWN)) {
newShip.y += 5;
}
//if ship moves off bottom of the stage then place it at top of the stage
if (newShip.y >= stage.stageHeight) {
newShip.y = 0;
//else if the ship moves off top of the stage then place it at bottom of the stage
} else
if (newShip.y <= 0){
newShip.y=stage.stageHeight;
//else if the ship moves off Right side of the stage then place it at left side of the stage
} else
if (newShip.x >= stage.stageWidth) {
newShip.x = 0;
//else if the ship moves off lef side of the stage then place it at right side of the stage
} else
if (newShip.x <= 0) {
newShip.x=stage.stageWidth;
}
}
//create a timer for the rocks that will fire every 5 seconds
var rockTimer:Timer = new Timer(5000);
//create a timer that will fire every seconds
var timer:Timer = new Timer(1000);
//event listener for the rock Timer and Timer
rockTimer.addEventListener(TimerEvent.TIMER, onTimer);
timer.addEventListener(TimerEvent.TIMER, timedFunction);
//start the rock timer and the timer
rockTimer.start();
timer.start();
function timedFunction(eventArgs:TimerEvent)
{
//display the score in the timer textbox
score_txt.text =(" Score: "+( timer.currentCount + 1));
}
//create a rock when the rock Timer fires and add it to the stage
function onTimer(evt:TimerEvent):void{
var newRock:rock = new rock();
addChild(newRock);
//place it at a random x and y position
newRock.x = Math.random() * stage.stageWidth;
newRock.y = Math.random() * stage.stageHeight;
//make the rock scale random
newRock.scaleX = Math.random();
newRock.scaleY = Math.random();
// make the x and y direction and speed of the rock a random number between -5 and 5
newRock.xDirection = Math.random()*10-5;
newRock.yDirection = Math.random()*10-5;
// make the direction and speed of the rock random number between -10 and 10
newRock.rotationDirection = Math.random()*20-10;
//add a new rock to the end of the array and add to the rock count
rockArray.push(newRock);
}
//event listener for the rock array
rockArray[i].addEventListener(Event.ENTER_FRAME,handlerocks);
function handlerocks(event:Event):void {
for (var i:int = 0; i< rockArray.length; i++) {
rockArray[i].x += rockArray[i].xDirection;
rockArray[i].y += rockArray[i].yDirection;
rockArray[i].rotation += rockArray[i].rotationDirection;
if(newShip.hitTestObject(rockArray[i]))
trace(newShip.hitTestObject(rockArray[i]))
removeChild(newShip);
gotoAndStop("3");
//if rockArray[i] moves off bottom of the stage then place it at top of the stage
if (rockArray[i].y >= stage.stageHeight) {
rockArray[i].y = 0;
//else if rockArray[i] moves off top of the stage then place it at bottom of the stage
} else
if (rockArray[i].y <= 0) {
rockArray[i].y=stage.stageHeight;
//else if the rockArray[i] moves off right side of the stage then place it at left side of the stage
} else
if (rockArray[i].x >= stage.stageWidth) {
rockArray[i].x = 0;
//else if the rockArray[i] moves off left side of the stage then place it at right side of the stage
} else
if (rockArray[i].x <= 0) {
rockArray[i].x=stage.stageWidth;
}
}
}
Trigger Clips From Array Using HitTest?
Hello again,
I've built an array of movieclips - all of them sitting static on the stage.
I'm trying to trigger the clips to play as they are hit by an invisible/alpha 0 bar which sweeps across the stage... kind of like a mexican wave?
I'm still a bit crappy with arrays - here's my code:
Can somebody please tell me what I'm doing wrong?
Code:
var target_mc:Array = new Array();
for (var i:Number = 1; i <= 30; i++)
{
target_mc.push("b" + i);
}
onEnterFrame = function() {
if (trigger_mc.hitTest(target_mc[i])) {
target_mc.gotoAndPlay(1);
}
}
HitTest Array And Duplicate Moive Clip Help
Help, I can't manipulate this array.
Ok,
I've got an array of draggable icons (with their absolute paths) on my _root timeline. They're duplicate movie clips. From within the icon movie clip I have a button with AS to drag and drop it any where on the stage. I want these icons to have collision detection such that if you drop one icon on top of another icon it returns it to the initial drag position.
The problem is that when I use a loop to go through and check if my icon has hit another one, I can't manipulate it to exclude the icon that I'm calling from. Here is where I'm at ... I've highlighted where I've gone wrong.
ActionScript Code:
on (release) {
for (i=0; i<_root.duplicatediconspaths.length; i++) {
[u]if (this.hitTest(_root.duplicatediconpaths[i]) && !this.hitTest(!this))[/u] {
this._x = this.old_x;
this._y = this.old_y;
}
}
stopDrag();
}
Thanks in advance and happy new year!
How To Take Time From HitTest True To HitTest False?
hi
i have 2 MCs one is going through the other
and i want to take the time from the beginning
to the end.my code is this:
onClipEvent(load) {
this._visible = 0;
}
onClipEvent(enterFrame) {
first = new Date;
second = new Date;
indicator = 0;
if(!indicator && this.hitTest(_root.rocket)) {
indicator = 1;
sec = erst.getSeconds;
mil = erst.getMilliseconds;
begining = sec add ":" add mil;
}
if(indicator && !this.hitTest(_root.rocket)) {
indicator = 0;
seco = zweit.getSeconds;
mill = zweit.getMilliseconds;
end = seco add ":" add mill;
xposi = getProperty(_root.rocket, _x);
yposi = getProperty(_root.rocket, _y);
position = xposi add yposi;
}
}
further i want to show begining, end and position in 3 different textfields, but nothing works at all !!!
can it be, that it doesn`t work, because "this" is a symbol
in a symbol?!?
thx
bo
[F8] Array Problem?, Hittest Problem?, Or I'm Clueless Problem?
Hey everybody!
I'm getting back to work on my game now that summer is here, and I have run into an interesting problem. My "bad guy" (running on an array) is able to pass through the bullets/mines/walls about a quarter of the time. What am I doing wrong?
You should probably download the file because it is hard to explain.
Thanks!
Peejaroni
Hittest=false, Trying To Do The Opposite Of Hittest.
This question may have such an easy solution it might be worth for the newbies section...
I need an mc to do an action (go to a certain x point) whenever the mouse ISN'T over a particular box. So basically I would need to revert the typical
if (hitTest( _root._xmouse, _root._ymouse));
Anyone knows how to do this?
Thank you soooo much!
HitTest...creating The Opposite Of A HitTest
When I roll over a mc an enter frame triggers a function that is designed to evaluate when the mouse moves off the mc...how do you test for the opposite of a hitTest? I though in an "!", but didn't work.
PHP Code:
var buttonTarget:String = "targetMarkets_mc";
root[buttonTarget].addEventListener(MouseEvent.MOUSE_OVER, overHandler);
function overHandler (event:MouseEvent){
root[buttonTarget].gotoAndStop ("active");
root[buttonTarget].addEventListener(MouseEvent.MOUSE_MOVE, mouseEval);
};
function mouseEval (event:MouseEvent) {
if (!root[buttonTarget].hitTestPoint (mouseX, mouseY, true)) {
root[buttonTarget].gotoAndStop ("inactive");
root[targetMC].removeEventListener (MouseEvent.MOUSE_MOVE, mouseEval);
}
};
Also, how do you remove the event listener? Is there a need?
Array, Array HELP - Importing A External File Into N ARRAY - Almost There
I am reading and external file with the following code:
ActionScript Code:
on (release, keyPress "<Enter>") {
lv = new LoadVars();
lv.onLoad = function() {
questions1 = this.filelist0.split(",");
answers1 = this.filelist1.split(",");
for(i=0;i<questions1.length;i++)
//trace(questions1[i]+" "+answers1[i]);
trace(questions1[i]);
//assumes same number of scores in each list
};
lv.load("questions.txt");
}
When I parse the file it puts it into an columar format as it should...however I need it to look like this:
questions1=new Array ("2+4=?","What is the capital of Illinois?","What color is the sky?","10x(5+2)=?");
answers1=new Array ("8","springfield","blue","70");
How do I do that?
Text file look like this:
&questions1=2+4=?,What is the Capital of Illinois?,What color is the sky?,10x(5+2)=?")&
&answers1=8,springfield,blue,70&
[hitTest/Mask] Can A Mask Hide A HitTest Area?
Hi, the subject pretty much says it all. I have the following code:
ActionScript Code:
volume.onEnterFrame = function() {
if (volume.hitTest(_xmouse, _ymouse, true)) {
_root.nextFrame();
} else {
_root.prevFrame();
}
};
...and here is the link. Move your mouse under the bar and move it up slowly under the the speaker next to the number. See what happens? Keep in mind that the look is still being perfected, I was just wanting to know if there were a way I could fix the problem or do I just have to start thinking of a new look for it? Thanks in advance.
(PS: let me know what you think of the look and layout please)
Pls Help: Need To Create New Array Taking 3 Random Entries From An Existing Array
Hello
I have a 2d array:
qTeeth[1] = [How many teeth do we have?, 1-10, 11-20, 21-30, 11-20]
etc.
It goes [question, option1, option2, option3, real answer]
I now just want to extract 3 or so of these entries and create a new array with them. Since I want to just use 3 or so questions randomly from a large array of questions.
Does anyone know a good tidy script to do this with??
Thanks in advance,
Ben.
Array Text Into Textfield And Creating New Line For Each Array Element
I have an array called dropTarg1 which stores dropped-in items.
I want to loop through this array and in a textfield, display each array item on a new line of this text field
I think I need to use something like Array.join("/n") but I can't get it working properly. I hope that the /n would create a new line of the text field called reviewBoxContentText.
for(var i:Number = 0; i<dropTarg.length; i++){
with(reviewBoxContent.reviewBoxContentText){
autoSize = true;
text = dropTarg1.join("/n");
}
}
All that is happening though is that the text field displays on a single line with /n in between each array element.
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!
Array.splice Works But Array.slice Doesnt?
This should be simple enough. I have an array of objects, and I want to SLICE a piece of the array and assign it to a new array. All of my attempts have failed. SPLICE works, and I could duplicate my original array into a temp array and splice out what I want, but surely slice is supposed to save me this trouble, right?
I'm a bit baffled, but here's the code:
Code:
private function createGlist() {
var glistObj:Glist = this;
xml_object = new XML();
xml_object.ignoreWhite = true;
xml_object.onLoad = function(success:Boolean):Void {
if(success) {
var i:Number = 0;
for (var this_node = this.firstChild.firstChild; this_node != null; this_node = this_node.nextSibling) {
glistObj.thumb_array.push(new Gthumb(glistObj, glistObj.thumb_array_mc.getNextHighestDepth(), this.firstChild.childNodes[i]));
i++;
}
var load_start:Number = 2;
var load_count:Number = 2;
glistObj.thumb_load_array = glistObj.thumb_array.slice(load_start,load_count);
trace(glistObj.thumb_load_array); //no result, no error
trace(glistObj.thumb_array.slice(load_start,load_count)); //no result, no error
trace(glistObj.thumb_array.splice(load_start,load_count)); //outputs [object Object],[object Object]
} else {
//error
}
}
xml_object.load(xml_url);
}
Array Copy Points To Original Array Instead Of Duplicating
Hey all.
Spent a long time trying to figure out what was wrong with my code. Then I remembered about arrays being objects instead of primitive variables. My question is, how can I make a duplicate copy of an Array?
Details:
So this code
PHP Code:
package{
import flash.display.*
public class tester extends MovieClip{
var a:Array = [1,2]
public function tester () {
var b = a
trace (a)
b.splice(1,1)
trace (a)
}
}
}
results in this output:
PHP Code:
1,2
1
How can i make b an actual duplicate of a, instead of a pointer?
PHP Code:
b = new Array
b = a
doesn't work either.
Thanks!
DHP
Creating Multi-dimentional Array From Single Array
I have an array
myArray=[hello,bye,fred,1,2,3,4,5,6];
I need to convert it to a multi-dimentional array that would look something like below
array1=[hello,bye,fred];
array2=[1,2,3];
array3=[4,5,6];
newArray=[array1, array2,array3];
I am not sure how to split the array can anyone help? myArray.length/3 would give me the number in each of the new arrays but I am puzzled after this?
Associating Array Elements With Another Array Keeping The Order.
hi, i have already posted this problem yesterday but i haven't solved it yet.
i have two arrays:
array_1[a,b,c,d]
array_2[01,02,03,04]
the first array represents mcs in my stage - the buttons of the menu.
the second represents other mcs, containing some text.
when i rollOver each element of array_1 i would like to show each element of array_2 in the same order and hide it when i rollOver another menu button to show a new one.
I mean, it always has to be showing a with 01, b with 02, c with 03...
any suggestions?
Array Of Movie Loaders/array Of Image Files
Alright. I'm fairly new to Actionscripting, so if we can somewhat lame out the tech talk to mild to medium I'd appreciate it. what I am trying to do is create an swf movie that will interact with a PHP script. first lets start with saying the PHP script reads the directory that it is currently in and filters out any file that is not a GIF,PNG, or JPG and then it suffes all of this into a URL encoded string and the directory path ,such as :
?pictures=image1+image2+image3+image4&path=http://servername/directoryPath
now i have flash load the variables "pictures" and split the images and stuff those into an array and the directory path of course stays in its own seperate variable. ive gotten this far with no problems.
so what im trying to do now with this info is create a bit of a slide show. I want to take the array of pictures and load those into an empty movie clip displaying each picture consecutively. Ive made several attempts but no such luck. Ive tried to use a for() loop to cycle through the array of pictures loading them into the empty clip. im still very new and rather lost with these objects and class use i. Im sure im probably not using a listener of somesort that i need and what not. I am sorry i am probably not giving enough info for all this. the whole idea of this clip is to be able to display an indefinite amount pictures , so the flash player will not know ahead of time how many pictures till the php script has sent all the names of what is in the directory. this movie needs to be able to dynamically load any images that are in that directory.so any suggestions on what i can do with an array an an empty clip? thank you to anyone who can make suggesions.
How Do I Lope Through Array, Delete Clip And Remove From Array
I have a function that creates an instance of a movieClip and adds it to an array.
In my gameloop I loop through the array and change some values. Now I want a cleanup function that loops through the array, and if the y value exceeds a certain value, I want to delete the clip instance and remove the record in the Array.
Could someone please help me with the syntax for that? I will lay the code out below.
Thankyou
Attach Code
var myClipArray = new Array();
public function createClipInstance() {
var myClipInstance:myClip = new myClip();
myClipInstance.y = 0;
addChild( myClipInstance );
myClipArray.push(myClipInstance);
}
// loop through array and check y value
// if y > 400: Delete clip and remove from array
public function cleanClips() {
for (var n:int = 0; n<myClipArray.length; n++){
if (myClipArray[n].y > 400) {
// DELETE CLIP AND REMOVE FROM ARRAY
trace("this is where I need help");
}
}
}
Generate Random Value From Array 'excluding' The Current Array Value
getting my head round flash (sorta!)...
ok, nearly got this working; i have 11 movie clips on the root timeline and a empty controller movie. what i need to happen is for a random movie clip to play. when it reaches a point in it's own timeline, it sets the playNext variable to true and the controller movie clip works out the next random movie to play.
the problem comes when the controller 'randomly' picks the movie clip thats already playing! then the whole thing breaks...
is there a way that i can say 'generate me a random clip to play from this array 'excluding' the currently playing movie clip'?
any suggestions would be grand.
this is what i have on my controller clip:
onClipEvent (load) {
//define a new array
video_array = new Array();
//list each of the videos
video_array[0] = "zero";
video_array[1] = "one";
video_array[2] = "two";
video_array[3] = "three";
video_array[4] = "four";
video_array[5] = "five";
video_array[6] = "six";
video_array[7] = "seven";
video_array[8] = "eight";
video_array[9] = "nine";
video_array[10] = "ten";
//this is the count of how many elements (videos) are in your array
max = video_array.length;
//set the playNext to true
_root.playNext = true;
}
onClipEvent (enterFrame) {
//if playNext is true
if (_root.playNext) {
//generate a new random video to play
randomNumber = Math.floor(Math.random()*max);
//store the name
randomVideo = video_array[randomNumber];
//tell that video to play
_parent[randomVideo].gotoAndPlay(13);
//record the video we are playing
crntVideo = randomVideo;
//set playNext to false
_root.playNext = false;
}
}
Load Xml Images-->Array-->Duplicate Array: AHAA
Hello Kirupians!
[Summary]
I want to load images from an XML, then store the images inside an array, then duplicate that array into other clone arrays so that I can addChild() copies of the images into stage whenever i want (and be able to change their properties).
Basicly i have to create two duplicates; big_img and icon_image
[SYMPTOMS]
Everything is loaded fine;the big_imgloads and positions correctly, but, when i try to load icon_image the first big_img disappears! as if the new array has hasn't duplicated the original array (as if it's only a shortcut, not a real copy).
The cody thing:
ActionScript Code:
// total images read from XMLvar axiLength=Accessoir.length();// main image container arrayvar axxARR:Array = new Array();// add images to arrayfor (var k=0; k<axiLength; k++) { var axxLoader:Loader = new Loader(); axxLoader.load(new URLRequest(Accessoir.PHOTO.text()[k])); axxARR.push(axxLoader); axxLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, axxLoaded);}function axxLoaded(e:Event):void { // show big image if (axiLength==axxARR.length) { axxShow(0); }}function axxShow(ID_AXX:Number) { // duplicate images array var axxImage:Array=axxARR.concat(axxARR); // reposition it axxImage[ID_AXX].x = product_details_swf.axx.x+(axxImage[ID_AXX].width/2)-5.5; // Add init image to accessoires axxImage[ID_AXX].name="axxImage"; product_details_swf.axx.addChild(axxImage[ID_AXX]);}// here i got an event listner to a button, once rolle over is triged it // should make small copies of the whole array images and put them on stage//....function rollover_button(ID_AXX:Number) { for (var i=0; i<axiLength; i++) { axxCreate(i); } function axxCreate(ID_AXX:Number) { var axxPic:Array=axxARR.concat(); imageResizer(axxPic[ID_AXX], 50, 50); axxPic[ID_AXX].name="axxPic_"+ID_AXX; axxPic[ID_AXX].x=product_details_swf.axx.getChildByName("axxBG_"+ID_AXX).x+axxPicSpacingX; axxPic[ID_AXX].y=product_details_swf.axx.getChildByName("axxBG_"+ID_AXX).y+axxPicSpacingY; product_details_swf.axx.addChild(axxPic[ID_AXX]); }}
[MORE INFORMATION]
I tried array duplication using; concat and slice but not work, it doesn't creat copies of the orriginal array, but just a shortcut to it!
thanx for any tips!
Generate Random Value From Array 'excluding' The Current Array Value
getting my head round flash (sorta!)...
ok, nearly got this working; i have 11 movie clips on the root timeline and a empty controller movie. what i need to happen is for a random movie clip to play. when it reaches a point in it's own timeline, it sets the playNext variable to true and the controller movie clip works out the next random movie to play.
the problem comes when the controller 'randomly' picks the movie clip thats already playing! then the whole thing breaks...
is there a way that i can say 'generate me a random clip to play from this array 'excluding' the currently playing movie clip'?
any suggestions would be grand.
this is what i have on my controller clip:
onClipEvent (load) {
//define a new array
video_array = new Array();
//list each of the videos
video_array[0] = "zero";
video_array[1] = "one";
video_array[2] = "two";
video_array[3] = "three";
video_array[4] = "four";
video_array[5] = "five";
video_array[6] = "six";
video_array[7] = "seven";
video_array[8] = "eight";
video_array[9] = "nine";
video_array[10] = "ten";
//this is the count of how many elements (videos) are in your array
max = video_array.length;
//set the playNext to true
_root.playNext = true;
}
onClipEvent (enterFrame) {
//if playNext is true
if (_root.playNext) {
//generate a new random video to play
randomNumber = Math.floor(Math.random()*max);
//store the name
randomVideo = video_array[randomNumber];
//tell that video to play
_parent[randomVideo].gotoAndPlay(13);
//record the video we are playing
crntVideo = randomVideo;
//set playNext to false
_root.playNext = false;
}
}
Copying Loaded Array Into A Local Array
I'm loading an array through loadVariablesNum (into level 0). The script properly returns array values... I've checked by using text boxes on my stage. But, when I try to store the loaded array within a local Actionscript array for manipulation, it doesn't seem to be able to read the loaded values. It's as if the stage and the frame Actionscript were independent of each other. Can anyone help?
Thanks
Inserting An Array Into An Array To Make It Multidemensional
hi there,
Using an ASP script I've managed to get strings into flash
at the moment the strings come in like this:
array1=data1,data2,data3,data4,data5
array2=celeb1,celeb2,celeb3,celeb4,celeb5
currently I'm doing this:
webfoldercontents = new Array();
webfoldercontens = websubfolders.split(",");
which creats a 2d array. what I need is this:
multidemesionalarray = [array1[array2]]
any help v.appreciated!
Danny
Saving An Array Then Importing Saved Array?
I am creating a kids activity. At the moment I am working on the stamp tool that allws them to stamp a shape in different colours over the canvas... this is working fine, however I need to track the position and colour (and maybe more later) so that the child can save the activity and go back to it later.
So far I have managed to create an array for each propery (_x position, _y position and colour) in seperate arrays as a new stamp is attached it is given a number (1,2,3,4...) and in each array entry of that number are the position or colour properties. When I save these arrays (using FSCommand in Flash5) I think thay form a string in the text document.
When I loads the array from the text document, that looks like this:
&colourArray=255,255,255,16711680,16711680,1671168 0,16711680,16711680,16711680,16711680&XposArray=23 3,420.95,389,262,556.95,674.95,619.95,481.95,458.9 5,280&YposArray=109,167,313,211,301,158,80,105,174 ,451.95
I cannot pull out the data from the arrays (colourArray[2] traces as undefined) What I want to do is a loop based on the lenght of one the arrays that attaches the stamp MC in the correct position and colour.
Hope someone can shed light on this for me... I think I need to find a way to convert the text file data from a string to an array?!?
Cheers
Oll
|