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

Using code inside a MovieClip to effect a different MovieClip on main timeline?

Explorer ,
Apr 16, 2019 Apr 16, 2019

Copy link to clipboard

Copied

I'm having a very hard time fixing this Flash Character Design Game I'm trying to build. I have 12 windows for choosing designs in a movie clip, they are my categories. In the Category Window, there are 17 - 29 new buttons that I want to use to select the designs. Each of the categories has 4 - 7 design sets that you can choose from, (with each set including 4 of the buttons plus the default button (to remove)) The button instance name is the same as a frame label in the design movie clip on the main timeline.

I've yet to be able to get the category Movieclip to react as desired.

Something that brought me a lot closer was the advice given in this Question (on a different forum): how do I link a button inside a movie clip into the mainframe (flash CS6 AS3)

The

buttonMode = true;

method seems to make the code be more active when its in the movie clip, But Ive tried every witch way to get the code to work moving sections around to different movie clips, frames or layers. I even tried having the code as a Class file, but still, I couldn't get not to run...

My category window has 13 frames, one default and twelve with this code repeated 4-7 times, (but each time with a different array)

    var myfa1Array = [this.Mindow.defalt, this.Mindow.d1, this.Mindow.d2, this.Mindow.d3, this.Mindow.d4];

    for each(var fa1 in myfa1Array) {

    this.Mindow.defalt.addEventListener(MouseEvent.CLICK, onfaA1Click);

    this.Mindow.d1.addEventListener(MouseEvent.CLICK, onfaA2Click);

    this.Mindow.d2.addEventListener(MouseEvent.CLICK, onfaA3Click);

    this.Mindow.d3.addEventListener(MouseEvent.CLICK, onfaA4Click);

    this.Mindow.d4.addEventListener(MouseEvent.CLICK, onfaA5Click);

    }

   

    this.Mindow.defalt.buttonMode = true;

    this.Mindow.d1.buttonMode = true;

    this.Mindow.d2.buttonMode = true;

    this.Mindow.d3.buttonMode = true;

    this.Mindow.d4.buttonMode = true;

Then on the main time line, there is the function MouseEvent.

function onfaA1Click(event: MouseEvent): void {

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

    }

    function onfaA2Click(event: MouseEvent): void {

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

    }

    function onfaA3Click(event: MouseEvent): void {

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

    }

    function onfaA4Click(event: MouseEvent): void {

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

    }

    function onfaA5Click(event: MouseEvent): void {

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

    }

When exported with current described code, 285 errors result. One for every "on____Click" in the category window Movieclip. every time the customization and default button was called upon in the Movieclip. It's always error 1120, access of undefined property.

What Im really looking for is an easy way to give the player access to all 228 options for customization, in 12 categories with 4 options per button set.

TOPICS
ActionScript

Views

894

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 ,
Apr 16, 2019 Apr 16, 2019

Copy link to clipboard

Copied

your first code snippet makes no sense.  you're not using your array.

if you used it, your code would look like

    var myfa1Array = [this.Mindow.defalt, this.Mindow.d1, this.Mindow.d2, this.Mindow.d3, this.Mindow.d4];     for(var i=0;i< myfa1Array.length;i++) {    myfa1Array.addEventListener(MouseEvent.CLICK, this['onfaA'+(i+1)+'Click'];     myfa1Array.buttonMode=true     }     

otherwise you're repeatedly executing the same code (that's in your for each loop).

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 ,
Apr 16, 2019 Apr 16, 2019

Copy link to clipboard

Copied

Okay I adjusted your code for the additional info in the other arrays on each frame,

var myfa1Array = [this.Mindow.defalt, this.Mindow.d1, this.Mindow.d2, this.Mindow.d3, this.Mindow.d4, this.Mindow.d5, this.Mindow.d6, this.Mindow.d7, this.Mindow.d8, this.Mindow.d9, this.Mindow.d10, this.Mindow.d11, this.Mindow.d12, this.Mindow.d13, this.Mindow.d14, this.Mindow.d15, this.Mindow.d16, this.Mindow.d17, this.Mindow.d18, this.Mindow.d19, this.Mindow.d20, this.Mindow.d21, this.Mindow.d22, this.Mindow.d23, this.Mindow.d24, this.Mindow.d25, this.Mindow.d26, this.Mindow.d27, this.Mindow.d28]; for(var i=0;i< myfa1Array.length;i++) {    myfa1Array.addEventListener(MouseEvent.CLICK, this['onfa'+(i+1)+'Click']);     myfa1Array.buttonMode=true     }    

The error that came up was that I was being reused. (because I have this code for 12 frames.  So I changed 11 of the i(s) to other letters. I'm not sure if that's right though. (I think that i just represents a variable number or something, I have done homework on the subject) The resulting export had no error but did not work as wanted. the menu displayed the categories but the category buttons did nothing.

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 ,
Apr 16, 2019 Apr 16, 2019

Copy link to clipboard

Copied

whatever's being reused, remove the var declaration after the first usage.

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 ,
Apr 16, 2019 Apr 16, 2019

Copy link to clipboard

Copied

okay so I replaced the other letters with i again, and removed the Var form every one but the first frame. It plays with no reported error, but the category buttons still do not work? What about the function script? I have it on the main time line, where the movie clips that contain the designs is, as well as the category menu, is that right? I cant think of where else to place them but there or in the menu frames...

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 ,
Apr 17, 2019 Apr 17, 2019

Copy link to clipboard

Copied

all function definitions can be on the first frame.

btw, why do you have different functions when they all do the same thing?

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 ,
Apr 17, 2019 Apr 17, 2019

Copy link to clipboard

Copied

Well, Im not sure how to right a function that would act for all of them...

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 ,
Apr 17, 2019 Apr 17, 2019

Copy link to clipboard

Copied

the code in each of the 5 functions you showed is the same.  all your buttons can call the first one and you can removed the others.

to debug why your buttons don't do what you expect, use the trace() function.

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 ,
Apr 17, 2019 Apr 17, 2019

Copy link to clipboard

Copied

okay is reduced recode, but you see, Not all the the code is the same, I only posted the first one, but there are multiple design movie clips. So I reduced it down to just the first of every movie clip, but its really a section of buttons, plus default, that each design is called for,

function onfa1Click(event: MouseEvent): void {

  trace(this.face1.gotoAndStop(event.target.name));

}

function onfa6Click(event: MouseEvent): void {

  trace(this.face2.gotoAndStop(event.target.name));

}

function onfa7Click(event: MouseEvent): void {

  trace(this.face2.gotoAndStop(event.target.name));

}

function onfa11Click(event: MouseEvent): void {

  trace(this.face3.gotoAndStop(event.target.name));

}

function onfa16Click(event: MouseEvent): void {

  trace(this.face4.gotoAndStop(event.target.name));

}

function onfa21Click(event: MouseEvent): void {

  trace(this.face5.gotoAndStop(event.target.name));

}

function onfa26Click(event: MouseEvent): void {

  trace(this.face6.gotoAndStop(event.target.name));

}

function onfa31Click(event: MouseEvent): void {

  trace(this.face7.gotoAndStop(event.target.name));

}

see here there are 7 design choices I want to be active at once in this example, each is effected by 5 different On___Click events, is there a way to change toe code to represent a range of these? something like,

function ['onfaA'+(1 || 2 || 3 || 4 || 5)+'Click'](event: MouseEvent): void {

  trace(this.face1.gotoAndStop(event.target.name));

but that uh, at tally works... yeah Im not to got at writing code, but good with concepts. I think...

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 ,
Apr 18, 2019 Apr 18, 2019

Copy link to clipboard

Copied

LATEST

no.

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