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




Trouble With HitTestPoint And Tween



Hi guys,I'm having a trouble with hitTestPoint and tween. Well, if you look at the code you will understand what I am trying to archive here.---------------------var action:Tween;target01.alpha = 0.6;target01.addEventListener(Event.ENTER_FRAME, transition01);function transition01(event:Event):void {if (target01.hitTestPoint(mouseX, mouseY, true)) {action = new Tween(target01, "alpha", Strong.easeOut,0.6, 1, 1, true);} else {action = new Tween(target01, "alpha", Strong.easeOut,1, 0.6, 1, true);}}---------------------Yes, that's right. I'm trying to make the movie clip 'target01' to fade in once the mouse pointer roll-overs, and fades out when roll-out. But tween actions don't work...Yes, I did MouseEvents instead, but it is not the way I want it.. Please help me outta here guys.



ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0
Posted on: 04-08-2008, 05:12 PM


View Complete Forum Thread with Replies

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

_x Tween Trouble
I am unable to tween into a specific position. Here is the code that I am using.
if (_root.arrow._x>330) {
_root.arrow._x-=70;
gotoAndPlay("loop");
} else{
gotoAndStop(1);
}
When I replace "-=70" with "--" I can hit the exact spot that I am going for, but it does not move fast enough.

Any suggestions would be greatly appreciated.

Thanks

Multiple Tween Trouble
Ok are you sopposed to have more then 1 dif. kind of tweens on 1 layer....or are u sopposed to make a seperate layer 4 a seperate tween
thx alot 4 the help
this ? is bothering me

Fade In Tween Trouble...
maybe i'm completely crazy... i'm trying to tween a mc symbol... just a simple alpha fade... on the main timeline of a swf... he symbol is made of dynamic text embeded... but of two different text boxes... converted to grapic symbols... on two different layers... in the mc symbol... is there something wrong with me...? it wont tween... i've tried it with one layer... i've tried it grouping them... i need the fonts to be two different sizes in the one symbol...

help... it's probably something silly...

[FCS3] Tween Trouble In CS3
My Flash experience is in using Flash8, and I'm currently using CS3 for the first time. I am however using AS2.0, not 3.0.

I'm using several motion tweens between various keyframes in a layer of a movieclip. Each tween is from a keyframe with a symbol instance set at color: Alpha, 0% and the same symbol with color: Alpha, 100%. These appear to be functioning properly. Below that layer I have a layer with almost identical "static" symbols. The intended effect being part of the swf "fades in."

However, by the second frame as the alpha starts to tween in, the entire image (including the normal static layer) is washed out as if the tween layer has 100% opacity over the static fill layer.

I've done the exact same thing in the past using Flash8, so maybe I'm just forgetting something. Thanks for any help!

Tween Class Trouble
An swf is worth a thousand words, so....

Please go to http://www.datapixel.eu/datapixel.htm

and watch yourself. When you click on "Apri Menu" (Open Menu in english) an animation made with the Tween class shows.

It should enlarge the green panel in order to show the buttons. And IT DOES! .... sometimes.

Instead sometimes the animation stops prematurely and the menu is not correctly viewed. Do you know what's happening?

Thanks.

Trouble With The Tween Class
I'm having trouble with this code, it's for tweening Thumbnails in a photo gallery application I'm building:


Code:
var tween:Tween = new Tween(Thumbnails[Thumbnails.cur_thumbnail], "_alpha", mx.transitions.easing.Strong.easeIn, 40, 100, 1, true);
Thumbnails.cur_thumbnail = new_thumbnail;
What happens is while the tween variable is tweening the value of Thumbnails.cur_thumbnail changes therefore cutting off the tween before it gets started or at least I'm assuming this is what's happening.

How do I get around this? Thanks.

Tween Class Trouble
Well, firstly, excuse my poor english... I guess its not so good, but I hope you can understand me.

Well, I have imported the tween class at my .fla file with:

-------
import mx.transitions.Tween;
import mx.transitions.easing.*;
-------

as everywhere says it must be done. Later, I use:

-------
ROLLOVER:
var tw:Tween=new Tween(plano_mc, "_xscale", mx.transitions.easing.Elastic.easeOut,40, 100, 40, false);

var tw2:Tween=new Tween(plano_mc, "_yscale", mx.transitions.easing.Elastic.easeOut,40, 100, 50, false);
-------

inside a function that i call on the rollover method for the movieClip I want to tween.

The trouble comes in the rollOut method, where I have this code:

-------
ROLLOUT:
var tw:Tween=new Tween(plano_mc, "_xscale", mx.transitions.easing.Elastic.easeOut, 100,40, 1, true);
var tw2:Tween=new Tween(plano_mc, "_yscale", mx.transitions.easing.Elastic.easeOut, 100,40, 1, true);
-------

After the user rolls out, and even after the rollOut tween is well done, it resizes to the 100%, even if I'm out of the hitArea for the rollOver. All this instead of staying at the 40% of _xscale and _yscale, that is what I wanted the class to do (you can see it in the parameters of the tween).

It only happens in the rollOut method, because the rollOver doesn't get resized after is called as well as the rollOut... It should be logical if it should happen at both methods, but it just happens at RollOut, and even, each time I rollOut, is just one (or both sometimes) property which gets resized (sometimes the _yscale, other times the _xscale....). Is there any explanation for this???

I want to erase this error, that I can't find why happens. My only explanation is that Robert Penner did a bad class, but I don't really trust it because he is a Flash master and I'm just a beginner, so, please
pleeeeeaaaase!, anybody help me!
Thank you very much!

Tween Class Trouble
I have 2 tweens. I want my first one to be around 50% completed to start my second one. How do I do that ?


Code:
var Tween_right:Tween = new Tween(_root.mc_holder.mc_backgroundBlue, "_x", Strong.easeOut, 0, 525, 1, true);

var AlphaUp:Tween = new Tween(obj, "_alpha", Regular.easeOut, 0, 100, 1, true);
AlphaUp.stop();

Trouble With A Shape Tween
Howdy guys,
I got this problem with a shape tween in my project. Its basically a CBt type of deal. But the problem is when u click on a button and go to the page, a shape tween of a semi-transparent box betting bigger is supposed to happen, it is also a movie clip. It happens inside of it. It happens in the flash file, but when I export it it goes all wierd. The box is supposed to come from the top left and go to the right bottom. But when it plays it only shows the right side line.
Are both the timelines supposed to be the same amount. There both 10 frames. Any kind of help will be greatly appericated.
thanks

Tween Class Trouble
I don't use Tween class often, so don't scold me if this is an obvious question.

When I set up a simple Tween, it works if I assign a specific object's instance name as the object to tween. But when doing it inside a for loop, it doesn't work. Yet everything else within the for loop works. I've tested every variable, and it's the object name that doesn't work. Here is a simplified version of the code. Someone please tell me what I've done wrong.









Attach Code

import mx.transitions.Tween;
import mx.transitions.easing.*;
for (var k:Number = 1; k<15; k++) {
var dakine = this["letter"+k];
dakine.onPress = function() {
this._xscale = this._yscale=90;
this.startX = this._x;
this.startY = this._y;
startDrag(this);
};
dakine.onRelease = dakine.onReleaseOutside=function () {
stopDrag();
this._xscale = this._yscale=100;
var letterUp:Tween = new Tween(this, "_x", Bounce.easeOut, this._x, this.startX, 2000);
};
}

