Skip to main content
anamariaf97539161
Participating Frequently
July 7, 2017
解決済み

error on array declaration

  • July 7, 2017
  • 返信数 3.
  • 649 ビュー

What am I doing wrong? I don't see it.This array gives me an error message   1120:Access of undefined property square

var shape:Array =[square, rectangle, triangle];

Thank you for your help

このトピックへの返信は締め切られました。
解決に役立った回答 Ned Murphy

If you answer all of the questions I asked we might be able to proceed.  I suspect your answer to "How is it named "square"?" might get somewhere as not naming it properly (via the instance name field, assuming it is manually created) will produce the error you indicate.

If you are going to show code, make sure it is code relative to your problem and not code that you based your code on.  Colin's code probably works for what it is supposed to be accomplishing.  Whatever you did to try to modify it is what matters.  In any case, all of that code is likely irrelevant to the error.

返信数 3

Ned Murphy
Legend
July 7, 2017

Ana Maria,

If you answer my questions I will try to help you.

If Colin keeps doing it there is no hope of me helping you.

anamariaf97539161
Participating Frequently
July 8, 2017

I'm sorry, I did not mean to ignore you, I did not have the chance to check until today.

I was trying to reproduce an example that Colin made with a single object and make it work with an array of objects. I created a square, a triangle and a rectangle. I import the images instead of creating them in animate(not sure if that makes a difference). make them movie clips and declare the array var shape:Array =[square, rectangle, triangle]; and when I try it out it gave that error message. And you are right the error is not just for square, but for all the objects.

var shape:Array = [square,triangle,rectangle];

for (var i = 0; i < shape.length; i++)

shape.buttonMode = true;

here is Colin's code where I replace every instance of shape with shape did not work so I tried replacing it with event.target, it did not work either.  Colin created something else, but I will not be able to try it until Monday as I do not have access to the software right now.  Thank you.

import flash.events.MouseEvent;

shape.addEventListener(MouseEvent.MOUSE_DOWN, pressed);

var rotationValue: Number = shape.rotation;

var startMouseAngle: Number;

function pressed(e: MouseEvent) {

  var dx: Number = e.stageX - shape.x;

  var dy: Number = e.stageY - shape.y;

  startMouseAngle = Math.atan2(dy, dx) * 180 / Math.PI;

  rotationValue = shape.rotation;

  stage.addEventListener(MouseEvent.MOUSE_MOVE, updaterot);

  stage.addEventListener(MouseEvent.MOUSE_UP, stoprot);

}

function updaterot(e: MouseEvent) {

  var dx: Number = e.stageX - shape.x;

  var dy: Number = e.stageY - shape.y;

  shape.rotation = rotationValue + Math.atan2(dy, dx) * 180 / Math.PI - startMouseAngle;

}

function stoprot(e: MouseEvent) {

  stage.removeEventListener(MouseEvent.MOUSE_MOVE, updaterot);

  stage.removeEventListener(MouseEvent.MOUSE_UP, stoprot);

}

Ned Murphy
Ned Murphy解決!
Legend
July 9, 2017

If you answer all of the questions I asked we might be able to proceed.  I suspect your answer to "How is it named "square"?" might get somewhere as not naming it properly (via the instance name field, assuming it is manually created) will produce the error you indicate.

If you are going to show code, make sure it is code relative to your problem and not code that you based your code on.  Colin's code probably works for what it is supposed to be accomplishing.  Whatever you did to try to modify it is what matters.  In any case, all of that code is likely irrelevant to the error.

Ned Murphy
Legend
July 7, 2017

I'd like to play thru if you don't mind.  I think my questions might be relevant, but only if the person with the issue answers them.

Colin Holgate
Inspiring
July 7, 2017
Ned Murphy
Legend
July 7, 2017

What is square?  How is it created? Where does it exist relative to the code?  How is it named "square"?  I suspect the same problem will arise with the other two once you resolve the problem with square.

Colin Holgate
Inspiring
July 7, 2017

'square' would be the instance name. This is the fourth topic about the same code.

Ned Murphy
Legend
July 7, 2017

And...?