Hit Detection on array

Hi i have a snake game, that after time loads sprites in an array to make the snake grow. Just wondering how i would go about adding a hit so when the head of the snake hits the body something happens. Below is the full document class code. Any pointers to what type of code would be massively helpful.
<code>
package {
import flash.display.Sprite;
import flash.events.KeyboardEvent;
import flash.events.TimerEvent;
import flash.ui.Keyboard;
import flash.utils.Timer;
import flash.display.MovieClip;
import flash.utils.getTimer;
import flash.text.TextField;
import flash.events.Event;
[SWF(width='430', height='430', frameRate='30')]
public class Snake extends MovieClip{
private const SPEED :uint = 25;//lower = faster
private const snakeAttach :uint = 400;//lower = faster
private const count:         uint = 10;
private const DIM :int = 50; //keep this number uneven to have the snake starting in the middle
private const INITIAL_SIZE :int = 3; //keep this lower then DIM/2
private var stopped :Boolean;
private var left :Boolean;
private var right :Boolean;
private var up :Boolean;
private var down :Boolean;
private var size :Number;
private var food :Sprite;
private var tmr :Timer;
private var count1          :Timer;
private var addSnake :Timer;
private var curI :Number;
private var curJ :Number;
private var snake :Array;
private var grid :Array;
private var sp               :Sprite;
private var _start:uint;
public var myTextBox:TextField = new TextField();
public function Snake(){
addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
private function onAddedToStage(event:Event):void {
removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
stage.addEventListener(KeyboardEvent.KEY_DOWN,changeDir);
size = stage.stageWidth / DIM; //change grid size
curI = curJ = Math.floor(DIM * 0.5); //change grid size
initSnake();
fillGrid();
addTimer();
addChild(myTextBox);
count1 = new Timer(count);
count1.addEventListener(TimerEvent.TIMER,stopWatch);
count1.start();
addSnake = new Timer(snakeAttach);
addSnake.addEventListener(TimerEvent.TIMER,placeFood);
addSnake.start();
tmr = new Timer(SPEED);
tmr.addEventListener(TimerEvent.TIMER,move);
tmr.start();
private function stopWatch(event:TimerEvent):void{
myTextBox.text = (count1.currentCount / 100).toString();
public function addTimer():void{ //timer
var myTextBox:TextField = new TextField();
addChild(myTextBox);
private function fillGrid():void{  //grid
grid = Make2DArray();
for (var i:uint = 0; i < DIM; i++){
for (var j:uint = 0; j < DIM; j++){
var sp:Sprite = new Sprite();
sp.graphics.beginFill(0xD7E0FC);
sp.graphics.lineStyle(1,0xF5F5F5);
sp.graphics.drawRect(0, 0, size  - 1, size - 1);
sp.x = i * size;
sp.y = j * size;
addChild(sp);
grid[i][j] = sp;
private function Make2DArray():Array{   //for the grid
var a:Array = new Array(DIM);
for(var i:uint = 0; i < a.length; i++){
    a[i] = new Array(DIM);
return a;
private function initSnake():void{ //initialises the snake
var center:Number = Math.floor(DIM * 0.5) * size;
snake = new Array(INITIAL_SIZE);
for (var i:uint = 0; i < INITIAL_SIZE; i++){
var sp:Sprite = makeItem();      //adds a body part of makeItem
sp.x = center;
sp.y = center + i * size;
addChild(sp); //adds to the stage
snake[i] = sp;  //sets the index to one
snake.reverse();
private function makeItem(c:uint = 0):Sprite{  //graphics for item
var s:Sprite = new Sprite();
s.graphics.beginFill(c);
s.graphics.lineStyle(2,0x3800E0);
s.graphics.drawRect(0, 0, size, size);
return s;
private function placeFood(event:TimerEvent):void{  
var rndI:uint = Math.floor(Math.random() * DIM);  //sets a random integer based on the the floor
var rndJ:uint = Math.floor(Math.random() * DIM);
var rndX:Number = grid[rndI][rndJ].x; // sets a grid position for the food item to go
var rndY:Number = grid[rndI][rndJ].y;
if (food != null) removeChild(food);  //if there is food on the grid removes the food from the board
food = makeItem(Math.random() * 0xFFFFFF);// random color
food.x = rndX;
food.y = rndY;
addChild(food); //adds the food to the board
for (var i:uint = 0; i < snake.length; i++){
if (rndY == snake[i].y && rndX == snake[i].x){
private function move(e:TimerEvent):void{
if (left){
curI -= 1;
}else if (right){
curI += 1;
if (up){
curJ -= 1;
}else if (down){
curJ += 1;
if (left || right || up || down){
var s:Sprite = makeItem();
if (curI > DIM - 1) curI = 0;
if (curJ > DIM - 1) curJ = 0;
if (curI < 0) curI = DIM - 1;
if (curJ < 0) curJ = DIM - 1;
s.x = grid[curI][curJ].x;
s.y = grid[curI][curJ].y;
addChild(s);
snake.push(s);
if (Math.floor(s.x) == Math.floor(food.x) && Math.floor(s.y) == Math.floor(food.y) ){
else if((tmr.currentCount % 3) > 0) { removeChild(snake[0]); snake.shift(); }
private function changeDir(e:KeyboardEvent):void{
if(e.keyCode == Keyboard.LEFT) {if (!right){left = true;  up = false; down = false; right = false;}}
if(e.keyCode == Keyboard.UP) {if (!down) {left = false; up = true;  down = false; right = false;}}
if(e.keyCode == Keyboard.RIGHT) {if (!left) {left = false; up = false; down = false; right = true;}}
if(e.keyCode == Keyboard.DOWN) {if (!up) {left = false; up = false; down = true;  right = false;}}
} </code>
thanks

ive added it to the move function and called it in but im getting this error :
                    TypeError: Error #2007: Parameter child must be non-null.
                     at flash.display::DisplayObjectContainer/removeChild()
                     at Snake/move()
                    at flash.utils::Timer/_timerDispatch()
                     at flash.utils::Timer/tick()
Heres the code that ive changed -
private function move(e:TimerEvent):void{
if (left){
curI -= 1;
}else if (right){
curI += 1;
if (up){
curJ -= 1;
}else if (down){
curJ += 1;
if (left || right || up || down){
var s:Sprite = makeItem();
if (curI > DIM - 1) curI = 0;
if (curJ > DIM - 1) curJ = 0;
if (curI < 0) curI = DIM - 1;
if (curJ < 0) curJ = DIM - 1;
s.x = grid[curI][curJ].x;
s.y = grid[curI][curJ].y;
addChild(s);
checkForHits();
if (Math.floor(s.x) == Math.floor(food.x) && Math.floor(s.y) == Math.floor(food.y) ){
else if((tmr.currentCount % 3) > 0) { removeChild(snake[0]); snake.shift(); }
private function checkForHits():void {
for(var i:int=1;i<snake.length;i++){
if(snake[0].hitTestObject(snake[i])){
trace("hit")

Similar Messages

  • Problem is detected with Array : 01

    I was backing up my server when it suddenly turned off. When it restarted it showed a critical error message saying "Problem is detected with Array : 01".
    Windows tried starting and kept rebooting so I just turned it off.
    When I launch the RAID utility I clearly see that the drive 02:01 seems ok but the other one is marked as "failed orisconnected" (it is connected ans spinning).
    This is the spec: On the server I have windows 2012R2 installed on two HD 1TB on RAID1.
    I habe an unused NAS, so I decided to create an iSCSI drive as a Target, and run the windows backup utility to do a Full Backup on it.hat may I have done wrong and how could I resolve this issue?
    This clearly is related to the windows backup utility since this server was working fine until then.
    Thanks.

    Hi,
    The issue could be due to that one of the two drive is failed in the RAID 1. You need to replace the failed drive and rebuild the array automatically.
    Best Regards,
    Mandy 
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

  • Hit detection between a line and a UIView?

    Hi all,
    I'm trying to figure out if a UIView I've got on the screen is intersecting a line I'm drawing.
    Here's the code for drawRect:
    -(void)drawRect:(CGRect)rect
    // Get the current graphics context and clear it
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextClipToRect(ctx, CGRectMake(0, 0, 240, 320));
    CGContextClearRect(ctx, rect);
    // The line style
    CGContextSetLineWidth(ctx, 3.0);
    CGContextSetLineCap(ctx, kCGLineCapRound);
    CGContextSetRGBStrokeColor(ctx, 1.0, 1.0, 1.0, 1.0);
    // Create the line
    CGContextMoveToPoint(ctx, source.x, source.y);
    CGContextAddLineToPoint(ctx, dest.x, dest.y);
    // Draw the line
    CGContextDrawPath(ctx, kCGPathStroke);
    CGContextStrokePath(ctx);
    That draws a line from and to wherever I need it, but when I draw it over a UIView that's already on the screen, I need to know if the centre point of the UIView is on that line. So, if you have a line going from 0,0 to 10,10, you have points at 1,1 2,2 3,3 ... 10,10. If the centre point of the UIView is at, say, 3,3, it would be on that line.
    I've seen use of the CGContextPathContainsPoint method, but I can't get it working - my line doesn't draw. Here's the code for drawRect:
    -(void)drawRect:(CGRect)rect
    // Get the current graphics context and clear it
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextClipToRect(ctx, CGRectMake(0, 0, 240, 320));
    CGContextClearRect(ctx, rect);
    // The line style
    CGContextSetLineWidth(ctx, 3.0);
    CGContextSetLineCap(ctx, kCGLineCapRound);
    CGContextSetRGBStrokeColor(ctx, 1.0, 1.0, 1.0, 1.0);
    // Create the path
    CGMutablePathRef linePath = CGPathCreateMutable();
    // Move to the source point and add a line to the destination point
    CGPathMoveToPoint(linePath, NULL, source.x, source.y);
    CGPathAddLineToPoint(linePath, NULL, dest.x, dest.y);
    // Draw the line
    CGPathDrawingMode(kCGPathStroke);
    CGContextDrawPath(ctx, kCGPathStroke);
    CGContextStrokePath(ctx);
    // Save the graphics state before doing the hit detection
    CGContextSaveGState(ctx);
    CGPathRef path = linePath;
    CGContextAddPath(ctx, path);
    if(CGContextPathContainsPoint(ctx, baddie, kCGPathStroke)) {
    NSLog(@"Yes");
    CGContextRestoreGState(ctx);
    I'm clearly doing something wrong here, but I can't quite figure it out.
    Any help much appreciated!

    I'm tearing my hair out with this. This is simple maths!!! Every point I put into the formula works fine, but when it's in code it fails. I think it's something to do with the frame I'm using...
    This is set in the init method:
    CGRect frame = CGRectMake(40.0, 60.0, 240.0, 320.0);
    The source and destination of the line I'm drawing, and the point I want to check (myPoint) are passed in and set up as follows (in their respective setter methods):
    source = CGPointMake(pos.x - 40.0, pos.y - 60.0);
    dest = CGPointMake(pos.x - 40.0, pos.y - 60.0);
    myPoint = CGPointMake(pos.x - 40.0, pos.y - 60.0);
    They have 40 and 60 pixels removed as the co-ords I'm passing in are the location on the iPhone screen (320x480). I have to subtract those values to get the top-left corner of the frame I'm drawing into, i.e. 40, 60 on the screen is actually 0, 0 of the frame.
    Now I draw the line in the drawRect method:
    CGMutablePathRef linePath = CGPathCreateMutable();
    CGPathMoveToPoint(linePath, NULL, source.x, source.y);
    CGPathAddLineToPoint(linePath, NULL, dest.x, dest.y);
    And here's where I check whether the point has touched the line:
    float m = (source.y - dest.y) / (source.x - dest.x);
    float y = (m * (source.x - myPoint.x)) + myPoint.y;
    if((y >= source.y - 3) && (y <= source.y + 3) && (myPoint.x >= source.x) && (myPoint.x <= dest.x)) // ±3 pixels for tolerance
    NSLog(@"Point hit the line!");
    What am I doing wrong?!
    The whole premise of my game rests on this one simple little problem. I've spent two weeks writing the rest of it, and a week writing THIS one part! Grrr.
    Any help much appreciated. If I can't get this done within a week, pop along to London and see a grown man cry.

  • Need to detect undefined array elements

    Hi:
    How does one detect unassigned elements of an array. Consider...
    type myarrtyp is table of char(1) index by binary_integer;
    myarr myarrtyp;
    myarr(1) := 'X';
    myarr(3) := 'X';
    for x in 0..3 loop
    dbms_output.put_line(x || ': ' || myarr(x));
    end loop;
    This fails when it hits myarr(2). Message is "no data found"
    If I try to detect a NULL in the loop...
    for x in 0..3 loop
    if myarr(x) is null
    then
    dbms_output.put_line(x || ': NULL');
    else
    dbms_output.put_line(x || ': ' || myarr(x));
    end if;
    end loop;
    ... it still fails, same reason.
    Q: How can one sense that myarr(2) has not been assigned?
    I'm thinking that behind the scenes, Oracle is just creating a table with two columns, one with the char(1) and the other with a NUMBER. When I do something like myarr(3) := 'X', it loads one record in the array table (values (3,'X')). When I try to get myarr(2), I get a "no data found" in the same sense that I would get a "no records found" in a more familiar SQL query. If true, then how can one sense "no data found" when refering to a PL/SQL table array indexed by a binary_integer?
    One work around is to init the array with something like '-', then selectively overwrite with 'X'. You will be able to sense the '-'. But, since I don't know how big the array will need to be, and I don't want to spend the cycles initializing a ridiculously large array, I'd prefere a more elegant solution.
    Thanks in Advance
    -dave

    Just add an exception handler in the loop to trap for the no_data_found condition:
    for x in 0..3 loop
      begin
        dbms_output.put_line(x || ': ' || myarr(x));
      exception
        when no_data_found then
          null;  -- do nothing, handle the exception silently
          -- dbms_output.put_line('element ' || x || ' not initialized');
      end;  
    end loop;

  • Hit detection

    i have included my code below for bullets in my game. the
    bullets are added to the stage when the mouse is clicked anywhere.
    easy enough... now the question i have is at the bottom of my
    shooter function. i am trying to detect when a bullet (boxr) hits
    my target.
    it could have something to do with the bullets being
    generated inside that function and the target being just a movie
    clip on the stage with the instance name "target". im not sure. any
    help would be greatly appreciated.

    awesome! i didn't realize you had to detect for a hit each
    frame. i just thought it was triggered when the two movie clips
    were on top of each other. thanks!

  • [AS3] Hit detection

    Hello, well I am trying make a game, simple game. It has a movie clip of a bullet, and a shape for a target.
    I am trying to make the bullet hit the target and cause it to register as a hit.
    I had a previous system with just 1 bullet without an array to make more of them, that worked.
    But, this is the error:
    TypeError: Error #1034: Type Coercion failed: cannot convert bullet$ to flash.display.MovieClip.
        at newball_fla::MainTimeline/hitTarget()
        at flash.utils::Timer/_timerDispatch()
        at flash.utils::Timer/tick()
    Here is the code:
    stage.addEventListener(KeyboardEvent.KEY_DOWN, right);
    stage.addEventListener(KeyboardEvent.KEY_DOWN, left);
    stage.addEventListener(KeyboardEvent.KEY_DOWN, space);
    var startbutton = new startButton();
    addChild(startbutton);
    startbutton.x = 400;
    startbutton.y = 350;
    startbutton.addEventListener(MouseEvent.MOUSE_DOWN, onClick);
    var targetTimer:Timer = new Timer(100);
    targetTimer.addEventListener(TimerEvent.TIMER, hitTarget);
    var player:Shape = new Shape();
    player.graphics.beginFill(0x0000FF);
    player.graphics.drawCircle(5, 5, 5);
    player.x = 100;
    player.y = 200;
    addChild(player);
    function onClick(event:MouseEvent):void {
    ball.x = 25;
    ball.y = 55;
    ball.visible = true;
    function right(bmove:KeyboardEvent):void{
    if (bmove.keyCode==Keyboard.RIGHT){
    player.x+= 10
    function left(bmove:KeyboardEvent):void{
        if (bmove.keyCode==Keyboard.LEFT) {
            player.x-= 10
    function space(bmove:KeyboardEvent):void{
    if (bmove.keyCode==Keyboard.SPACE){
    var Bullet:bullet = new bullet();
    targetTimer.start()
    Bullet.x = player.x
    Bullet.y = player.y
    addChild(Bullet);
    Bullet.addEventListener(Event.ENTER_FRAME, moveBullet);
    function moveBullet(e:Event):void{
        e.target.y -=5;
        if(e.target.y <= -10){
            e.target.removeEventListener(Event.ENTER_FRAME, moveBullet);
            removeChild(MovieClip(e.target));
    function hitTarget(event:TimerEvent) : void {
            if(MovieClip(bullet).hitTestObject(ball)) {
            ball.x = 600;
            ball.y = 600;
            ball.visible = false;
            if(MovieClip(bullet).hitTestObject(ball2)) {
            ball2.x = 600;
            ball2.y = 600;
            ball2.visible = false;
    Any help?

    There's a couple of things wrong with the code.  The error you are seeing is partly because you are trying to convert a class (bullet) into a movieclip... not the Bullet you created.  But in the function where you attempt to do that, you don't even have access to the bullets because they are scoped within the function where you create them.
    What you should do is to get rid of the Timer coding altogether and just use the moveBullet function to test for hits since it gets passed the bullet info in its event argument.  Change your moveBullet function to something like...
    function moveBullet(e:Event):void{
        e.target.y -=5;
        if(e.target.y <= -10){
            e.target.removeEventListener(Event.ENTER_FRAME, moveBullet);
            removeChild(MovieClip(e.target));
        } else {
            if(MovieClip(e.target).hitTestObject(ball)) {
               ball.x = 600;
               ball.y = 600;
               ball.visible = false;
           if(MovieClip(e.target).hitTestObject(ball2)) {
               ball2.x = 600;
               ball2.y = 600;
               ball2.visible = false;

  • Cant detect raid array after update

    so i updated this morning, left the computer on all day, and then later this afternoon while booting, couldnot detect /dev/md1 (/ filesystem). so i booted off live cd and changed a line grub menu.lst from
    kernel /vmlinuz26 root=/dev/md1 ro fastboot
    to
    kernel /vmlinuz26 root=/dev/disk/by-uuid/3fa0af4e-01d3-4cbd-b840-647d85fdb12b ro fastboot
    and now it works. so can someone please tell me how come after an upgrade /dev/md1 cannot be detected like it has been.

    may i know what is bricked?
    also, the update to os4.1 had "removed" my jailbreak. does it affect?
    also, what if my phone had not been jailbreak? is there ways to resolve it?

  • Hit Detection on Scaled or Rotated Lines?

    Hi,
    I'm writing a java program in which I paint a number of line segments.
    I've added the ability to scale or rotate the scene. Now, if the scene
    is neither scaled or rotated, then detecting when the mouse pointer
    is over a particular line is not especially difficult. I just iterate through
    all the line objects and compare their coordinates with the mouse's
    coordinates.
    But I can't figure how to detect when the mouse is over a line when the
    scene has been scaled and/or rotated. I guess this problem requires
    a bit of maths - something I'm bit rusty at. Can someone help me?
    Thanks.

    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.util.Hashtable;
    import javax.swing.*;
    import javax.swing.event.*;
    public class TransformSelection extends JPanel implements ChangeListener {
        JSlider rotateSlider;
        JSlider scaleSlider;
        Polygon polygon;
        Line2D[] lines;
        int selectedIndex = -1;
        Color[] colors = {
            Color.red, Color.green.darker(), Color.blue, Color.magenta, Color.orange
        AffineTransform at = new AffineTransform();
        double theta = 0;
        double scale = 1.0;
        public void stateChanged(ChangeEvent e) {
            JSlider slider = (JSlider)e.getSource();
            int value = slider.getValue();
            double cx = getWidth()/2.0;
            double cy = getHeight()/2.0;
            if(slider == rotateSlider) {
                theta = Math.toRadians(value);
            if(slider == scaleSlider) {
                scale = value/100.0;
            at.setToTranslation((1.0-scale)*cx, (1.0-scale)*cy);
            at.scale(scale, scale);
            at.rotate(theta, cx, cy);
            repaint();
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                RenderingHints.VALUE_ANTIALIAS_ON);
            g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
                                RenderingHints.VALUE_STROKE_PURE);
            if(lines == null) {
                initLines();
            AffineTransform orig = g2.getTransform();
            g2.setTransform(at);
            //g2.setPaint(Color.blue);
            //g2.draw(polygon);
            g2.setPaint(Color.red);
            for(int j = 0; j < lines.length; j++) {
                g2.setPaint(colors[j]);
                g2.draw(lines[j]);
                if(j == selectedIndex) {
                    g2.setPaint(Color.red);
                    double cx = (lines[j].getX1() + lines[j].getX2())/2;
                    double cy = (lines[j].getY1() + lines[j].getY2())/2;
                    g2.draw(new Ellipse2D.Double(cx-4, cy-4, 8, 8));
            g2.setTransform(orig);
        public void setSelectedIndex(int index) {
            selectedIndex = index;
            repaint();
        private void initLines() {
            int w = getWidth();
            int h = getHeight();
            double cx = w/2.0;
            double cy = h/2.0;
            int R = Math.min(w,h)/6;
            int sides = 5;
            int[][]xy = generateShapeArrays(w/2, h/2, R, sides);
            polygon = new Polygon(xy[0], xy[1], 5);
            lines = new Line2D[sides];
            double theta = -Math.PI/2;
            for(int j = 0; j < sides; j++) {
                double x1 = cx + (R/2)*Math.cos(theta);
                double y1 = cy + (R/2)*Math.sin(theta);
                double x2 = polygon.xpoints[j];
                double y2 = polygon.ypoints[j];
                lines[j] = new Line2D.Double(x1, y1, x2, y2);
                theta += 2*Math.PI/sides;
        private JPanel getControls() {
            rotateSlider = new JSlider(JSlider.HORIZONTAL, -180, 180, 0);
            rotateSlider.setMajorTickSpacing(30);
            rotateSlider.setMinorTickSpacing(10);
            rotateSlider.setPaintTicks(true);
            rotateSlider.setPaintLabels(true);
            rotateSlider.addChangeListener(this);
            scaleSlider = new JSlider(JSlider.HORIZONTAL, 50, 200, 100);
            scaleSlider.setMajorTickSpacing(50);
            scaleSlider.setMinorTickSpacing(10);
            scaleSlider.setPaintTicks(true);
            scaleSlider.setLabelTable(getLabelTable(50, 200, 50));
            scaleSlider.setPaintLabels(true);
            scaleSlider.addChangeListener(this);
            JPanel panel = new JPanel(new GridBagLayout());
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.weightx = 1.0;
            gbc.fill = gbc.HORIZONTAL;
            gbc.gridwidth = gbc.REMAINDER;
            panel.add(rotateSlider, gbc);
            panel.add(scaleSlider, gbc);
            return panel;
        private Hashtable getLabelTable(int min, int max, int inc) {
            Hashtable<Integer,JComponent> table = new Hashtable<Integer,JComponent>();
            for(int j = min; j <= max; j += inc) {
                String s = String.format("%d%%", j);
                table.put(new Integer(j), new JLabel(s));
            return table;
        private int[][] generateShapeArrays(int cx, int cy, int R, int sides) {
            int radInc = 0;
            if(sides % 2 == 0) {
                radInc = 1;
            int[] x = new int[sides];
            int[] y = new int[sides];
            for(int i = 0; i < sides; i++) {
                x[i] = cx + (int)(R * Math.sin(radInc*Math.PI/sides));
                y[i] = cy - (int)(R * Math.cos(radInc*Math.PI/sides));
                radInc += 2;
            // keep base of triangle level
            if(sides == 3) {
                y[2] = y[1];
            return new int[][] { x, y };
        public static void main(String[] args) {
            TransformSelection test = new TransformSelection();
            test.addMouseListener(new LineSelector(test));
            JFrame f = new JFrame("click on lines");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(test);
            f.getContentPane().add(test.getControls(), "Last");
            f.setSize(400,400);
            f.setLocation(200,200);
            f.setVisible(true);
    class LineSelector extends MouseAdapter {
        TransformSelection transformSelection;
        Rectangle net;
        int lastSelectedIndex;
        final int SIDE = 4;
        public LineSelector(TransformSelection ts) {
            transformSelection = ts;
            net = new Rectangle(SIDE, SIDE);
        public void mousePressed(MouseEvent e) {
            net.setLocation(e.getX() - SIDE/2, e.getY() - SIDE/2);
            AffineTransform at = transformSelection.at;
            Line2D[] lines = transformSelection.lines;
            for(int j = 0; j < lines.length; j++) {
                Shape xs = at.createTransformedShape(lines[j]);
                if(xs.intersects(net)) {
                    transformSelection.setSelectedIndex(j);
                    lastSelectedIndex = j;
                    break;
    }

  • How to change alpha of an array?

    It's me again.
    I am trying to dynamically change the alpha value of a set of movieclips on a timer.  The timer works but I get an error message from the function.     
    This is the error:
    TypeError: Error #1010: A term is undefined and has no properties.
    at piedacoulisse_timer_fla:MainTimeline/zoom/piedacoulisse_timer_fla:onTime()[piedacoulisse_ timer_fla.MainTimeline::frame1:124]
    at flash.utils::Timer/flash.utils:Timer::_timerDispatch()
    at flash.utils::Timer/flash.utils:Timer::tick()
    This is the code:
      var txt:Array = ["txt1","txt2","txt3","txt4","txt5"];
      var flashTimer:Timer = new Timer(3000,5);
      flashTimer.addEventListener(TimerEvent.TIMER, onTime);
      flashTimer.start();
      var frame:int = 0;
      function onTime(evt:TimerEvent):void{
       zoomIn.slider_mc.txt[frame].alpha = 1;  \\ line 124
       frame ++;  
    Can anyone tell me what the problem is and how to fix it?

    Sorry guys, no luck.  I tried all three suggestions and got the same error.  I ended up using timeline animation to change the alpha of my movieclips.  That worked but I am getting the error again when I try to stop some of the mc's from playing.  Here's the error:
    TypeError: Error #1010: A term is undefined and has no properties.
    at piedacoulisse_timer3_fla:MainTimeline/zoom/piedacoulisse_timer3_fla:onTime()[piedacouliss e_timer3_fla.MainTimeline::frame1:136]
    at flash.utils::Timer/flash.utils:Timer::_timerDispatch()
    at flash.utils::Timer/flash.utils:Timer::tick()
    Here's the complete code, in case there is something I am not seeing elsewhere in the program:
    slider_mc.tickMark_mc.stop();
    slider_mc.stop();
    var myRectangle:Rectangle = new Rectangle(9,9,125, 420);
    var slideRectangle:Rectangle = new Rectangle(body_mc.x + 24.5,body_mc.y + 1,219.5,.01);
    var startSlide:Number;
    var deltaSlide:Number = 0;
    var startMoveX:Number = 0;
    var startMoveY:Number = 0;
    var endMoveX:Number = 0;
    var endMoveY:Number = 0;
    var contactTop:Boolean = false;
    var contactBottom:Boolean = false;
    var contactPoint:String;
    body_mc.addEventListener(MouseEvent.MOUSE_DOWN,pickUp);
    body_mc.addEventListener(MouseEvent.MOUSE_UP,dropIt);
    body_mc.addEventListener(MouseEvent.MOUSE_OUT,dropIt);
    slider_mc.addEventListener(MouseEvent.MOUSE_DOWN,beginSlide);
    slider_mc.addEventListener(MouseEvent.MOUSE_UP,stopSlide);
    slider_mc.addEventListener(MouseEvent.MOUSE_OUT,stopSlide);
    topMask.addEventListener(Event.ENTER_FRAME,moveMask);
    botMask.addEventListener(Event.ENTER_FRAME,moveMask);
    bodyMask.addEventListener(Event.ENTER_FRAME,moveMask);
    stage.addEventListener(Event.ENTER_FRAME,zoom);
    //  blockIt stops the draggable mc's when they hit the phone_mc
    function blockIt(event:Event):void{
    if(topMask.hitTestObject(phone_mc) == true){
      reply.text = "top hit";
      contactTop = true;
      event.currentTarget.stopDrag();
      contactPoint =  "top";
      nudgeIt(null);
    }else if(botMask.hitTestObject(phone_mc) == true){
      reply.text = "bottom hit";
      contactBottom = true;
      event.currentTarget.stopDrag();
      contactPoint = "bottom";
      nudgeIt(null);
    }else if(bodyMask.hitTestObject(phone_mc) == true){
      reply.text =  "body hit";
      event.currentTarget.stopDrag();
      contactPoint = "body";
      nudgeIt(null);
    //  drags the hit-detection objects - I needed to do this to allow for a U-shaped object to surround another object.
    function moveMask(event:Event){
    topMask.x = body_mc.x+19;
    topMask.y = body_mc.y+108;
    botMask.x = slider_mc.x+32;
    botMask.y = slider_mc.y+108;
    bodyMask.x = body_mc.x+100;
    bodyMask.y = body_mc.y+38;
    //  drags the movable mc's
    function pickUp(event:MouseEvent):void{
    event.currentTarget.startDrag(false,myRectangle);
    slider_mc.addEventListener(Event.ENTER_FRAME,followMe);
    body_mc.addEventListener(Event.ENTER_FRAME,blockIt);
    startMoveX = event.currentTarget.x;
    startMoveY = event.currentTarget.y;
    contactTop = false;
    //  drops the movable mc's
    function dropIt(event:MouseEvent):void{
    event.currentTarget.stopDrag();
    slider_mc.removeEventListener(Event.ENTER_FRAME,followMe);
    endMoveX = event.currentTarget.y;
    endMoveY = event.currentTarget.y;
    contactBottom = false;
    //  moves the slider with the body when it is dragged
    function followMe(event:Event) {  
         slideRectangle.y = body_mc.y;
      slideRectangle.x = body_mc.x + 24.5;
      slider_mc.x = slideRectangle.x + deltaSlide;
      slider_mc.y = body_mc.y;
    //  drags the slider along the body
    function beginSlide(event:MouseEvent):void{
    event.currentTarget.startDrag(false,slideRectangle);
    deltaSlide = slider_mc.x - slideRectangle.x
    contactBottom = false;
    // drops the slider
    function stopSlide(event:MouseEvent):void{
    event.currentTarget.stopDrag();
    // adjusts the postion of the draggable mc's to just butt up against the phone_mc - I did this so the mc's can be dragged again.  Without it, they are
    locked in place by the hitTest.
    function nudgeIt(event:Event):void{
    if(contactPoint == "top"){
      body_mc.x = body_mc.x - 1;
    }else if(contactPoint == "bottom"){
      slider_mc.x = slider_mc.x + 1;
    }else if(contactPoint == "body"){
      body_mc.y = body_mc.y - 1;
    // "zooms" in on the image and adds text commentary.  tickMark and oval mc's animate and then stop
    //  This is where the error messages started appearing
    //  Lines 136 137 and 138 all throw the same error
    function zoom(event:Event):void{
    if(contactTop == true &&contactBottom == true){
      body_mc.removeEventListener(MouseEvent.MOUSE_DOWN,pickUp);
      slider_mc.removeEventListener(MouseEvent.MOUSE_DOWN,beginSlide);
      var zoomIn:MovieClip = new MovieClip;
      zoomIn.addChild(phone_mc);
      zoomIn.addChild(body_mc);
      zoomIn.addChild(slider_mc);
      zoomIn.scaleX = 2.5; zoomIn.scaleY =2.5;
      addChild(zoomIn);
      zoomIn.x = -150; zoomIn.y = -350;
      slider_mc.tickMark_mc.gotoAndPlay(2);
      var flashTimer:Timer = new Timer(2000,8);
      flashTimer.addEventListener(TimerEvent.TIMER, onTime);
      flashTimer.start();
      var frame:int = 2;
      function onTime(evt:TimerEvent):void{
       slider_mc.gotoAndPlay(frame);
       slider_mc.stop();
       frame ++; 
       if(frame == 3){zoomIn.slider_mc.tickMark_mc.gotoAndStop(1);}   // line 136
       if(frame == 5){zoomIn.slider_mc.oval1_mc.gotoAndStop(1);}        // line 137
       if(frame == 7){zoomIn.slider_mc.oval2_mc.gotoAndStop(1);}        // line 138

  • Not detecting tv display when connected with Apple Mini-DVI to Video Adapte

    I am connecting my macbook to my older tv using a Apple Mini-DVI to Video Adapter to an RCA (yellow video prong) and then into the tv. The red and white audio prongs hang loose, not hooked into anything on both ends. When I go into Displays there is no option for mirroring displays. I hit 'detect displays' but nothing happens. The Apple Mini-DVI to Video Adapter is brand new, just ordered it from apple. And I use the RCA cord all the time with other machines into my tv and it works fine.
    Any help is really appreciated. Thanks!

    Which generation MacBook do you have because at some point Apple dropped support for that adapter. Here is a link to a list of Apple adapters and compatible computer models:
    http://support.apple.com/kb/HT3235

  • Imac 27" won't detect samsung syncmaster dvi

    A couple weeks ago I bought my first mac.  iMac 27" 2.7 GHz.  Before that I had a custom built pc with a Samsung Syncmaster T260HD hooked up through DVI.
    Today I mini-display to DVI adaptor in attempt to connect my samsung and use it as an external display.  It isn't working.  Everything is connected properly and the monitor is on and set to DVI.  I go to the system pref menu and hit detect displays and nothing happens.  One thing that I have noticed it that when I switch to DVI on the monitor it goes for a sec and then basically falls asleep.  It is still on but nothing goes up.
    My computer is also fully updated and I've tried restarting it.
    Please HELP!
    Thanks

    bump.
    Just bought a new adapter and it still doesn't work.

  • Can't detect some external displays with Macbook Pro 17"

    My macbook pro 17" connects just fine to my Apple Cinema display. But twice now I've tried to use it for presentations where I am connecting to either a video projector or a plasma screen through some sort of switchbox installed in the room. There's a VGA cable I'm supposed to connect to, and I use my DVI-VGA adaptor for that. But the macbook never recognizes the external monitor. In one case, everytime I hit "detect displays" i would see a brief bit of noise on the external screen like it was about to connect, but then nothing -- and Display Preferences showed no evidence of any connected external monitor. In both cases, I know the host systems generally handle Macs just fine. Is there something different about a Macbook Pro with dual-DVI? A design flaw or a mysterious switch that needs to be set right? Or maybe there's a glitch in my specific macbook??

    Have you tried resetting PRAM…
    http://docs.info.apple.com/article.html?artnum=2238
    … ?

  • My MacBook Air (OS 10.8.4) does not connect to projectors consistently using a VGA/Thunderbolt connetor. The Monitors/detect displays box that I am used to never appears. Intermittently the "arrangement" window appears in the Displays System Preferences

    My previous MacBook Air running an older operating system synced up just fine with these same projectors using the same minidisplay to vga adapter. My new computer has Airplay on it, and Airplay shows up on my menu bar on the new laptop where the displays icon used to appear. I cannot get the displays icon to display (even when I turn Airplay mirroring off). It used to show up on the menu bar and if I had projector issues I hit "detect displays" and it resolved. None of that appears to be available with the new operating system and Airplay on. I am not sure why.

    My previous MacBook Air running an older operating system synced up just fine with these same projectors using the same minidisplay to vga adapter. My new computer has Airplay on it, and Airplay shows up on my menu bar on the new laptop where the displays icon used to appear. I cannot get the displays icon to display (even when I turn Airplay mirroring off). It used to show up on the menu bar and if I had projector issues I hit "detect displays" and it resolved. None of that appears to be available with the new operating system and Airplay on. I am not sure why.

  • RAID arrays and Windows

    Not sure where to post this one.  You have been very helpful before so I’ll try again.
    The machine is the Media Centre in my signature.
    Installed two new Maxtor SATA drives, set up as RAID 0, clean install of XP MCE. Boots on the RAID array.  Not a single problem. Installed MSI drivers, XFS video card drivers and KCorp PCI network adaptor for wireless link.  Download and install all Windows updates. All OK.
    On a later start up it spends long time trying to detect RAID array, then RAID error. Automatically reboots and detects a healthy raid array. Tries to open Windows but screen goes almost black but faint Windows loading page with the short activity bar showing no activity.  If left it eventually springs to life. Tried starting in safe mode, no problem.  Restore to an earlier restore point, no better.
    The RAID problem is intermittent. The Windows problem looks as if it stalls for a variable length of time before it gets going.
    Don’t know where to go next.  Any suggestions?   

    fafner: I wanted a large disk to hold recorded TV progs, videos, CDs etc and 160GB is the max for this mainboard.  I went for 2x160GB Maxtor drives.  As I was using two drives I reasoned I might as well use RAID 0 to get a single volume and a faster machine.  In particular I read somewhere that RAID 0 halved, or nearly so, the start up time.  Who wants to wait a couple of minutes for the TV to fire up?
    Fredrik:  The XFX video card drivers are in fact nVidia drivers which are the latest.
    Doctor Stu:  I have subsequently installed XP on both drives individually.  On one it worked well, on the other same old problem: either the drive not found in the BIOS after the heading ‘Detect IDE drives’ or the screen fades as Windows starts up.  Checked both drives with Maxtor’s Powermax disk checking utility.  Provided the drive was connected to the SATA1 socket and the other drive not connected both passed the Full Test.  I could not get Powermax to recognise SATA2 even though both were detected correctly in the BIOS.  My conclusion is that the problem was a dodgy connection which I hope has been rectified with all the swapping around.
    Is there disk testing utility that puts the disc under load similar to Mem86 for memory?
    Will I try RAID again?  I doubt it even though it did start up in far less time.
    My thanks to all.   

  • SCXI-1001 cannot detect modules via SCXI-1600

    我現有
    NI AT-MIO-16E-10
    SCXI-1001
    SCXI-1102
    SCXI-1102B
    SCXI-1303
    SCXI-1160
    SCXI-1324
    SCXI-1600
    除SCXI-1600外,都是以前的人留下的,
    在兩個月前, 在使用其間電腦detect不到SCXI-1001,
    因為 NI AT-MIO-16E-10 實在太舊,
    所以認為問題出自它,並買了SCXI-1600替代,
    選SCXI-1600因為可以連USB方便得多
    現在當我在SCXI-1001中只放SCXI-1600,是沒有問題的,
    在Measurement & Automation中,
    可以看見在"Devices and Interfaces"中有"NI SCXI-1001"SCI"",
    之中還有"1: NI SCXI-1600 "Dev1"",而"1"代表slot nukber,
    我已全試了12個slot,每一個都能正常detect,
     證明SCXI-1001全身應該無問題,每個slot都正常運作
    而問題是,當我放SCXI-1102或SCXI-1102B進其他slot時,
    就不能detect出來,我right cick "NI SCXI-1001"SCI""開"Properties",
    在打開的"SCXI Chassis Configuration"視窗中,
    能看見"SCXI-1600"在相應 slot number 的"Module Array"中,
    就算按下"Auto-Detect All Modules"也好,
    SCXI-1102都不能detect出來
    我亦試過手動輸入"Module Array"為SCXI-1102,而"Accessory"為SCXI-1303,
    但當我test "NI SCXI-1600 "Dev1"時,就會出現以下error:
     Verify SCXI Chassis
    "SCXI-1001
    Chassis IDC1
    Slot Number 4: the confiduration specifies a SCXI-1102 module but nothing was detected."
    即是說SCXI-1001跟本detect不到SCXI-1102,
    換上SCXI-1102B結果都是一樣
    問題是不是出自SCXI-1102和SCXI-1102B?
    應該如何證實?
    另外,若換上SCXI-1160的話,Measurement & Automation就只能detect SCXI-1600而detect不到SCXI-1001,
    為甚應會這樣?
    謝謝
    已解決!
    轉到解決方案。

    建議將 SCXI-1102 等等送到 NI Taiwan 客服部,
    客服部會請工程師幫忙檢查是否故障
    如果檢查的結果是故障,您可以決定是否付費維修

Maybe you are looking for

  • Error opening a transaction in Logic Editor

    Hi, Using 11.5 SR3. I have a transaction which some 20 sequences and 30 action blocks. I configured it as a listener. For some strange reason, I just cannot open the transaction in the Logic editor. Another issue, though not sure if its related to th

  • Sender FTP communication channel

    Hi experts, We have had the following problem twice with two different comm channels: A sender FTP communication channel stops polling for no apparent reason. There were no errors and the status remained green. After I stopped and started the communi

  • "Extendscript.dll was not found" at startup

    Just bought and installed Photoshop and Premiere Elements 12 on my PC running Vista 64 bit. Now everytime I boot up my PC I get an error box titled "Elementsautoanalyzer.exe - Unable to Locate Component" and a message that says ExtendScript.dll was n

  • Brand New Update Retriever Repository, No Visible Updates

    I've been using TVUR and System Update for over two years and, except for the temporary program cancellation, it's worked very well. My TVUR workstation died and I've tried to recycle the old repository using another workstation (the files are on a f

  • Access Ldap directory

    Dear All, I want to access the ldap directory to get the users' names , but i don't know how to get the ldap password and data required to access it, plz help. Thanks alot, Marwa