Still Having Trouble W/ Basic Color Tween
ok.
i have flash mx

frame one i create a circele with one color

click on frame 10, cpress f6(to create an identical keyframe to frame one, right)

by doing this the new objest is highlighted so i go to the properties window and change the color....


next i click on any frame between 1 and 10 and creat a motion tween from insert menu..

it still does not work.

the motion tween is dotted ... i know its supposed to be a solid line.

if i click on tframe 10 and create tween it change the objects to the same color.... what in tarnations is goin on here?!

please help.
thank you

Having Trouble With Tween Navigation (New To Flash)
http://douglas.mackenzie.natcoll.net...lash/index.swf
http://douglas.mackenzie.natcoll.net...lash/index.fla
is the link to the flash file.

The problem I am having is that it only tweens once. I wanted to be able to go back and forth - It just doesn't seem to respond after the first click.

Also it always goes the same way no matter where it's clicked. Can anyone work this out?

If anyone has time to read over this code it would be greatly appreciated.

Thanks


Code:
import fl.transitions.Tween;
import fl.transitions.easing.*;

var xTween:Tween;
var yTween:Tween;

var castMc:cast = new cast;
addChild(castMc);
castMc.x = -580;
castMc.y = 145;
//castMc.buttonMode = true;

var trailerMc:trailer = new trailer;
addChild(trailerMc);
trailerMc.x = 120;
trailerMc.y = 145;
//trailerMc.buttonMode = true;

var datesMc:dates = new dates;
addChild(datesMc);
datesMc.x = 820;
datesMc.y = 145;
//datesMc.buttonMode = true;

castMc.addEventListener(MouseEvent.CLICK, navigate);
trailerMc.addEventListener(MouseEvent.CLICK, navigate);
datesMc.addEventListener(MouseEvent.CLICK, navigate);

var castXposFarLeft:Number = -1280;
var castYposFarLeft:Number = 145;

var castXposLeft:Number = -580;
var castYposLeft:Number = 145;

var castXposMiddle:Number = 120;
var castYposMiddle:Number = 145;

var trailerXposLeft:Number = -580;
var trailerYposLeft:Number = 145;

var trailerXposMiddle:Number = 120;
var trailerYposMiddle:Number = 145;

var trailerXposRight:Number = 820;
var trailerYposRight:Number = 145;

var datesXposFarRight:Number = 1280;
var datesYposFarRight:Number = 145;

var datesXposRight:Number = 820;
var datesYposRight:Number = 145;

var datesXposMiddle:Number = 120;
var datesYposMiddle:Number = 145;

function navigate(event:MouseEvent):void
{
if(event.currentTarget.name == "castMc")
{
setTweenCast(castXposMiddle, castYposMiddle);
setTweenTrailer(trailerXposRight, trailerYposRight);
setTweenDates(datesXposFarRight, datesYposFarRight);
}
else if(event.currentTarget.name == "trailerMc")
{
setTweenCast(castXposLeft, castYposLeft);
setTweenTrailer(trailerXposMiddle, trailerYposMiddle);
setTweenDates(datesXposRight, datesYposRight);
}
else(event.currentTarget.name == "datesMc")
{
setTweenCast(castXposFarLeft, castYposFarLeft);
setTweenTrailer(trailerXposLeft, trailerYposLeft);
setTweenDates(datesXposMiddle, datesYposMiddle);
}

//trace(event.currentTarget.name);
}

function setTweenDates(tweenX:Number, tweenY:Number):void
{
xTween = new Tween(datesMc, "x", Strong.easeOut, datesMc.x, 0, 4, true);
yTween = new Tween(datesMc, "y", Strong.easeOut, datesMc.y, 145, 4, true);

xTween.begin = datesMc.x;
yTween.begin = datesMc.y;

xTween.finish = tweenX;
yTween.finish = tweenY;
xTween.start();
yTween.start();
}

function setTweenCast(tweenX:Number, tweenY:Number):void
{
xTween = new Tween(castMc, "x", Strong.easeOut, castMc.x, 0, 4, true);
yTween = new Tween(castMc, "y", Strong.easeOut, castMc.y, 145, 4, true);

xTween.begin = castMc.x;
yTween.begin = castMc.y;

xTween.finish = tweenX;
yTween.finish = tweenY;
xTween.start();
yTween.start();
}

function setTweenTrailer(tweenX:Number, tweenY:Number):void
{
xTween = new Tween(trailerMc, "x", Strong.easeOut, trailerMc.x, 0, 4, true);
yTween = new Tween(trailerMc, "y", Strong.easeOut, trailerMc.y, 145, 4, true);

xTween.begin = trailerMc.x;
yTween.begin = trailerMc.y;

xTween.finish = tweenX;
yTween.finish = tweenY;
xTween.start();
yTween.start();
}

Tween Action Script Trouble
i need to make a tween in flash that repeats its self when it finishes. it needs to be 1 frame and be in action script 2.0 i have managed to make the tween but it wont play again.

Could any one give me and hand

Thanks
Stupid Saint

Trouble With 1st Kirupa Flash 8 Tween Tutorial
Hi,

I'm on a Mac and a Flash MX 2004 user. I attempted to do Kirupa's very basic animation tweening tutorial to get myself going with Flash 8, but I cannot get it to work.

The motion works fine, but when I introduced the alpha part, it started behaving erratically. It just won't fade IN.

I am familiar and comfortable with animation tweens involving motion and fades in MX 2004...

I tried just doing a fade in for a single letter, not even inside a movie clip (as the tutorial has you do), and didn't use motion -- just a fade in: Can't even get that to work.

Any ideas? Some silly thing I overlooked??

Thanks!

SL

Tween Class Trouble (based On The Tutorial)
Hey hey hey.

I was gonna have a fiddle with this tutorial http://www.kirupa.com/developer/actionscript/tween.htm
so I downloaded, unzipped, saved and published it. I didn't have a chance to fiddle with anything and it's already broken! I get this:

