• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

undefined property, seem defined?

Explorer ,
Mar 29, 2019 Mar 29, 2019

Copy link to clipboard

Copied

Hello, I'm making a flash game to be a character designer combing two methods Ive used on two separate designer games in the past....

Here is the original code from a working game:

var myWindowArray = [colorWindow1, colorWindow2, colorWindow3, hornsWindow4, wingsWindow5, extraWindow6];

function hideALLWindows (){

  for each (var window in myWindowArray) {

  window.x = -213;

  }

}

window1.addEventListener(MouseEvent.CLICK, showWindow1);

window2.addEventListener(MouseEvent.CLICK, showWindow2);

window3.addEventListener(MouseEvent.CLICK, showWindow3);

window4.addEventListener(MouseEvent.CLICK, showWindow4);

window5.addEventListener(MouseEvent.CLICK, showWindow5);

window6.addEventListener(MouseEvent.CLICK, showWindow6);

function showWindow1 (event:MouseEvent):void {

  hideALLWindows ();

  colorWindow1.x = 12;

}

function showWindow2 (event:MouseEvent):void {

  hideALLWindows ();

  colorWindow2.x = 12;

}

function showWindow3 (event:MouseEvent):void {

  hideALLWindows ();

  colorWindow3.x = 12;

}

function showWindow4 (event:MouseEvent):void {

  hideALLWindows ();

  hornsWindow4.x = 12;

}

function showWindow5 (event:MouseEvent):void {

  hideALLWindows ();

  wingsWindow5.x = 12;

}

function showWindow6 (event:MouseEvent):void {

  hideALLWindows ();

  extraWindow6.x = 12;

}

/* Click to Go to Frame and Stop

Clicking on the specified symbol instance moves the playhead to the specified frame in the timeline and stops the movie.

Can be used on the main timeline or on movie clip timelines.

Instructions:

1. Replace the number 5 in the code below with the frame number you would like the playhead to move to when the symbol instance is clicked.

*/

back.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_3);

function fl_ClickToGoToAndStopAtFrame_3(event:MouseEvent):void

{

  gotoAndStop(2);

}

and after modification to fit new instance names, and add-on of new windows, it no longer works. the error is always that the objects are undefined,.... so I tried a basic rewrite, her is the code now, (it might not work even if the undefended objects were defined... since I have not gotten it working...)

import fl.controls.ColorPicker;

import fl.events.ColorPickerEvent;

import flash.geom.ColorTransform;

import flash.display.MovieClip;

import flash.display.DisplayObjectContainer;

import flash.display.DisplayObject;

import flash.events.MouseEvent;

var myArray:Array = new Array(12);

var movieclip:Array = ["Mindow1", "Mindow2", "Mindow3", "Mindow4", "Mindow5", "Mindow6", "Mindow7", "Mindow8", "Mindow9", "Mindow10", "Mindow11", "Mindow12"];

function hideALLArray (){

  for each (var window in myArray) {

  window.x = -1300.10;

  }

}

window1.addEventListener(MouseEvent.CLICK, showWindow1);

function showWindow1 (event:MouseEvent):void {

  hideALLArray ();

  MovieClip(Mindow1).x = -1.00;

}

window2.addEventListener(MouseEvent.CLICK, showWindow2);

function showWindow2 (event:MouseEvent):void {

  hideALLArray ();

  MovieClip(Mindow2).x = -1.00;

}

window3.addEventListener(MouseEvent.CLICK, showWindow3);

function showWindow3 (event:MouseEvent):void {

  hideALLArray ();

  MovieClip(Mindow3).x = -1.00;

}

window4.addEventListener(MouseEvent.CLICK, showWindow4);

function showWindow4 (event:MouseEvent):void {

  hideALLArray ();

  MovieClip(Mindow4).x = -1.00;

}

window5.addEventListener(MouseEvent.CLICK, showWindow5);

function showWindow5 (event:MouseEvent):void {

  hideALLWindows ();

  MovieClip(Mindow5).x = -1.00;

}

window6.addEventListener(MouseEvent.CLICK, showWindow6);

function showWindow6 (event:MouseEvent):void {

  hideALLArray ();

  MovieClip(Mindow6).x = -1.00;

}

window7.addEventListener(MouseEvent.CLICK, showWindow7);

function showWindow7 (event:MouseEvent):void {

  hideALLArray ();

  MovieClip(Mindow7).x = -1.00;

}

window8.addEventListener(MouseEvent.CLICK, showWindow8);

function showWindow8 (event:MouseEvent):void {

  hideALLArray ();

  MovieClip(Mindow8).x = -1.00;

}

