Make the code found on movieclip wich I clicked on

Hi all

I'm doing a game in AS3.

I have a scene with empty space. There is an empty space 1, 2 empty space... etc.

When the player clicks on an empty space, a usebox appear with 2 buttons. He the usebox even for all the empty spaces. When the reader, click on the 'Buy' buttons a window pops up where he can choose between different buildings (same windows for all the empty spaces).

When he clicks on the building he wants, the 'building' function is called (someBuilding.visible = true) and the building appears on the scene.

But I did not how tell the code to make the corresponding building to empty space visible...

If the player has clicked on the empty space 2 for example, how can I know the code to make someBuilingInEmptySpace2.visible = true? If he clicked on the empty space 3-> someBuilingInEmptySpace3.visible = true?

(something like):

function build():void{ 
if clicked on emptyspace2 { 
someBuilingInEmptySpace2.visible = true ; } 
if clicked on emptyspace3 { 
.. .

I asked around, and told me to:

emptySpace1.addEventListener(MouseEvent.CLICK, onSpaceClicked);
emptySpace2.addEventListener(MouseEvent.CLICK, onSpaceClicked);
emptySpace3.addEventListener(MouseEvent.CLICK, onSpaceClicked);


function onSpaceClicked(evt:MouseEvent):void 
{
    var clickedSpace:MovieClip = evt.currentTarget as MovieClip;
    //... perform the actions you need to perform on the clickedSpace
}

But I really don't see where to put it. If someone could help me, it'll be a great help.

So, here's my coden and my organization:

I've got Engine.as where the elements of the game are:

private function createBackground(thisBack:String):void{ 
for (i in usableItems){ 
var thisClip = usableItems[i]; 
thisClip.buttonMode = true; 
thisClip.addEventListener(MouseEvent.CLICK, examine, false, 0, true); 
thisClip.gotoAndStop(1); 
} 


private function createUI():void{  
toolbar = new Toolbar(stage); 
addChild(toolbar); 
toolbar.x = 0; 
toolbar.y = 400;  
buildings = new Buildings(stage); 
addChild(buildings); 
buildings.visible = false;  
puzzle = new Puzzle(stage);  
stage.addEventListener("endGame", endGame, false, 0, true); 
}  


private function examine(e:MouseEvent):void{ 
stage.dispatchEvent(new Event("itemClicked")); 
useBox = new UseBox(stage, e.currentTarget); 
useBox.x = mouseX; 
useBox.y = mouseY; 
stage.addChild(useBox); 
}

When the player clicks on an empty area (emptyspace2 for example), consider the function is called and the useBox is displayed.

In my UseBox.as :

public function UseBox(stageRef:Stage, thisThing:Object){ 
this.stageRef = stageRef; 
this.thisThing = thisThing; 
this.visible = true; 
useButton.buttonMode = true; 
lookButton.buttonMode = true; 
lookButton.addEventListener(MouseEvent.CLICK, lookAt, false, 0, true); 
useButton.addEventListener(MouseEvent.CLICK, useThing, false, 0, true);  


private function useThing(e:MouseEvent):void{ 
Engine.buildings.visible = true; 
useButton.removeEventListener(MouseEvent.CLICK, useThing); 
}

In my Buildings.as

public function Batiments(stageRef:Stage){ 
houseBtn.addEventListener(MouseEvent.CLICK, houseConstruction, false, 0, true);
} 
private function houseConstruction(e:MouseEvent):void{ 
var house; 
var emptyspace1; 
trace("choix"); 
stage.dispatchEvent(new Event("itemClicked")); 
Engine.buildings.visible = false; 
Engine.puzzle.houseBuilt(); 
toolbar.money.text = String( Number(toolbar.money.text ) - 100 ); 
}


And, finally, in my Puzzle.as

public function Puzzle(stageRef:Stage){ 
allPuzzles = new Object; 
allPuzzles.tundra.maisonBought = false; 
}  
public function maisonBuilt():void{ 
var house; var emptyspace1; 
for (var i in Engine.usableItems){ 
if (Engine.usableItems[i].displayName == "HOUSE") 
house = Engine.usableItems[i]; 
if (Engine.usableItems[i].displayName == "EMPTYSPACE1") 
emptyspace1= Engine.usableItems[i]; 
} 
allPuzzles.tundra.houseBought = true; 
house.visible = true; 
house.gotoAndStop("contruction"); 
house.lookTag = "1"; 
timeConstruction.addEventListener(TimerEvent.TIMER_COMPLETE, constructionFini); 
timeConstruction.start(); 
emptyspace1.visible = false; }

Where should I put the emptyspace listeners? I did too classes?

Thanks again for the help.


This is correct:

emptySpace1.addEventListener(MouseEvent.CLICK, onSpaceClicked);
emptySpace2.addEventListener(MouseEvent.CLICK, onSpaceClicked);
emptySpace3.addEventListener(MouseEvent.CLICK, onSpaceClicked);

function onSpaceClicked(evt:MouseEvent):void
{
    var clickedSpace:MovieClip = evt.currentTarget as MovieClip;
    //... perform the actions you need to perform on the clickedSpace

if (clickedSpace == emptyspace2) {
someBuilingInEmptySpace2.visible = true ;

} else if (clickedSpace == emptyspace3 {
someBuilingInEmptySpace3.visible = true ;

}

}

Tags: Adobe Animate

Similar Questions

  • What compiler is used to make the .cod files?

    What compiler is used in the development of Blackberry to make the .cod files? Is - this cap?

    Yes you are right.

    CAP takes to the entry of the .java files list or a JAR file and generates a .cod file that can be loaded onto the handset BlackBerry.

  • Make the code to pause

    Is it possible to pause a plsql block for awhile to a point in the code before continuing to the next line.

    Ben

    DBMS_LOCK. Sleep (5);

    For more information, see this link:
    http://psoug.org/reference/sleep.html

    Published by: Oracle angry on May 15, 2012 20:10

  • Make the code wait until the code is ready

    Hey there,

    Sorry for the stupid topic title, I do not know how to make my problem: $

    I have a mxml... page which initializes a Manager in which all the bottom of things happens (xml is loaded etc etc).
    a little further in the mxml page (always in code part of course), I'd like to collect a table that does not exist in the Manager of... However, after testing the various scenarious, I came to the conclusion that it looks like (I'm not sure), that the call I make in the mxml page occurs FIRST and AFTER Manager does its job...

    Is it possible to put some code 'pending' until I'm ready to run? Can I somehow use a listener for this problem?

    private function init (): void {}
    Manager = new XMLLoader();

    fillArray();
    }

    I thought I could use some Eventlistener - Loader?

    .addEventListener("ready",fillArray,false,0,true); = in init();


    real function = fillArray(evt:Event)

    -don't know how to fix that if...

    So, as you can see above, I first initialize the Manager! (so I expect to fill the class with necessary data).
    Then I call fillArray calling certain functions to display the data of the handler class. (However when I try to display the data it gives NULL return (as it is still empty)... If I trace data IN the Manager, it appears... make me believe the crib does it's work after the fillArray()...

    Sorry if this seems incomprehensible, thank you to those of you who are reading this to try to help :)

    OK - I thought about it. : p I'll meet you here, in case someone crosses once the same question I have...

    Thanks to all who responded, you all helped me very much! I found EXACTLY what I had on this page:
    The example is great!

    http://livedocs.Adobe.com/Flex/2/langref/Flash/events/EventDispatcher.html#includeExamples summary

  • How to make the code comments?

    I don't know how make code comments, but I never really learned conventions for her. When should you comment on something? What is the standard allows you to comment on a field? A method?
    Ask him because this trig Solver in that I was average in the quarter got so much hand I'm lost in my own code and had to stop.

    As you can see no human being could possibly do anthing out of this without comment, that I was coding it I was fine. But when I woke up the next morning and has started again, I was lost.
    package trianglesolver;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.GroupLayout;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    
    public class Main {
    
        static boolean alreadyPressed = false;
    
        public static void main(String[] args) {
            JFrame mainFrame = new JFrame();
            mainFrame.setLocation(100, 100);
            mainFrame.setSize(480, 140);
            mainFrame.setTitle("Triangle Solver");
            mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            mainFrame.setResizable(false);
            JPanel mainPanel = new JPanel();
            mainFrame.add(mainPanel);
            GroupLayout grouplayout = new GroupLayout(mainPanel);
            grouplayout.setAutoCreateGaps(true);
            grouplayout.setAutoCreateContainerGaps(true);
            JMenuBar menuBar = new JMenuBar();
            JMenu file = new JMenu("File");
            menuBar.add(file);
            mainFrame.setJMenuBar(menuBar);
            JMenuItem exit = new JMenuItem("Exit");
            file.add(exit);
            mainFrame.setVisible(true);
            exit.addActionListener(new ActionListener() {
    
                public void actionPerformed(ActionEvent e) {
                    System.exit(0);
                }
            });
            JLabel angleA_Label = new JLabel("Angle A");
            final JTextField angleA = new JTextField("0", 8);
            JLabel angleB_Label = new JLabel("Angle B");
            final JTextField angleB = new JTextField("0", 8);
            JLabel angleC_Label = new JLabel("Angle C");
            final JTextField angleC = new JTextField("0", 8);
            JLabel sideA_Label = new JLabel("Side A");
            final JTextField sideA = new JTextField("0", 8);
            JLabel sideB_Label = new JLabel("Side B");
            final JTextField sideB = new JTextField("0", 8);
            JLabel sideC_Label = new JLabel("Side C");
            final JTextField sideC = new JTextField("0", 8);
            JButton solve = new JButton("Solve");
            solve.addActionListener(new ActionListener() {
    
                public void actionPerformed(ActionEvent e) throws NumberFormatException {
                    if (alreadyPressed == false) {
                        double A = Double.parseDouble(angleA.getText());
                        double B = Double.parseDouble(angleB.getText());
                        double C = Double.parseDouble(angleC.getText());
                        double a = Double.parseDouble(sideA.getText());
                        double b = Double.parseDouble(sideB.getText());
                        double c = Double.parseDouble(sideC.getText());
                        if (a != 0 & b != 0 & c != 0) {
                            A = Math.acos((Math.pow(a, 2) - Math.pow(b, 2) - Math.pow(c, 2)) / (-2 * b * c));
                            B = Math.asin((b * Math.sin(A)) / a);
                            angleA.setText(String.valueOf(Math.toDegrees(A)));
                            angleB.setText(String.valueOf(Math.toDegrees(B)));
                            angleC.setText(String.valueOf(180 - Math.toDegrees(A) - Math.toDegrees(B)));
                            angleA.setCaretPosition(0);
                            angleB.setCaretPosition(0);
                            angleC.setCaretPosition(0);
                        } else if (a != 0 & b != 0 & C != 0) {
                            c = Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2) - 2 * a * b * Math.cos(Math.toRadians(C)));
                            B = Math.asin((b * Math.sin(Math.toRadians(C))) / c);
                            sideC.setText(String.valueOf(c));
                            angleB.setText(String.valueOf(String.valueOf(Math.toDegrees(B))));
                            angleA.setText(String.valueOf(180 - Double.valueOf(angleB.getText()) - Double.valueOf(angleC.getText())));
                            sideC.setCaretPosition(0);
                            angleB.setCaretPosition(0);
                            angleA.setCaretPosition(0);
                        } else if (b != 0 & c != 0 & A != 0) {
                            a = Math.sqrt(Math.pow(b, 2) + Math.pow(c, 2) - 2 * b * c * Math.cos(Math.toRadians(A)));
                            B = Math.asin((a * Math.sin(Math.toRadians(A))) / a);
                            sideA.setText(String.valueOf(a));
                            angleB.setText(String.valueOf(String.valueOf(Math.toDegrees(B))));
                            angleC.setText(String.valueOf(180 - Math.toDegrees(B) - Double.valueOf(angleA.getText())));
                            sideA.setCaretPosition(0);
                            angleB.setCaretPosition(0);
                            angleC.setCaretPosition(0);
                        } else if (a != 0 & c != 0 & B != 0) {
                            b = Math.sqrt(Math.pow(a, 2) + Math.pow(c, 2) - 2 * a * c * Math.cos(Math.toRadians(B)));
                            C = Math.asin((c * Math.sin(Math.toRadians(B))) / b);
                            sideB.setText(String.valueOf(b));
                            angleC.setText(String.valueOf(String.valueOf(Math.toDegrees(C))));
                            angleA.setText(String.valueOf(180 - Double.valueOf(angleB.getText()) - Math.toDegrees(C)));
                            sideB.setCaretPosition(0);
                            angleC.setCaretPosition(0);
                            angleA.setCaretPosition(0);
                        }
                        alreadyPressed = true;
                    }
                }
            });
            grouplayout.setHorizontalGroup(
                    grouplayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(angleA_Label).addComponent(angleA).addComponent(angleB_Label).addComponent(angleB).addComponent(angleC_Label).addComponent(angleC).addComponent(sideA_Label).addComponent(sideA).addComponent(sideB_Label).addComponent(sideB).addComponent(sideC_Label).addComponent(sideC).addComponent(solve));
        }
    }

    Comments won't save sloppy code. Don't throw all your code in a method.

  • Cannot make the code more far

    After you install adobe dreamweaver cs6 my code is too close to me, I can't move it to the left or to the right.

    Here is the image:

    check.PNG

    Yes tnx for any help

    Hey man, I disabled the back to the line and everything worked fine

  • Variable code of the code

    I was wondering how you can make a variable code of the code, for example, normally, you can use this 'blabla' [+ variable]; to make the code tell blablavariable.

    But now I want to make new variables using this code in a loop [using teller1 as the increase in the value]

    This ["var ringsegment_mc:Ring_" + teller1 + "= new [Ring_" + teller1 +"] ()" "];

    which I essentially want to have said:

    var ringsegment_mc:Ring_1 = new Ring_1();

    but this does not work, this isn't a variable called ringsegment_mc.

    why I want to do it, is because I have to do a add a child who makes 16 pieces of 16 different clips.

    Here's the code for this loop for:

    for (var teller1 = 0; teller1 < 16; teller1 ++) {}
    kernplaats += Number (Math.random () * 200 + 300);
    This ["var ringsegment_mc:Ring_" + teller1 + "= new [Ring_" + teller1 +"] ()" "];
    ringsegment_mc.x = XCO [teller1] + kernplaats;
    ringsegment_mc.y = yco [teller1] + kernplaats;
    ringsegment_mc.geklikt = Number (0);
    ringsegment_mc.score = Number (ringscore);
    ringsegment_mc.speedmodded = Number (0);
    ringsegment_mc.kerngroep = Number (1);
    ringsegment_mc.addEventListener (Event.ENTER_FRAME, vernietig);
    addChild (ringsegment_mc);
    }

    you do not export frame 1.   Why?  unless you know what you're doing, check this box.

  • FlashBuilder - how to move the code with drag and drop

    Guys, I must be stupid. Each IDE I worked in allows me to highlight one or more lines of code, and then, when I mouse over the highlighted lines, updates of the cursor to indicate that I can now drag the code, and it moves when I click and drag.

    FlashBuilder (burrito) does not seem to exhibit this feature, but if I hold down the CTRL I do not copy the code via drag and drop.

    There has been one or two occasions where the drag-and - déposer worked, but I can't understand, or reproduce these conditions.

    Can anyone help?

    Thank you

    T

    It should work in Flash Builder, but you are right, that feedback cursor is not very good because it is not updated to show that any sort of slider. Try selecting the text, then click and hold for about a second before you drag it to a new location. If it still does not work for you it must be another problem. Make sure that in preferences, general-> editors-> text editors "Enable drag and drop of text" is turned on.

  • How to increase the size of the code?

    Hello

    I want to make the code a little bigger to make it easier to read. Is this possible? How can I do?

    On a Mac, preferences is in the Dreamweaver menu.

  • How to make the recovery for vpcl231fx cd

    I want to restart my pc to factory settings and don't know how to do the recovery partition recovery cd. If anyone can help. Thank you

    There are two ways to recover your computer system: the recovery Partition and recovery disks.

    Where you can create a set of recovery discs before the upgrade? If this isn't the case, then you can try to restore the original Windows 7 operating system and all the software that came from the original factory configuration by accessing the recovery Partition. The recovery Partition are accessible by turn on/off the device with the ASSIST button instead of the power button.

    - Press the ASSIST button when your computer is off to launch VAIO Care Rescue.
    If the language selection window, select the desired language, and then click OK.
    - Click Start the Recovery Wizard. To make the custom recovery, select Tools, and then click Start the wizard advanced recovery.
    - Follow the on-screen instructions.

    If you cannot start with recovery options, it means only that delete you the recovery partition when you upgraded your operating system. If this is the case, you will need to buy recovery disks to restore the original software.

    You can buy recovery disks of Sony parts and accessories or parts distributor authorized Sony

    If my post answered your question, please mark it as "accept as a Solution.

  • Help make the text visible so click on the button

    Hello

    I am new to livecycle designer and have very little experience with scripts.

    That's what I want to do:

    I inserted a button on a form. When the button is clicked I want to make a text box read-only containing information useful and visible.

    I don't know about the editor script etc and my form is saved in a dynamic form - I don't know what script to write!  Previously, I managed to make a visible text box when a box is checked, but so far I could not find how to make the text appears when a button is clicked: it's the syntax with which I struggle. Any help is appreciated!

    Thank you very much.

    It comes to FormCalc on the click of the button or checkbox:

    If ($.rawValue == 1) then

    TextField1.presence = "visible".

  • What is the code to scale a MovieClip runtime?

    I can't believe how it has been difficult to find an answer to a question as simple.  I found a thread in this forum entitled "How to resize a MovieClip runtime?", but the code that has been published in response has been removed from the post.  WHY?  What is a very well-kept secret?

    In any case... I just want to know how to change a movieclip at run time with a function slide... and also the parent movieclip having already a drag function active.

    Any help would be appreciated.

    BTW... I found a cure for death that makes you instantly as the richest person in the world with all the knowledge of the universe...

    It can be found here:

    onMouseUp and onRelease is usually (but not always) the same thing.

    You can use a scale factor:

    var scaleFactor:Number is. 3;

    {mc.onPress = function ()}

    resize_mc = this;

    startX = _xmouse;

    startY = _ymouse;

    this.onEnterFrame = resizeF;

    }

    {mc.onRelease = function ()}

    delete this.onEnterFrame;

    }

    function resizeF (): Void {}

    resize_mc._width += (_xmouse-startX) * scaleFactor;

    resize_mc._height += (_ymouse-startY) * scaleFactor;

    }

  • Can I use the dashboard Code found on a website online?

    I literally looked for over an hour for the answer to this question:

    Can I use the dashboard Code found on a website online?

    Chrome, Safari, Firefox all have developer tools options, but I am looking for a desktop application that will allow me to make non-destructive modifications to a page web - one app "debugger" that I can open and point to an existing Web site and practically change the CSS to see what it would look like before actually and permenatly change the code on this site online.

    If the edge Code can indeed do what I described above, can someone guide me through the steps to enable this feature?

    Any help is greatly appreciated!

    That said, there is an extension called PageSuck that will pull down a copy of the source code of the web page to push you to locally.  You may find useful.  Here's How to install extensions in the Code of edge.

    -Peter

  • Select code from CBWMS makes the text jump around

    Just upgraded to Dreamweaver CC and found an annoying "feature" that makes the Skączcie code when the selection of text in the long code wrapped.

    For example if there is a long single line javascript code and you select somewhere in the Middle, he instantly pushes this line to the following line similar to a line break (even if it isn't actually inserts a break of)

    This is a feature that can be disabled? Or I wonder if it is a question with my Mavericks install where reinstall it will help.

    Thanks in advance to all.

    I think that this problem is also solved with Nancy O solution:

    "Try to disable the speech recognition & dictation in the settings of your system."

    http://forums.Adobe.com/message/6147142#6147142

    Hope it's OK for this mark as 'correct' show that it has been resolved for someone else, that this could affect.

  • Is there a way to make the as3 to run a &lt; A Href &gt; I have code html?

    I tried to figure this out for a while now. The billing company that I am obliged to pass by sucks and it's the only key codes they provide:

    " < a HREF =" http://www.lexiefyfe.com/ccbill9001/index.htm "> < img src ="ccbutton.jpg"> < / a > .

    I'm not not sure how to change the code, or if as3 can actually run it. Every time I try to change things all that I get url not found... I'm not sure on the img src = bit but Im asuming that is supposed to Im button to use? I want to make my own buttons in flash. I'm trying to pull up files to the same folder on the server that my flash files. Its establishment as a html site would be (not my fault). As always, no compensation or help is greatly appreciated.

    Thank you all

    Thomas

    If you create a dynamic textfield (named tf below) and that you assign this text (slightly modified with slashes) as its htmlText property, this link should work as long as the image is in the same directory that the file you are testing (save the file before testing)...

    tf.htmlText = "http://www.lexiefyfe.com/ccbill9001/index.htm\" >';

Maybe you are looking for