**Error** Scene=Scene 1, layer=actions, frame=1:Line 5: There is no property with the name 'onMotionFinished'.
xScaleT.onMotionFinished = function() {

**Error** Scene=Scene 1, layer=actions, frame=1:Line 8: There is no property with the name 'onMotionFinished'.
xPosT.onMotionFinished = function() {

Total ActionScript Errors: 2 Reported Errors: 2


Any ideas why guys? Cheers in advance.

<"))))><

Edit: MX04 by the way.

Scope Trouble... Unregister/ Remove Object / Tween ?
Hi,

I hope somebody can help with the following problem.
I'm trying to make a powerpoint kind of projector:
- Main flash movie: works as a container to load different flash files.
reacts on the left and right arrow buttons to go to the next or previous movie, which is loaded in a movieClip.

- Several external swf files all exported from the same: slide.fla only adjusting xml node settings make the differences in text and pictures.
This works, but after loading into the container I use to show the images the tween of my images gets messed up. (Not in the first loaded movie, but sure after around the third)

Please can anybody look at my code and tell me what could be the problem?
I'm sure it has to do with the scope after loading into the container.fla, and all the objects having the same name, for the submovies. (exported from the same .fla)
Do I have to unregister/ remove these objects after usage - I think this might be it, but don't know how.

In the container.fla I already set:
clipLoader_mc._lockroot = true;
but this doesn't solve the problem.


Code:
/// **************************** ///
/// START TWEEN METHODS FOR SCREENS ///
/// **************************** ///
var mcl_obj:Object = new Object();
mcl_obj.onLoadInit = function(target_mc:MovieClip):Void {
target_mc._width = 500;
target_mc._height = 395;
target_mc._x = 500;
var distance:Number = 5;
var angleInDegrees:Number = 45;
var color:Number = 0x000000;
var alpha:Number = 75;
var blurX:Number = 7;
var blurY:Number = 7;
var strength:Number = 1;
var quality:Number = 3;
var inner:Boolean = false;
var knockout:Boolean = false;
var hideObject:Boolean = false;
var filter:DropShadowFilter = new DropShadowFilter(distance, angleInDegrees, color, alpha, blurX, blurY, strength, quality, inner, knockout, hideObject);
var filterArray:Array = new Array();
filterArray.push(filter);
target_mc.filters = filterArray;
var tween_target:Object = new Tween(target_mc, "_y", Back.easeInOut, Stage.height, 300, 1, true);
tween_target.onMotionFinished = function() {
intervalClearScreenId = setInterval(ClearScreen, 8000, counter);
};
screenCounter++;
//initiated on top of the page.
};
function ClearScreen():Void {
var tween_screen:Object = new Tween(mover_mc, "_x", Strong.easeInOut, mover_mc._x, 1250, 1, true);
tween_screen.onMotionFinished = function() {
if (screenCounter<screenMaxCount) {
ShowScreens();
} else {
screenCounter = 0;
ShowScreens();
}
clearInterval(intervalClearScreenId);
};
}
ShowScreens = function ():Void {
// Create a movie clip instance.
this.createEmptyMovieClip("mover_mc", getNextHighestDepth());
var img_mcl:MovieClipLoader = new MovieClipLoader();
img_mcl.addListener(mcl_obj);
// Load an image into the movie clip
img_mcl.loadClip(imageArray[screenCounter], mover_mc);
};
//load XML voor screens on the left:
function loadScreensXML(loaded) {
if (loaded) {
_rootNode = this.firstChild.childNodes[imageNodeNr].childNodes[0];
trace(_rootNode);
total = _rootNode.childNodes.length;
for (i=0; i<total; i++) {
//add images to imageArray:
imageArray[i] = _rootNode.childNodes[i].firstChild.nodeValue;
}
screenMaxCount = imageArray.length;
//initiated on top of the page
//Show the screens:
ShowScreens();
} else {
content = "file not loaded!";
}
}
xmlScreens = new XML();
xmlScreens.ignoreWhite = true;
xmlScreens.onLoad = loadScreensXML;
xmlScreens.load(urlImagesXML);
/// **************************** ///
/// END TWEEN METHODS FOR SCREENS ///
/// **************************** ///
I'm trying all day already to solve this so please can anybody help?
Thanks in advance!

HitTestPoint
I do not understand hitTestPoint, what does it exactly do?

Why does this code not work?
It won't hit...


ActionScript Code:
if (h.hitTestPoint(Ehelis[EheliNum].x, Ehelis[EheliNum].y, true)) {
trace("hit")
}

HitTestPoint?
Can you do a hitTestPoint on only half of an mc? eg, only to test if the players legs are touching the ground.

HitTestPoint Bug
I made this test file so you can see what I mean about this hitTestPoint() bug.

The area on the stage that is registering the "hit" is never in the same place as the visible MC that is used as the hit tester. IE the spot that results as true when rolled over is always some where off and to the right of the actual MC. Just move your mouse around the stage and you'll see what I mean. Things are not lining up. There is absolutely nothing else in the hit tested MC at all. No invisible assets within it etc... Just what you see.

I had it in a few classes before and I have tested it quite a bit and I always get the same thing.

Any thoughts?


the timeline based code:

ActionScript Code:
import flash.utils.*;

var _hitTestTimer:Timer = new Timer(50);
_hitTestTimer.addEventListener (TimerEvent.TIMER, hitTester);
_hitTestTimer.start ();

function hitTester (evt:Event) {
    //if (testMC.hitTestPoint(mouseY, mouseX, true)) {
    if (testMC.hitTestPoint(mouseY, mouseX, false)) {
        testMC.alpha = .5;
    } else {
        testMC.alpha = 1;
    }
}

HitTestPoint() Bug
I made this test file so you can see what I mean about this hitTestPoint() bug.
Heres the file swf online

The area on the stage that is registering the "hit" is never in the same place as the visible MC that is used as the hit tester. IE the spot that results as true when rolled over is always some where off and to the right of the actual MC. Just move your mouse around the stage and you'll see what I mean. Things are not lining up. There is absolutely nothing else in the hit tested MC at all. No invisible assets within it etc... Just what you see.

I had it in a few classes before and I have tested it quite a bit and I always get the same thing.

Any thoughts?




Heres the timeline code:








Attach Code

import flash.utils.*;

var _hitTestTimer:Timer = new Timer(50);
_hitTestTimer.addEventListener (TimerEvent.TIMER, hitTester);
_hitTestTimer.start ();

function hitTester (evt:Event) {
//if (testMC.hitTestPoint(mouseY, mouseX, true)) {
if (testMC.hitTestPoint(mouseY, mouseX, false)) {
testMC.alpha = .5;
} else {
testMC.alpha = 1;
}
}

HitTestPoint
I have this code so that when a spaceship goes through a blackhole it plays the spaceships moveiclip. This works fine on the first part of the code when the user just clicks the start button. However, i have put in a difficulty setting and when you change the difficulty setting the hittest doesn't work anymoreand there are no error messages. I have tried putting the blackHoles array in the difficulty function but nothing changes and i didn't really think this would make a difference as the easy function is already using the blackHoles array outside the difficulty function. Can anyone tell me whats wrong?







Attach Code

var blackHoles:Array = new Array();
function position(target) {
target.x = Math.random() * stage.stageWidth;
target.y = Math.random() * stage.stageHeight;
for (var i:uint=0; i<blackHoles.length; i++) {
if(target.hitTestObject(blackHoles[i])){
position(target);
return false;
}
}
}

startButton.addEventListener(MouseEvent.CLICK, startGame);
function startGame(evt:MouseEvent):void{
var moon = new Moon;
moon.x = 250;
moon.y = 320;
addChild(moon);
for(var i:int = 0; i < 10; i++)
{
var blackHole:BlackHole = new BlackHole();
blackHole +i;
blackHole.x = Math.random() * stage.stageWidth;
blackHole.y = Math.random() * stage.stageHeight;
position(blackHole);
blackHoles.push(blackHole);
addChild(blackHole);
}
stage.addEventListener(Event.ENTER_FRAME, hitTest);
function hitTest(evt:Event):void
{
for(var i:int = 0; i < blackHoles.length; i++)
{
if (spaceship.hitTestPoint(blackHoles[i].x, blackHoles[i].y, true))
{
spaceship.gotoAndPlay(1);
}
}
}

difficulty.addEventListener(MouseEvent.CLICK, chooseDifficulty);
function chooseDifficulty(evt:MouseEvent):void{
var easy:Easy = new Easy();
var normal:Normal = new Normal();
var hard:Hard = new Hard();
easy.x = 210;
easy.y = 260;
normal.x = 210;
normal.y = 300;
hard.x = 210;
hard.y = 340;
addChild(easy);
addChild(normal);
addChild(hard);
removeChild(startButton);
removeChild(difficulty);
removeChild(exit);


easy.addEventListener(MouseEvent.CLICK, chooseEasy);
function chooseEasy(evt:MouseEvent):void{
var moon = new Moon;
moon.x = 250;
moon.y = 320;
addChild(moon);
for(var i:int = 0; i < 5; i++)
{
var blackHole:BlackHole = new BlackHole();
blackHole +i;
blackHole.x = Math.random() * stage.stageWidth;
blackHole.y = Math.random() * stage.stageHeight;
position(blackHole);
blackHoles.push(blackHole);
addChild(blackHole);
}

stage.addEventListener(Event.ENTER_FRAME, hitTest);
function hitTest(evt:Event):void
{
for(var i:int = 0; i < blackHoles.length; i++)
{
if (spaceship.hitTestPoint(blackHoles[i].x, blackHoles[i].y, true));
{
spaceship.gotoAndPlay(1);
}
}
}
timer.start();
addChild(spaceship);
spaceship.x = 80;
spaceship.y = 80;
removeChild(easy);
removeChild(normal);
removeChild(hard);
removeChild(splashScreen);
}

























Edited: 12/30/2008 at 08:42:43 AM by g-rebel

HitTestPoint Help
I can't figure out hitTestPoint. I'm trying to make this map of the US and each state needs to do something when you mouse over the state, but the overlaps are killing me as movie clips are square and states are not. I'm new to AS3 and was hoping someone could help me out.

Help With HitTestPoint
Hi,

hitTestPoint works fine in my application until the application is scaled. I'm hoping that someone can explain where I've gone wrong. In the following details the 'source' is a sprite being dragged over the 'target'.

Display Hierarchy:
stage
frame [ frame.swf ]
content [ content.swf ]
source & target sprites

Hit Test Pseudo-code [ content.swf ]:
var pt:Point = source.parent.localToGlobal( new Point( source.x, source.y ) );
if( target.hitTestPoint( pt.x, pt.y, true ) )
{ ... }

Scaling Pseudo-code [ frame.swf ]:
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
...
scaleX = <computed scale>;
scaleY = <computed scale>;

Cheers!

HitTestPoint Problem
I am trying to create a space game where you have to fly around black holes. I have made a difficulty setting where easy has less black holes and hard has more. In creating the difficulty setting my hitTestPoint code has stopped working and i'm not sure why. Here is the code i am using -


Code:
difficulty.addEventListener(MouseEvent.CLICK, chooseDifficulty);
function chooseDifficulty(evt:MouseEvent):void{
var easy:Easy = new Easy();
var normal:Normal = new Normal();
var hard:Hard = new Hard();
easy.x = 210;
easy.y = 260;
normal.x = 210;
normal.y = 300;
hard.x = 210;
hard.y = 340;
addChild(easy);
addChild(normal);
addChild(hard);
removeChild(startButton);
removeChild(difficulty);
removeChild(exit);

easy.addEventListener(MouseEvent.CLICK, chooseEasy);
function chooseEasy(evt:MouseEvent):void{
for(var i:int = 0; i < 5; i++)
{
var blackHole:BlackHole = new BlackHole();
blackHole.name = "BlackHole" +i;
blackHole.x = Math.random() * stage.stageWidth;
blackHole.y = Math.random() * stage.stageHeight;
addChild(blackHole);
}
splashScreen.visible = false;
timer.start();
addChild(spaceship);
spaceship.x = 80;
spaceship.y = 80;
removeChild(easy);
removeChild(normal);
removeChild(hard);
}
}

stage.addEventListener(Event.ENTER_FRAME, hitTest)
function hitTest(evt:Event):void{
if (spaceship.hitTestPoint(blackHole.x, blackHole.y, true))
{
removeChild(spaceship);
}
}
Any ideas?

HitTestPoint Issues
Hi, I'm new to Flash and Actionscript, but I'm an experienced javascript developer, so I thought I'd jump straight in to AS3 by creating a side-scrolling game. I've hit a snag and was wondering if anyone could point me in the right direction. I've got a MovieClip named "man", who is an instance of my MoveCharacter class that I was hoping to use as a base class for movement, physics, and collision detection in any side-scrolling game. I'm using hitTestPoint to try to test a collision with walls of a level (Ob) that is made up of simple line-tool vector graphics. If the shapeFlag argument is set to true, no collisions with Ob are detected, and if shapeFlag is false, collisions are detected anywhere within the Ob MovieClip, so that the character simply won't move. My question is: how do I accurately test collisions against Ob?

MoveCharacter

Code:
package
{
import flash.events.*;
import flash.display.*;
import flash.ui.Keyboard;
import flash.geom.*;
import KeyPoll;
import Main;
import World;
import Ob;

public class MoveCharacter extends MovieClip
{
public var xspeed:Number = 0;
public var yspeed:Number = 0;
public var hitwalll:Boolean = false;
public var hitwallr:Boolean = false;
public var gravity:Number = 0;
public var jumping:Boolean = false;
public var running:Boolean = false;

public static var world:World;
public static var objects:Ob;
private var key:KeyPoll;

public function MoveCharacter()
{
this.addEventListener(Event.ADDED_TO_STAGE, onStageReady)
function onStageReady(e:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE, onStageReady);
trace("MoveCharacter defined and initialized");

key = new KeyPoll(stage);
objects = new Ob();
world = new World();
stage.addChild(world);
world.x = 0; world.y = 0;
stage.addChild(objects);
objects.x = 100.6; objects.y = -700.4;
stage.addEventListener(Event.ENTER_FRAME, moveAround);

function moveAround(event:Event):void
{
var pointtop:Point = new Point(x + (width / 2), y);
var pointbottom:Point = new Point (x + (width / 2), y + height);
var pointleft:Point = new Point (x, y + (height / 2));
var pointright:Point = new Point (x + width, y + (height / 2));

if (objects.hitTestPoint(pointright.x, pointright.y, false) == true)
{
hitwallr = true;
}
if (objects.hitTestPoint(pointleft.x, pointleft.y, false) == true)
{
hitwalll = true;
}
if(key.isDown(Keyboard.RIGHT))
{
trace("Right");
if (!hitwallr)
{
running = true;
x+=5;
world.x+=5;
trace(pointright);
}
trace(hitwallr);
scaleX = 1;
hitwallr = false;
}
if(key.isDown(Keyboard.LEFT)){
trace("Left");
if (!hitwalll)
{
running = true;
x-=5;
trace(pointleft);
}
trace(hitwalll);
scaleX = -1;
hitwalll = false;
}
if(key.isDown(Keyboard.UP))
{
trace("Up");
}
if(key.isDown(Keyboard.DOWN))
{
trace("Down");
}
}
}
}
}
}

HitTestPoint Problem
I am trying to create a space game where you have to fly around black holes. I have made a difficulty setting where easy has less black holes and hard has more. In creating the difficulty setting my hitTestPoint code has stopped working and i'm not sure why. I have attached the code i am using, can anyone help?








Attach Code

difficulty.addEventListener(MouseEvent.CLICK, chooseDifficulty);
function chooseDifficulty(evt:MouseEvent):void{
var easy:Easy = new Easy();
var normal:Normal = new Normal();
var hard:Hard = new Hard();
easy.x = 210;
easy.y = 260;
normal.x = 210;
normal.y = 300;
hard.x = 210;
hard.y = 340;
addChild(easy);
addChild(normal);
addChild(hard);
removeChild(startButton);
removeChild(difficulty);
removeChild(exit);

easy.addEventListener(MouseEvent.CLICK, chooseEasy);
function chooseEasy(evt:MouseEvent):void{
for(var i:int = 0; i < 5; i++)
{
var blackHole:BlackHole = new BlackHole();
blackHole.name = "BlackHole" +i;
blackHole.x = Math.random() * stage.stageWidth;
blackHole.y = Math.random() * stage.stageHeight;
addChild(blackHole);
}
splashScreen.visible = false;
timer.start();
addChild(spaceship);
spaceship.x = 80;
spaceship.y = 80;
removeChild(easy);
removeChild(normal);
removeChild(hard);
}
}

stage.addEventListener(Event.ENTER_FRAME, hitTest)
function hitTest(evt:Event):void{
if (spaceship.hitTestPoint(blackHole.x, blackHole.y, true))
{
removeChild(spaceship);
}
}

HitTestPoint Problem
I have some code that takes a movieclip called blackHole and places 10 instances of them randomly on the stage. I then want another movieclip called spaceship to collide with these instances. The problem is the spaceship movieclip only collides with one instance of the blackHole movieclip. Any ideas?









Attach Code

startButton.addEventListener(MouseEvent.CLICK, startGame);
function startGame(evt:MouseEvent):void{
var moon = new Moon;
moon.x = 250;
moon.y = 320;
addChild(moon);
for(var i:int = 0; i < 10; i++)
{
var blackHole:BlackHole = new BlackHole();
blackHole +i;
blackHole.x = Math.random() * stage.stageWidth;
blackHole.y = Math.random() * stage.stageHeight;
position(blackHole);
blackHoles.push(blackHole);
addChild(blackHole);
}
stage.addEventListener(Event.ENTER_FRAME, hitTest);
function hitTest(evt:Event):void
{
if (spaceship.hitTestPoint(blackHole.x, blackHole.y, true))
{
spaceship.gotoAndPlay(1);
}
}
timer.start();
addChild(spaceship);
spaceship.x = 80;
spaceship.y = 80;
removeChild(startButton);
removeChild(difficulty);
removeChild(exit);
removeChild(splashScreen);
}

HitTestPoint On Transparent PNG
Hey all,

So i have a transparent .png that is about 100px by 200px with a picture of a man in the middle.

I want to click on the man and only the man to have my function fire but it seems like if i click within the bounding box, the function still fires.

I'm using the hitTestPoint function that seems to say I can specify whether I want to do an alpha check or a shape check. Both of those options seem to do the same thing when I run it real time.

Any ideas?

Thanks!

HitTestPoint Problem
Hi. I have created a lunar lander game where you have to avoid blackholes and land on the moon. I have used hitTestPoint for the collision between the spaceship and the blackholes, this hitTest works fine but I have tried to add an difficulty setting where easy has less blackholes and hard has more. However, hitTestPoint doesn't work when you change the difficulty setting and i'm not sure why. It doesn't give an error, it just doesn't work. Here's my code -


Code:
var blackHoles:Array = new Array();
function position(target) {
target.x = Math.random() * stage.stageWidth;
target.y = Math.random() * stage.stageHeight;
for (var i:uint=0; i<blackHoles.length; i++) {
if(target.hitTestObject(blackHoles[i])){
position(target);
return false;
}
}
}

startButton.addEventListener(MouseEvent.CLICK, startGame);
function startGame(evt:MouseEvent):void{
moon.visible = true;;
for(var i:int = 0; i < 10; i++)
{
var blackHole:BlackHole = new BlackHole();
blackHole +i;
blackHole.x = Math.random() * stage.stageWidth;
blackHole.y = Math.random() * stage.stageHeight;
position(blackHole);
blackHoles.push(blackHole);
addChild(blackHole);
}
stage.addEventListener(Event.ENTER_FRAME, hitTest);
function hitTest(evt:Event):void
{
for(var i:int = 0; i < 10; i++)
{
if (spaceship.hitTestPoint(blackHoles[i].x, blackHoles[i].y, true))
{
spaceship.gotoAndPlay(1);
}
}
}

function chooseDifficulty(evt:MouseEvent):void{
var easy:Easy = new Easy();
var normal:Normal = new Normal();
var hard:Hard = new Hard();
easy.x = 210;
easy.y = 260;
normal.x = 210;
normal.y = 300;
hard.x = 210;
hard.y = 340;
addChild(easy);
addChild(normal);
addChild(hard);
removeChild(startButton);
removeChild(instructions);
removeChild(difficulty);
removeChild(exit);

easy.addEventListener(MouseEvent.CLICK, chooseEasy);
function chooseEasy(evt:MouseEvent):void{
var moon = new Moon;
moon.x = 250;
moon.y = 320;
addChild(moon);
for(var i:int = 0; i < 5; i++)
{
var blackHole:BlackHole = new BlackHole();
blackHole +i;
blackHole.x = Math.random() * stage.stageWidth;
blackHole.y = Math.random() * stage.stageHeight;
position(blackHole);
blackHoles.push(blackHole);
//blackHoles.push(moon);
//blackHoles.push(gameTimer_tb);
//blackHoles.push(lives_tb);
//blackHoles.push(spaceship_mc);
addChild(blackHole);
}

stage.addEventListener(Event.ENTER_FRAME, hitTest);
function hitTest(evt:Event):void
{
for(var i:int = 0; i < 5; i++)
{
if (spaceship.hitTestPoint(blackHoles[i].x, blackHoles[i].y, true));
{
spaceship.gotoAndPlay(1);
}
}
}
I then have a normal setting which is 10 blackHoles and a hard setting which is 15 blackholes, coded in the same way. Can anyone help?

HitTestPoint Vs Array Read
I was wondering if some one could answer the folllowing question i have. How much slower on the cpu would doing a hitTestPoint (1 point to one very large vector shape lets say 2500*2500) than reading a position value in a map array.

Is using hitTestPoint on a complex shape much slower than a simple shape please enlighten me on this critical subject thanks in advance.

Bounce Effects With HitTestPoint
im building a flash car game where if u hit the sides of the buildings you bounce off
my problem is that sometimes you get stuck in the walls and it doesnt bounce at all

heres my bounce code

Code:
public function moveCar(timeDiff:Number) {


// get current position
var carPos:Point = new Point(gamesprite.car.x, gamesprite.car.y);

// calculate change
var carAngle:Number = gamesprite.car.rotation;
var carAngleRadians:Number = (carAngle/360)*(2.0*Math.PI);
var carMove:Number = speed*timeDiff;
var dx:Number = Math.cos(carAngleRadians)*carMove;
var dy:Number = Math.sin(carAngleRadians)*carMove;

// see if car is NOT on the road
if (!gamesprite.road.hitTestPoint(carPos.x+dx+gamesprite.x, carPos.y+dy+gamesprite.y, true)) {
gamesprite.car.y = gamesprite.side.y;
gamesprite.car.x = gamesprite.side.x;


// see if car is on the side
//bounce off
if (gamesprite.side.hitTestPoint(gamesprite.car.x, gamesprite.car.y, true)) {
gamesprite.y = (Math.sin(gamesprite.car.rotation * 0.018) * speed) * 5 / -1;
gamesprite.x = speed * Math.cos(gamesprite.car.rotation * 0.018) * 4;
speed = 0 - speed * bounce;

}
}

// set new position of car
gamesprite.car.x = carPos.x+dx;
gamesprite.car.y = carPos.y+dy;
}
heres a copy of the game
here

can someone help me out plz

thanks

HitTestPoint Against Global Variables?
I'm storing all variables that I want to be global--accessible throughout the project--in a separate class in a static Object variable. This seems to work fine except for one problem.

I have a Sprite that is added to the stage on frame 1 of my flash file and then passed to my GlobalVarContainer. A ball with a separate class definition is later added and interacts with the Sprite.

The problem is that the ball's class actionscript is using hitTestPoint with the shapeFlag Boolean set to true to detect a collision with aforementioned Sprite that is stored in the static Object variable.

But the shapeFlag is not working and the ball is colliding with the bounding box of the sprite.

Here is the code from my Ball class that references the object:


Code:
if (GlobalVarContainer.vars.terrainium.hitTestPoint(spot_x, spot_y, true)){
Can anyone tell me why it is not detecting a pixel-level collision but uses a bounding box despite the shapeFlag Boolean being set to true?

I will elaborate more on my code if necessary. Thanks for your help!

HitTestPoint On Objects Which Are Not On The Displaylist
I want to do a hitTestPoint on an object which isn't on the displaylist. When setting the shapeFlag to false (default), this will work without any problems. As soon as this is set to true, it alway's returns false.
Is this the behaviour we should expect, or is this some kind of flash bug? Does anyone know a workaround?

As soon as I add the displayObject to the displaylist this will work fine. But it's simply not an option to have it rendered visually, cause of performance reasons.

HitTestPoint And Custom Method
Hi,

I have some little glitches using hitTestPoint, On canvas Shapes laying on an other large canvas.


ActionScript Code:
// on mouse down
// 'This' is the board canvas

trace('point ', this.contentMouseX, this.contentMouseY);
                             
trace(currentShape.hitTestPoint(this.contentMouseX, this.contentMouseY, true))

trace('curshape', currentShape.x, currentShape.y, currentShape.x+currentShape.width,  currentShape.y+currentShape.height);

cruShape is the previously drawn shape.

> point 342, 252
> false
> curShape, 320,220,700,360

We agree that 342, 252 is inside the shape but why does the hitpoint test fails? Somethind to do with the coordinates of curShape it uses? how can i tell him to use contentMouseX,Y ?


Thanks
>

MovieClip Control / HitTestPoint...I Think
OK, so, I want to make a movieclip play forward and backward based on whether or not the hit Test Point returns true or false, right? Keep in mind, I'm extremely stupid, so I am not going to intuitively construct my AS 3 code correctly.

I used to use this:

on ClipEvent (enterFrame){

if (this.hitTest (root.xmouse, root.ymouse, true)) {

this.nextFrame ();

}else{

this.prevFrame ();
}
}

But, of course, that was too easy. Now, with AS 3, they've deprecated all my code so I have to use event handlers, import classes, blah blah blah. The compiler is treating me like crap, complaining about everything I do...reminds me of my ex wife.

Anyway, it's not working. Is there anyone who could tell me the simple code to use to test if the mouse is over my MovieClip and play clip forward and backward? I can't imagine it's so difficult, but I've been at this for 3 days to no avail. Remember, I'm not a programmer, just a stupid, unemployed carpenter, so please don't assume I can
just put the rest of the code in...I'm sure I can't. I've been trying to do that for many many hours.

Thanks!

Bounce Effect Using HitTestPoint
im building a flash car game where if u hit the sides of the buildings you bounce off
my problem is that sometimes you get stuck in the walls and it doesnt bounce at all

heres my bounce code

Code:
public function moveCar(timeDiff:Number) {


// get current position
var carPos:Point = new Point(gamesprite.car.x, gamesprite.car.y);

// calculate change
var carAngle:Number = gamesprite.car.rotation;
var carAngleRadians:Number = (carAngle/360)*(2.0*Math.PI);
var carMove:Number = speed*timeDiff;
var dx:Number = Math.cos(carAngleRadians)*carMove;
var dy:Number = Math.sin(carAngleRadians)*carMove;

// see if car is NOT on the road
if (!gamesprite.road.hitTestPoint(carPos.x+dx+gamesprite.x, carPos.y+dy+gamesprite.y, true)) {
gamesprite.car.y = gamesprite.side.y;
gamesprite.car.x = gamesprite.side.x;


// see if car is on the side
//bounce off
if (gamesprite.side.hitTestPoint(gamesprite.car.x, gamesprite.car.y, true)) {
gamesprite.y = (Math.sin(gamesprite.car.rotation * 0.018) * speed) * 5 / -1;
gamesprite.x = speed * Math.cos(gamesprite.car.rotation * 0.018) * 4;
speed = 0 - speed * bounce;

}
}

// set new position of car
gamesprite.car.x = carPos.x+dx;
gamesprite.car.y = carPos.y+dy;
}
heres a copy of the game
here

can someone help me out plz

thanks

Help With HitTestPoint And Bounce Objects
im building a flash car game where if u hit the sides of the buildings you bounce off
my problem is that sometimes you get stuck in the walls and it doesnt bounce at all

heres my bounce code
Code:

public function moveCar(timeDiff:Number) {

         
         // get current position
         var carPos:Point = localToGlobal(new Point(gamesprite.car.x, gamesprite.car.y));
         
         // calculate change
         var carAngle:Number = gamesprite.car.rotation;
         var carAngleRadians:Number = (carAngle/360)*(2.0*Math.PI);
         var carMove:Number = speed*timeDiff;
         var dx:Number = Math.cos(carAngleRadians)*carMove;
         var dy:Number = Math.sin(carAngleRadians)*carMove;
                        
         
         // see if car is NOT on the road
         if (gamesprite.road.hitTestPoint(carPos.x+dx+gamesprite.x, carPos.y+dy+gamesprite.y, true)) {
               gamesprite.y =  (Math.sin(gamesprite.car.rotation * 0.018) * speed) * 6 / -1;
               gamesprite.x = speed * Math.cos(gamesprite.car.rotation * 0.018) * 4;
               speed = 0 - speed * bounce;
               gamesprite.car.y = gamesprite.side.y;
               gamesprite.car.x = gamesprite.side.x;
               
         
            // see if car is on the side
            /*//bounce off
            if (gamesprite.side.hitTestPoint(carPos.x+dx+gamesprite.x, carPos.y+dy+gamesprite.y, true)) {
               gamesprite.y =  (Math.sin(gamesprite.car.rotation * 0.018) * speed) * 6 / -1;
               gamesprite.x = speed * Math.cos(gamesprite.car.rotation * 0.018) * 4;
               speed = 0 - speed * bounce;
               
            }*/
         }
         
         // set new position of car
         gamesprite.car.x = carPos.x+dx;
         gamesprite.car.y = carPos.y+dy;
      }
i can supply more code if necessary

the problem im having is that sometimes it doesnt bounce off. it will just go right into the other object and get stuck
not sure where i went wrong maybe someone can help

heres a copy of the game
http://danberko.com/adam/gameLevel1.swf

can someone help me out plz

thanks

Weird Behavior Of HitTestPoint And RemoveChild()
Hi
I am trying to drag and drop multiple instances of UILoader on stage. My goal is if user puts UILaoder partially on top of other UILoader , it should just stay on top of it. If user puts on top of UILoader more than the central point of other UILoader, the other UILoader will change the color of its border and on mouse release gets replaced by the placed UILoader.
I am successful in getting all this but I am getting inconsistent results as an output. Sometimes I have to put exactly on top of other UILoader to replace it and sometimes I just touch the UILoader and it shows red border and gets replaced. I used the logic of calculating the center of rectangle(my UILoader container) and use hitPoint method, and as soon as dragged UILoader hits the calculated center of UILoader, it gets replaced.
Please help me out in where I am messing things up.Any better idea than this will also be highly appreciated.
( Following is the function which is telling my UILoader to replace of stopDrag.)
Thanks a lot
Anuj
/*************************CODE***************/
function dropUILoader(e:MouseEvent):void
{

if(e.target is UILoader)
{
var myUILoader:UILoader = e.target as UILoader;

if (mouseY<746)
{
myUILoader.stopDrag();
//Putting video on top of already existed videos
var trackChild:Number=container.getChildIndex(myUILoad er);
var childContainerisplayObject= container.getChildAt(trackChild);
for (var z:Number=0; z<=container.numChildren-1; z++)
{
var restChildisplayObject=container.getChildAt(z);

if (childContainer!=restChild)
{
if(restChild is UILoader)
{
var cRC:UILoader=restChild as UILoader;
var regcRCx:Number=cRC.x;
var regcRCy:Number=cRC.y;

var regcRCWidth:Number=cRC.width;
var regcRCHeight:Number=cRC.height;

if(childContainer.hitTestPoint(((regcRCx+regcRCWid th)/2),(regcRCy+regcRCHeight)/2)==true)
{
trace("Totally Hit");
container.removeChild(cRC);
}
else
{
trace("Partially Hit");
}
}
}
}
}
else
{
myUILoader.unload();
container.removeChild(myUILoader);
}
}
}

HitTestPoint With Nested Movie Clips?
Hi. I'm trying to make a top-down racing game, and I'm having some trouble with hitTestPoint.

I'm trying to detect a collision between each of the corners of the car (a movie clip) and the track wall (a long curvy shape inside a movie clip).

I have hitTestPoint working fine between the wall and the registration of the car movie clip (which is in the center), but I can't get it to work between the wall and a corner of the car.

I tried two things: First, I tried putting a movie clip at each corner inside the car movie clip and doing a hit test between the corner movie clip and the wall, but when I did that, it didn't detect a collision or do anything.

I also tried adding to the car.x and car.y in hitTestPoint to offset the spot it was checking, but it did that relative to the stage, not relative to the car movie clip like I need (because the car's rotation changes).

Does anyone have any idea how to do this? Is it just impossible to do hitTestPoint within nested movie clips? Am I just doing it all wrong? Any help is appreciated.

Weird Behavior Of HitTestPoint And RemoveChild()
Hi
I am trying to drag and drop multiple instances of UILoader on stage. My goal is if user puts UILaoder partially on top of other UILoader , it should just stay on top of it. If user puts on top of UILoader more than the central point of other UILoader, the other UILoader will change the color of its border and on mouse release gets replaced by the placed UILoader.
I am successful in getting all this but I am getting inconsistent results as an output. Sometimes I have to put exactly on top of other UILoader to replace it and sometimes I just touch the UILoader and it shows red border and gets replaced. I used the logic of calculating the center of rectangle(my UILoader container) and use hitPoint method, and as soon as dragged UILoader hits the calculated center of UILoader, it gets replaced.
Please help me out in where I am messing things up.Any better idea than this will also be highly appreciated.
( Following is the function which is telling my UILoader to replace of stopDrag.)
Thanks a lot
Anuj
/*************************CODE***************/
function dropUILoader(e:MouseEvent):void
{

if(e.target is UILoader)
{
var myUILoader:UILoader = e.target as UILoader;

if (mouseY<746)
{
myUILoader.stopDrag();
//Putting video on top of already existed videos
var trackChild:Number=container.getChildIndex(myUILoad er);
var childContainerisplayObject= container.getChildAt(trackChild);
for (var z:Number=0; z<=container.numChildren-1; z++)
{
var restChildisplayObject=container.getChildAt(z);

if (childContainer!=restChild)
{
if(restChild is UILoader)
{
var cRC:UILoader=restChild as UILoader;
var regcRCx:Number=cRC.x;
var regcRCy:Number=cRC.y;

var regcRCWidth:Number=cRC.width;
var regcRCHeight:Number=cRC.height;

if(childContainer.hitTestPoint(((regcRCx+regcRCWid th)/2),(regcRCy+regcRCHeight)/2)==true)
{
trace("Totally Hit");
container.removeChild(cRC);
}
else
{
trace("Partially Hit");
}
}
}
}
}
else
{
myUILoader.unload();
container.removeChild(myUILoader);
}
}
}

Moving A Dynamically Added MC On A HitTestPoint
Hi,
I was reading through one of the tutorials from kirupa found here http://www.kirupa.com/developer/flas...es_AS3_pg2.htm

I got a lot out of it =]
but when i tried modifying the code to add a hitTest on it, it became "weird"
here is my .as file
package {
import flash.display.*;
import flash.events.*;
import flash.geom.Point;

public class Sq extends MovieClip {
var radians =0;
var speed =0;
var radius =0;
var randomValue=0;

public function Sq() {
speed =.01+.5*Math.random();
radius =2+10*Math.random();
randomValue= Math.random()*1;

this.x = Math.random()*550;
this.y = Math.random()*400;
this.rotation = Math.random()*360;
this.scaleX = this.scaleY = randomValue;
this.alpha = 1-randomValue;
this.addEventListener(Event.ENTER_FRAME, rotateSq);
}
function rotateSq(e:Event) {
if (this.hitTestPoint(mouseX,mouseY,true)) {
radians+=speed;
//trace("test works");
this.x+=Math.round(radius*Math.cos(radians));
this.y+=Math.round(radius*Math.sin(radians));
}else{
trace("nope");
}
}
}
}

the effect i'm trying to accomplish is when the user rolls over one of the MC's added
by the following function inside the .fla

function AddSq() {
for (var i:int =0; i<50; i++) {
var newSq:Sq = new Sq();
this.addChild(newSq);
}
}
AddSq();

is that the MC(which is a square) starts moving in a circle. but it seems that the hit area is in a different location and the square is in another.

is there something i'm doing wrong?
Thanks!

Other Ways Of Collision Detection Other Than HitTestPoint/Object
Hello all,

I'm way stuck here. The thing I'm trying to do is to detect collision with one object to another. I've tried using hitTestObject and also tried to use intersect by creating rectangles around the objects and testing for intersecting. Either works great as long as there is only object near the sprite I am controlling.

BUT, I have 82 objects on the screen and some of the objects are clustered (but not overlapping). When I move my sprite to the clusters, it detects the collision from an object that is defined sooner within the loop as I check each item in my array. (not sure how else to put that.) Essentially the detection is found is determined by which object is tested first for collision. For example:

If we had objects X, Y, Z and S was the sprite. Given this format:

X Y Z

and the letter 'S' is right under the Y.

Upon testing to see which letter was closest, you'd think that Y would be detected over any of the other letters. (Assume the letters are on rectangular shaped tile too). Each letter is stored into an array and upon collision detection, it's looped thru to test collision detection. Because X is in the array sooner (position wise), it tests as true and the result i get from flash is, the closest letter is X, not Y.

hitTestObject seems to be unreliable in the case of many many objects all around. Is there any way I can detect a collision?

Any hints are appreciated,
-m

Major Slowdown From Multiple Enemies In Game.. (hitTestPoint?)
I'm trying to create a game involving enemies that spawn from the ceiling and fall onto platforms. From their they walk to the end of their platform and fall, and then turn around, repeating the process. This involves a few for loops (some double), and hitTestPoint tests.

There is about 70 platforms on screen to which each enemy is being collision checked against at all times. I realize this is a lot, but I didn't think it would be near enough to slow the game down completely.

As a test, my code currently spawns 30 enemies onscreen, which is a lot but isn't too unrealistic in comparison to what I need. Once at least 3 enemies get on screen, things start to slow down a lot. Especially when an enemy is in freefall (which is weird considering I believe that is when less calculations occur).

I have posted example code, and attached the project itself for more detail.

I keep getting too discouraged when I encounter problems like this and stop my projects.. so I hope this is easy to resolve.


Code:
public function tick(event:TimerEvent){
var i:int;

for(i=0;i<enemyList.length;i++){
//trace(enemyList[i].vy+" "+enemyList[i].vx);
enemyList[i].vy+=gravity;

if(enemyList[i].onGround){
if( Math.floor((enemyList[i].y-(enemyList[i].height/2)) / gridSize) % 2 == 0) enemyList[i].direction=1;
else enemyList[i].direction=-1;
enemyList[i].walk();
}
else enemyList[i].falling();

var collision=enemyCollisionFloor(enemyList[i]);
if(collision != -1){
//trace(collision);
enemyList[i].y = collision;
enemyList[i].vy=0;
}
if(enemyList[i].vy==0) enemyList[i].onGround=true;
else enemyList[i].onGround=false;

enemyList[i].applyFriction(0.8);
enemyList[i].updatePos();
}
}

...

public function enemyCollisionFloor(enemy:Enemy):int{
var i:int;
var p:int;
var r:int;
for(i=0;i<groundList.length;i++){
for(p=1;p<=enemy.vy;p++)
//for(r=0;r<enemy.width;r++)
if(groundList[i].hitBox.hitTestPoint(enemy.x+enemy.vx,enemy.y+p,false) ||
groundList[i].hitBox.hitTestPoint(enemy.x+(enemy.width/2)+enemy.vx,enemy.y+p,false) ||
groundList[i].hitBox.hitTestPoint(enemy.x+(enemy.width)+enemy.vx,enemy.y+p,false)){
//trace("hitbox y: "+(groundList[i].y+groundList[i].hitBox.y)+" vy: "+vy+" enemy y: "+enemy.y+" collision y: "+(enemy.y+p));
return groundList[i].y+groundList[i].hitBox.y;
}
}
return -1;
}

Tween Class: Can One Tween More Than One Property Using The Same Tween
I want to scale both the _xscale and the _yscale properties of a clip, using a single execution of the Tween Class. See example below:


Code:
import mx.transitions.Tween;
var myTween:Tween = new Tween(myMovieClip_mc, "_xscale", Strong.easeOut, myMovieClip_mc._xscale, 300, 5, false);

Since one property at a time must be passed as a string to the constructor, I tried the following code, but it does not work quite as flawless as I expected:


Code:
myTween.onMotionChanged = function() {
//trace( this.position );
myMovieClip_mc._yscale += (300 - myMovieClip_mc._yscale)/12;
};
Any suggestions?

Using Stop(); On A Shape Tween Of A Swapped Movie Clip Symbol Within A Motion Tween
Thanks a lot for your time. I'm new to actionscript, and language syntax and I never really got along to begin with so I appreciate any help in the matter.

Basically the title says it all - I made a motion tween in the main scene, made a movie clip symbol (to shape tween a gradient) and added a stop(); inside the gradient-tweened-symbol. I then swapped the movie clip symbol with the motion tween in the main scene, and got exactly the effect I wanted (the item moved, then tweened itself) but the stop(); seems to have no effect.

I know this looks like one of those "that idiot didn't google before posting" questions, but I've been looking for about a half hour with different permutations of stop, doesn't work, actionscript, and flash, and I haven't found anything that seems to target this problem specifically.

If you've got any idea what's going wrong, please feel free to respond or show me how to better seek help on my own. Thanks again.

Tween Class If Moved Mc Passed Point Start Another Tween
Hey Actionscript Gurus

Now I am using the Tween Class to move some boxes in my movie, now I can move the first mc and then another mc after the first tween has finished with onMotionFinished but I was hoping someone could help with how do I start the second tween when the first mc has passed a certain _x coordinate.

ie starting the second mc moving while the first tween is still moving.

I am trying to do a intro loader for my front page controlling around 7 boxes. So I need to repeat this a few times.

Regs,
Jacko

Tween Class If Moved Mc Passed Point Start Another Tween
Hey Kirupa Flash Gurus

Now I am using the Tween Class to move some boxes in my movie, now I can move the first mc and then another mc after the first tween has finished with onMotionFinished but I was hoping someone could help with how do I start the second tween when the first mc has passed a certain _x coordinate.

ie starting the second mc moving while the first tween is still moving.

Regs,
Jacko

Laco Tween Engine Versus Flash Native Tween
i am wondering if there is a way to put a delay (seconds) on the flashs' native tween class like you can on the laco tween engine... such as

Code:
#include "lmc_tween.as"
my_mc.tween("_x",100,1,"easeOutStrong",1.5,callbackFunction)
where "1.5" is would be the one and a half second delay before the tween starts. this is very useful to me because i dont have to use a callback function or an onMotionFinished function to start a new tween.

thanks in advance to anyone who can teach me

-frankf

Tween Class Scaling Breaks Motion Tween?
I have a movie clip which uses a motion guide to animate the entry (and eventually the exit) of a bunch of other movie clips. These smaller clips contain buttons, and animate on rollOver and rollOut using the following code:


Code:
on(rollOver) {
this.swapDepths(2);
ParentxScale = new mx.transitions.Tween(this, "_xscale", mx.transitions.easing.Back.easeOut, this._xscale, 100/.6, .5, true);
ParentyScale = new mx.transitions.Tween(this, "_yscale", mx.transitions.easing.Back.easeOut, this._yscale, 100/.6, .5, true);
play();
}
on(rollOut) {
ParentxScale = new mx.transitions.Tween(this, "_xscale", mx.transitions.easing.Bounce.easeOut, this._xscale, 100, .5, true);
ParentyScale = new mx.transitions.Tween(this, "_yscale", mx.transitions.easing.Bounce.easeOut, this._yscale, 100, .5, true);
stop();
}
However, once an object has been moused over, it doesn't exit with the others. Any ideas why it seems to "fall off the track" of the motion guide?

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