window9.addEventListener(MouseEvent.CLICK, showWindow9);

function showWindow9 (event:MouseEvent):void {

  hideALLArray ();

  MovieClip(Mindow9).x = -1.00;

}

window10.addEventListener(MouseEvent.CLICK, showWindow10);

function showWindow10 (event:MouseEvent):void {

  hideALLArray ();

  MovieClip(Mindow10).x = -1.00;

}

window11.addEventListener(MouseEvent.CLICK, showWindow11);

function showWindow11 (event:MouseEvent):void {

  hideALLArray ();

  MovieClip(Mindow11).x = -1.00;

}

window12.addEventListener(MouseEvent.CLICK, showWindow12);

function showWindow12 (event:MouseEvent):void {

  hideALLArray ();

  MovieClip(Mindow12).x = -1.00;

}

In every export, the recurring error has been that windowX or MindowX (I wasn't sure if its case sensitive so I switch the first letter for second object) is undefended. How the array is meant to work: user clicks a Botton with brace name windowX upon clicking the object MindowX is summoned to be visible with further button options. SO, many of the MindowX objects have Actions in their frames.

But Basically,  Ive used the code that works on other files, and Ive used a new code, yet, despite having the objects intense names clearly written on the objects, and in the code, they seem undefined, I'm unsure what to do? write instance name on object and you can call it in code right? so why is it not calling?

Any help would be nice. Thanks in advance!

TOPICS
ActionScript

Views

700

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 29, 2019 Mar 29, 2019

Copy link to clipboard

Copied

actionscript is case-sensitive.

and this is problematic:

  1. function hideALLArray (){ 
  2.   for each (var window in myArray) { 
  3.   window.x = -1300.10
  4.   } 

window is a string and strings don't have an x property.  to coerce a string to an object you can use:

this.getChildByName(window).x = -1300.10

assuming window are children of 'this'.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 29, 2019 Mar 29, 2019

Copy link to clipboard

Copied

That seems to have solved that code, thanks, but I still can not test the movie as the second part of the code, (witch I thought was working) is now returning errors. I am basing it off this code I used in an earlier game:

import fl.controls.ColorPicker;

import fl.events.ColorPickerEvent;

import flash.geom.ColorTransform;

var SkinFemalecolorInfo:ColorTransform = MovieClip(SkinFemale).transform.colorTransform;

CPer1.addEventListener(ColorPickerEvent.CHANGE, colorChange2);

function colorChange2(event:ColorPickerEvent):void {

SkinFemalecolorInfo.color = CPer1.selectedColor;

MovieClip(SkinFemale).transform.colorTransform = SkinFemalecolorInfo;

}

And here is the error code,

import fl.controls.ColorPicker;

import fl.events.ColorPickerEvent;

import flash.geom.ColorTransform;

var autcolor1Info:ColorTransform = MovieClip(autcolor1).transform.colorTransform;

ColorPicker(CPer2).addEventListener(ColorPickerEvent.CHANGE, colorChange2);

function colorChange2(event:ColorPickerEvent):void {

autcolor1Info.color = ColorPicker(CPer2).selectedColor;

MovieClip(autcolor1).transform.colorTransform = autcolor1Info;

}

The error states that both my colorpicker, (which is a movie clip with instance name CPer2) and the movie clip it's targeted to color change are undefined. The both code and target movie clip are in a movie clip frame to be summoned on a button click, but colorpicker is on main stage. Although I have tried with it in the movie clip, it still creates error

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 29, 2019 Mar 29, 2019

Copy link to clipboard

Copied

both need to exist in the frame when the code (that triggers the error) executes.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 30, 2019 Mar 30, 2019

Copy link to clipboard

Copied

yes! by putting both objects on the same frame and having the system target the absolute instance name for me, the color picker works.

But I've made some modifications to main code, it reads and works like so:

var mywindowArray = [this.window1, this.window2, this.window3, this.window4, this.window5, this.window6, this.window7, this.window8, this.window9, this.window10, this.window11, this.window12];

for each (var window in mywindowArray) {

  window1.addEventListener(MouseEvent.CLICK, onwindow1Click);

  window2.addEventListener(MouseEvent.CLICK, onwindow2Click);

  window3.addEventListener(MouseEvent.CLICK, onwindow3Click);

  window4.addEventListener(MouseEvent.CLICK, onwindow4Click);

  window5.addEventListener(MouseEvent.CLICK, onwindow5Click);

  window6.addEventListener(MouseEvent.CLICK, onwindow6Click);

  window7.addEventListener(MouseEvent.CLICK, onwindow7Click);

  window8.addEventListener(MouseEvent.CLICK, onwindow8Click);

  window9.addEventListener(MouseEvent.CLICK, onwindow9Click);

  window10.addEventListener(MouseEvent.CLICK, onwindow10Click);

  window11.addEventListener(MouseEvent.CLICK, onwindow11Click);

  window12.addEventListener(MouseEvent.CLICK, onwindow12Click);

}

function onwindow1Click (event:MouseEvent):void {

  this.Mindow.gotoAndStop(event.target.name);

}

function onwindow2Click (event:MouseEvent):void {

  this.Mindow.gotoAndStop(event.target.name);

}

function onwindow3Click (event:MouseEvent):void {

  this.Mindow.gotoAndStop(event.target.name);

}

function onwindow4Click (event:MouseEvent):void {

  this.Mindow.gotoAndStop(event.target.name);

}

function onwindow5Click (event:MouseEvent):void {

  this.Mindow.gotoAndStop(event.target.name);

}

function onwindow6Click (event:MouseEvent):void {

  this.Mindow.gotoAndStop(event.target.name);

}

function onwindow7Click (event:MouseEvent):void {

  this.Mindow.gotoAndStop(event.target.name);

}

function onwindow8Click (event:MouseEvent):void {

  this.Mindow.gotoAndStop(event.target.name);

}

function onwindow9Click (event:MouseEvent):void {

  this.Mindow.gotoAndStop(event.target.name);

}

function onwindow10Click (event:MouseEvent):void {

  this.Mindow.gotoAndStop(event.target.name);

}

function onwindow11Click (event:MouseEvent):void {

  this.Mindow.gotoAndStop(event.target.name);

}

function onwindow12Click (event:MouseEvent):void {

  this.Mindow.gotoAndStop(event.target.name);

}

SO I'm using frame labels to call the menu set up to view by assign like manes to the buttons and frame labels. this method has by far proven to be the most stable, cattily allowing me to display the menu frames in preview, all other error-free tests must have had less strict errors or simply been non-functional.

Now, I wish to use similar code to that above, but inside the movie clip it brings to frame. So far I have:

import fl.controls.ColorPicker; 

import fl.events.ColorPickerEvent; 

import flash.geom.ColorTransform; 

import flash.display.MovieClip; 

import flash.events.MouseEvent; 

var myDia1Array = [Object(root).Mindow.defalt, Object(root).Mindow.d1, Object(root).Mindow.d2, Object(root).Mindow.d3, Object(root).Mindow.d4];

for each (var Dia1 in myDia1Array) {

  Object(root).Mindow.defalt.addEventListener(MouseEvent.CLICK, onDia1Click);

  Object(root).Mindow.d1.addEventListener(MouseEvent.CLICK, onDia2Click);

  Object(root).Mindow.d2.addEventListener(MouseEvent.CLICK, onDia3Click);

  Object(root).Mindow.d3.addEventListener(MouseEvent.CLICK, onDia4Click);

  Object(root).Mindow.d4.addEventListener(MouseEvent.CLICK, onDia5Click);

}

function onDia1Click (event:MouseEvent):void {

  Object(root).Mindow.Dia1.gotoAndStop(event.target.name);

}

function onDia2Click (event:MouseEvent):void {

  Object(root).Mindow.Dia1.gotoAndStop(event.target.name);

}

function onDia3Click (event:MouseEvent):void {

  Object(root).Mindow.Dia1.gotoAndStop(event.target.name);

}

function onDia4Click (event:MouseEvent):void {

  Object(root).Mindow.Dia1.gotoAndStop(event.target.name);

}

function onDia5Click (event:MouseEvent):void {

  Object(root).Mindow.Dia1.gotoAndStop(event.target.name);

}

var myDia2Array = [Object(root).Mindow.defalt, Object(root).Mindow.d5, Object(root).Mindow.d6, Object(root).Mindow.d7, Object(root).Mindow.d8];

for each (var Dia2 in myDia2Array) {

  Object(root).Mindow.defalt.addEventListener(MouseEvent.CLICK, onDia6Click);

  Object(root).Mindow.d5.addEventListener(MouseEvent.CLICK, onDia7Click);

  Object(root).Mindow.d6.addEventListener(MouseEvent.CLICK, onDia8Click);

  Object(root).Mindow.d7.addEventListener(MouseEvent.CLICK, onDia9Click);

  Object(root).Mindow.d8.addEventListener(MouseEvent.CLICK, onDia10Click);

}

function onDia6Click (event:MouseEvent):void {

  Object(root).Mindow.Dia2.gotoAndStop(event.target.name);

}

function onDia7Click (event:MouseEvent):void {

  Object(root).Mindow.Dia2.gotoAndStop(event.target.name);

}

function onDia8Click (event:MouseEvent):void {

  Object(root).Mindow.Dia2.gotoAndStop(event.target.name);

}

function onDia9Click (event:MouseEvent):void {

  Object(root).Mindow.Dia2.gotoAndStop(event.target.name);

}

function onDia10Click (event:MouseEvent):void {

  Object(root).Mindow.Dia2.gotoAndStop(event.target.name);

}

var myDia3Array = [Object(root).Mindow.defalt, Object(root).Mindow.d9, Object(root).Mindow.d10, Object(root).Mindow.d11, Object(root).Mindow.d12];

for each (var Dia3 in myDia3Array) {

  Object(root).Mindow.defalt.addEventListener(MouseEvent.CLICK, onDia11Click);

  Object(root).Mindow.d9.addEventListener(MouseEvent.CLICK, onDia12Click);

  Object(root).Mindow.d10.addEventListener(MouseEvent.CLICK, onDia13Click);

  Object(root).Mindow.d11.addEventListener(MouseEvent.CLICK, onDia14Click);

  Object(root).Mindow.d12.addEventListener(MouseEvent.CLICK, onDia15Click);

}

function onDia11Click (event:MouseEvent):void {

  Object(root).Mindow.Dia3.gotoAndStop(event.target.name);

}

function onDia12Click (event:MouseEvent):void {

  Object(root).Mindow.Dia3.gotoAndStop(event.target.name);

}

function onDia13Click (event:MouseEvent):void {

  Object(root).Mindow.Dia3.gotoAndStop(event.target.name);

}

function onDia14Click (event:MouseEvent):void {

  Object(root).Mindow.Dia3.gotoAndStop(event.target.name);

}

function onDia15Click (event:MouseEvent):void {

  Object(root).Mindow.Dia3.gotoAndStop(event.target.name);

}

var myDia4Array = [Object(root).Mindow.defalt, Object(root).Mindow.d13, Object(root).Mindow.d14, Object(root).Mindow.d15, Object(root).Mindow.d16];

for each (var Dia4 in myDia4Array) {

  Object(root).Mindow.defalt.addEventListener(MouseEvent.CLICK, onDia16Click);

  Object(root).Mindow.d13.addEventListener(MouseEvent.CLICK, onDia17Click);

  Object(root).Mindow.d14.addEventListener(MouseEvent.CLICK, onDia18Click);

  Object(root).Mindow.d15.addEventListener(MouseEvent.CLICK, onDia19Click);

  Object(root).Mindow.d16.addEventListener(MouseEvent.CLICK, onDia20Click);

}

function onDia16Click (event:MouseEvent):void {

  Object(root).Mindow.Dia4.gotoAndStop(event.target.name);

}

function onDia17Click (event:MouseEvent):void {

  Object(root).Mindow.Dia4.gotoAndStop(event.target.name);

}

function onDia18Click (event:MouseEvent):void {

  Object(root).Mindow.Dia4.gotoAndStop(event.target.name);

}

function onDia19Click (event:MouseEvent):void {

  Object(root).Mindow.Dia4.gotoAndStop(event.target.name);

}

function onDia20Click (event:MouseEvent):void {

  Object(root).Mindow.Dia4.gotoAndStop(event.target.name);

}

There are at lest 4 new movie clips of designs, clothing, extra, for each menu page, 1 has labels d1 - d4 + the label default. The next has d5 - d8 and they continue up by four and all contain a blank default frame. The buttons on the movie clip menu are labeled d1 - up to d28 (d16 in example) there is only one default button per movie frame menu.

This code is basically coping the first code, but its not working, in tasing, no errors are reported, but the buttons don't work, and also, react slow to the over and hit when done on them. The main menu buttons work fine, responding in time, but the buttons in the movie clip do not work and react slow.

Any suggestions for this? My thought is maybe the movie clip isn't selected or in focus so to say... Although I haven't really enough know how of AS3 to solve this, and for whatever reason all adobe guides seem to clash with my learning style... I can't fish up any valuable info from them. SO thank you forums for your help so far, Hopefully, after this, I just need to get the color picker for the menu selected objects to work, I think it should be an easy thing, but the display designs are on a movie clip in the menu movie clip, so that may be a combination...

again thanks for help I need just a little more!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 30, 2019 Mar 30, 2019

Copy link to clipboard

Copied

LATEST

that's more code and info than i can quickly read.  in addition, i suspect i would need to download your file(s) to find the problem and i don't do that unless i'm hired.  if you want to hire me, send me a private message or email (via http://www.kglad.com)

and, if you're patient, someone else might do it for free.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines