Skip to main content
Participant
October 5, 2021
Question

help with selections

  • October 5, 2021
  • 1 reply
  • 150 views

Hello I am new to the program and I really do not know much code, I hope you can help me.

I want to make an interactive animation at the beginning there is a selection of characters and backgrounds I want the user to select a character and a background and go to the next scene where only the character that he selected and the animated background are, I understand that this is with code how can I do it?

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
October 6, 2021

html5/canvas or as3?

Participant
October 6, 2021

with as3

kglad
Community Expert
Community Expert
October 6, 2021

use:

 

var selectedCharacter;

var selectedBackground;

var charactersA:Array = [your character instances here];

var backgroundsA:Array = [your background instances here];

 

// your next movieclip or button listener

yournextobject.addEventListener(MouseEvent.CLICK,nextF);

 

for(var i:int=0;i<charactersA.length;i++){

charactersA[i].addEventListener(MouseEvent.CLICK,characterF);

}

for(i=0;i<backgroundsA.length;i++){

backgourndsA[i].addEventListener(MouseEvent.CLICK,backgroundF);

}

function characterF(e:MouseEvent):void{

selectedCharacter = e.currentTarget;

}

function backgroundF(e:MouseEvent):void{

selectedBackground = e.currentTarget;

}

function nextF(e:MouseEvent):void{

if(selectedCharacter && selectedBackground){

for(var i:int=0;i<charactersA.length;i++){

charactersA[i].parent.removeChild(charactersA[i]);

}

for(i=0;i<backgroundsA.length;i++){

backgroundsA[i].parent.removeChild(backgroundsA[i]);

}

addChild(selectedBackground);

addChild(selectedCharacter);

// position each per your needs

} else {

// perhaps an info message to select one of each

}

}