How to understand what number I in the variable?

Hello.

I create game related stuff. If icon 1 == 2 icon can I remove this icons. Player to finish the game when it matches all the icons.

I try give points for correct unswers. And try to calculate this visit.

Code:

package 
{
     import flash.display.MovieClip;
     import flash.events.MouseEvent;
     import flash.text.TextField;


     public class MyMatching extends MovieClip
     {
          public var play_btn:MyButton = new MyButton();//creating new object play_btn
          public var xIconsContainer=100;//all icons start to draw from this x
          public var yIconsContainer=100;//all icons start to draw from this y
          
          private var iconsVertical=2;//icons columns
          private var iconsHorizontal=2;//icons rows
          
          private var firstIcon;//player click to first icon
          private var secondIcon;//player click to second icon
          
          private var deletedIcons;//if firstIcon==secondIcon we will delete 2 icons
          
          private var myTimer:MyTimer;
          //private var myScore:MyScore;
          
          private var playerScoreSum:int;
          private var playerScorePreview:TextField; 
          
          //constructor
          public function MyMatching():void
          {
               welcomeScreen();
               deletedIcons = 0;
               playerScoreSum = 0;
          }
          
          public function welcomeScreen():void
          {
               gotoAndStop('WelcomeScreen');
               play_btn.x=210;
               play_btn.y=300;
               play_btn.visible=true;
               addChild(play_btn);//draw play_btn object
               play_btn.addEventListener(MouseEvent.CLICK, goToLevel_1);//added event for the play_btn object
          }
          
          public function goToLevel_1(event:MouseEvent)
          {
               play_btn.visible=false;
               gotoAndStop('Level_1');
               
               var iconsArray:Array = new Array();//creating new object iconsArray
               for (var i:int; i < iconsVertical*iconsHorizontal/2; i++)
               {
                    iconsArray.push(i);
                    iconsArray.push(i);
               }
               trace(iconsArray);
               
               //added timer to the screen
               myTimer = new MyTimer();
               addChild(myTimer);
               
               //added score to the sceen
               playerScorePreview = new TextField();
               playerScorePreview.text = String(playerScoreSum);
               playerScorePreview.x=200;
               playerScorePreview.y=0;
               addChild(playerScorePreview);
               
               for (var x:int = 0; x < iconsVertical; x++)
               {
                    for (var y:int = 0; y < iconsHorizontal; y++)
                    {
                         var iconsList:Icon = new Icon();
                         addChild(iconsList);
                         iconsList.stop();
                         iconsList.x=x*51+xIconsContainer;
                         iconsList.y=y*51+yIconsContainer;
                         var myRandom:int=Math.floor(Math.random()*iconsArray.length);//creates a random number that will be related to an index of the array named "iconsArray"
                         //var showIcon;//cast as whatever type of element the array is holding
                         iconsList.showIcon=iconsArray[myRandom];//assigns the randomly selected element of iconsArray to the variable showIcon
                         iconsArray.splice(myRandom,1);//removes the randomly selected element (now showIcon) from the array (not the last one, the random one) //we use the splice command to remove number from the array so that it won’t be used again
                         //iconsList.gotoAndStop(iconsList.showIcon+2);//showIcon+2 would be the next frame in the timeline after the frame for the random item deleted, so that code is essentially moving in the timeline to the frame just after the frame for the item that was removed from the array
                         trace(myRandom);
                         iconsList.addEventListener(MouseEvent.CLICK, clickToIcon);
                         deletedIcons++;//when we draw icons we every time add +2 icons to our deletedIcons variable, in future we will deleted 2 icons from this variable if firstIcon==secondIcon
                    }
               }
               trace("*************************random finished ******************************");
          }
          
          public function clickToIcon(event:MouseEvent)
          {
               var thisIcon:Icon = (event.currentTarget as Icon);//what icon player clicked...
               trace(thisIcon.showIcon);//trace clicked icon to the output pannel
               if (firstIcon==null)
               {
                    firstIcon=thisIcon;
                    firstIcon.gotoAndStop(thisIcon.showIcon + 2);
               } 
               else if (firstIcon == thisIcon)
               {
                    firstIcon.gotoAndStop(1);
                    firstIcon=null;
               } 
               else if (secondIcon==null)
               {
                    secondIcon=thisIcon;
                    secondIcon.gotoAndStop(thisIcon.showIcon + 2);
                    
                    playerScoreSum -= playerScoreSum;// -1 point for playerScoreSum
                    
                    if (firstIcon.showIcon==secondIcon.showIcon)
                    {
                         playerScoreSum += 20;// +20 points for playerScoreSum
                         playerScorePreview.text = String(playerScoreSum);
                         
                         removeChild(firstIcon);
                         removeChild(secondIcon);
                         deletedIcons -= 2;
                         if (deletedIcons == 0)
                         {
                              myTimer.Stop();//stoping timer, so now we know how time player spend to playing the level 1
                              //playerScorePreview.text = String(playerScoreSum);//stoping  and show player score
                              gotoAndStop('GameoverScreen');//if player match all icons we go to GameoverScreen                              
                         }
                    }
               }
               else
               {
                    firstIcon.gotoAndStop(1);
                    secondIcon.gotoAndStop(1);
                    firstIcon = null;
                    secondIcon = null;
               }
          }
     }

}

So, in class, I added 2 variables:

private var playerScoreSum:int;
private var playerScorePreview:TextField;

Display the text on the screen and recreate the type:

//added score to the sceen
playerScorePreview = new TextField();
playerScorePreview.text = String(playerScoreSum);
playerScorePreview.x=200;
playerScorePreview.y=0;
addChild(playerScorePreview);

If icon1 is icons2:

if (firstIcon.showIcon==secondIcon.showIcon)
                    {
                         playerScoreSum += 20;// +20 points for playerScoreSum
                         playerScorePreview.text = String(playerScoreSum);
                         
                         removeChild(firstIcon);
                         removeChild(secondIcon);
                         deletedIcons -= 2;
                         if (deletedIcons == 0)
                         {
                              myTimer.Stop();//stoping timer, so now we know how time player spend to playing the level 1
                              //playerScorePreview.text = String(playerScoreSum);//stoping  and show player score
                              gotoAndStop('GameoverScreen');//if player match all icons we go to GameoverScreen                              
                         }
                    }

Now I see 0 to start the game.

20 when I mutching 2 icons

20 when I mutching still 2icons (but must be 40)

I don't understand why I don't have 40.

I tried debugger IDE Flash, but can't understand how all of them work. : () I thought that I must go into the code as compiler go... to a line of code to the other + must see my game + must see changes made to variables...

Then issue:

Why can't you culculate?

And can you suggest what debuger need to use as3 code? (I've used FlashDevelop to write code and I find the tutorial on the use of a debugger, but not everything can have :())

Your problem is probably in the following line:

playerScoreSum = playerScoreSum; / / - 1 point for playerScoreSum

Which is set to zero the playerScoreSum just before that your code can add 20 to it.

Tags: Adobe Animate

Similar Questions

  • Do not understand what is wrong in the code

    Task of my code that movieclip on stage, changing its size - height when changing window size of browsers (player) so height movieclip = fenΩtre rowsers (player) of height.

    Here's my code:

    package
    {
    import flash.display. *;
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.events.Event;

    SerializableAttribute public class ZhMenu extends Sprite
    {
    public var menubg:MovieClip;

    public void ZhMenu()
    {
    var menubg: = new menuGrad();
    stage.scaleMode = StageScaleMode.NO_SCALE;
    internship. Align = StageAlign.TOP_LEFT;
    stage.addEventListener (Event.RESIZE, onResize);
    this.addChild (menubg);
    menuBG.x = 0;
    menuBG.Width = 150;
    menuBG.Height = stage.stageHeight;
    }


    public void onResize (event: Event): void
    {
    var sh: number = stage.stageHeight;
    menuBG.x = 0;
    menuBG.Width = 150;
    menuBG.Height = SH;
    }
    }
    }

    In the number MovieClip menubg added on stage, but when I change the size of the window I have error:

    TypeError: Error #1009: it is not possible to cause a property or a method by referring to the object "null."
    to ZhMenu / onResize)

    And menubg do not change size of course.

    I don't understand what the problem is.

    Plize help me if you know Action Script 3.0 better.

    I don't know if this will fix the error, but in the function ZhMenu, you declare another object in mwnubg (var menubg: = new menuGrad();), which will have no scope within this function.  That you declare (public var menubg:MovieClip ;) outside is never instantiated, and is the one who tries to change your function onResize.)

    As far as the error goes, go to your publication of Flash settings and select the option to enable debugging.  When you run the file again, there may be a number provided in the error message indicating which line is causing the problem.

  • How to track what is running in the HARD drive?

    [moved from Virus & Malware topic]

    When I delete an unused partition, it displays an error message, and I have no idea what is using it, which is just 64 MB of space empty.

    Could not complete because the partition is opened or used, it could be defined as a system, boot, virtual memory or keep a file print damage.

    Partition (t) is used at the moment, if you force to delete this partition, please press Yes
    WARNING: remove force may cause the application using this partition accidentally error, do you want to continue?

    It seems to me strange on this partition, there no hidden on this activity?

    I tried Process Monitor v3.1, but have no idea on how to perceive what that activity within a specific partition.

    Someone has suggestions on all the tools to track what turns HARD drive?

    Thanks in advance for your suggestions :>

    Process Monitor v3.1

    http://TechNet.Microsoft.com/en-us/Sysinternals/bb896645.aspx

    Well the task mgr shows all running, but it still gives no details.

    To see what works on commissioning, go in run, type: Msconfig

    Also, for more information, go in run, type: services.msc

    MSC, scroll through, double-click a serice, chk on the properties, also

    Open the tab dependencies, see what works with a service...

  • How to record what is happening by the sound card without using the microphone to avoid loss of quality.

    I tried, but there is no "Stereo mix" available options. There is only the (Conexant High Definition Audio) Microphone. It did not work. What I'll do is to buy a DVD for TV (tv Record program) burner and plug the hdmi cable from my computer to the DVD recorder and record what I want. After that, I just rip the audio from the file. I see no other option to do. I use windows vista Home premium.

    I would like to know how I can record the sound that is played by the soundcard using Vista without using the microphone as a source. Let's say the audio is played (audio stream) and I want to record this stream. There are many software that we can download that record what is happening in the microphone. The sound bounces off the speakers to the microphone. But when this happens, you lose a lot of the quality of the audio. So my question is if it is possible to record what is happening to the right of the sound card, before being sent to the sound card in order to avoid the loss of audio quality.

    ==============================
    Movie Maker has an option to record Narration...
    (Tools / tell the chronology). If you select stereo mix
    as the "Audio Input Source", you can save the
    Audio online. Your speakers and microphone are
    not required.

    And... maybe this link will help:

    How to record Internet radio stations on Windows Vista (using Audacity)
    http://www.ehow.com/how_4604071_record-Internet-radio-Windows-Vista.html John Inzer - MS - MVP - digital media experience

  • can keyboard usuage:How I insert a number 2 at the upper right part of 10 to represent 10 squared?

    How can I insert a number 2 at the upper right part of 10 to represent 10 squared? Similarly, if I wanted to display oxygen gas, whose symbol is uppercase O with a number 2 at the bottom right of the letter O, can I do?

    Start - type in the search box-> find the table of characters at the top of list - Double click on it.

    on the line of police - click on the arrow down and select the font you want - then Double click on a character
    and at the bottom right will be the main features this character to the product.

    How to use the character map in Vista
    http://www.Vistax64.com/tutorials/93584-character-map.html

    Using special characters (character map): frequently asked questions
    http://Windows.Microsoft.com/en-us/Windows-Vista/using-special-characters-character-map-frequently-asked-questions

    These can help:

    Special ALT characters
    http://www.tedmontgomery.com/Tutorial/altchrc.html

    ALT Codes / key Codes Alt
    http://usefulshortcuts.com/ALT-codes

    I hope this helps.

    Rob Brown - MS MVP - Windows Desktop Experience: Bike - Mark Twain said it right.

  • If I am trying to speed up my computer, how to understand what programs to uninstall? According to troubleshoot, he suggested I uninstall programss that run at startup.

    My compaq is so slow, and I'm trying to understand what programs to uninstall to try sppeed process, among other issues. I am not notified with the office. I'm also, thanked the community for your respose to my first question last week... so far, everything is going well w / windows media player.

    Depends on what exactly you mean by "acceleration".

    Uninstalling a program is unlikely to have an impact on performance

  • How to create a group/list of the variables in the box for display in the text field, in the format in annex

    I need to identify a series of variables single-response checkbox and display links selected (as a group) in a text field in an annex (comma, space) format. Last week, you provided a small script for a similar requirement by using the list box (multiple response) variables. This time, I need to know how to identify the variables of the box officially and, presumably, use a similar script to display the results in a comma, space format.

    You've been a great help.

    Thank you

    Here's the script for this situation. It assumes there are ten boxes named cb1, cb1, cb2,... cb10.

    // Custom Calculate script for text field
    (function () {
    
        // Initialize the string
        var v, s = "";
    
        // Loop through the check boxes to build up a string
        for (var i = 1; i < 11; i++) {
    
            // Get the value of the current check box
            v = getField("cb" + i).value;
    
            if (v !== "Off") {
                if (s) s += ", ";  // Add a comma and a space if needed
                s += v;  // Add the selected value
            }
        }
    
        // Set this field value to the string
        event.value = s;
    
    })();
    

    You will have to change the name of the field and start/end numbers to match your form.

  • When you use a left and right axis, how to choose what issed axis for the value of y GetGraphCursor?

    I use a graph with a left and right axis (2 data sets).  I try to use a slider to select a point in time (x) and the values of y in the two sets of data.  I can't understand how the control, the value that is returned for the value is when you use the GetGraphCursor call.

    GetGraphCursor (panelHandle, PANEL_GRAPH, yourCursorNumber, & x & y)

    Using SetCursorAttribute with the attribute ATTR_CURSOR_YAXIS must be what you are looking for. The online help for this attribute explains wery well:

    Description: Used to change the y-axis which is associated with the bar graph.
    When a graphics cursor is created, the Y axis with which it is associated is determined by the value of ATTR_ACTIVE_YAXIS.  Subsequently, the association can be changed using ATTR_CURSOR_YAXIS.
    The y-axis associate serves as reference for the coordinates of the cursor position in calls to SetGraphCursor and GetGraphCursor.

  • understand what to remove from the iPad

    I have a 32 GB iPad mini

    I continue to receive messages that the storage capacity is full and I have to delete something...

    I can't understand which fits all this space, I have a ton of HD movies out there or anything like that...

    perhaps I should simply get rid of all my photos and add just sometimes a few extraordinary those back in?

    is there a quick guide somewhere in the management of the photos on the iPad?

    also I understand whatever it is to remove... I need room for a few episodes of SOUTH PARK (small capacity) I don't want to watch!

    (either by the way streaming services like hulu, never work for me - mainly because I can never get the wi - fi works in the gym...)

    Thanks for the input / return.

    w

    Go to settings > general > use iCloud and storage > storage and see which occupies the space of storage of your iPad. Remove what you think, you need to delete.

    There is another way. Apple throws sometimes ios all the garbage system until the / other directory. If this is the case and you don't see that something is your space in the iPad settings, connect your iPad to iTunes. If 'Other' directory of storage can hold up to 3 GB, it's time to worry because you can then erase your iPad completely.

    Also. If you have movies and movies stored on your computer, you can load them onto your device using telegram - great messaging application (it supports files up to 1.5 GB, unlimited and free).

  • How to identify what items appear in the search

    I have Robohelp HTML 7 and I'm trying to find a way to tag topics I want will appear when a user searches for the project. I have a few topics I've used as popups and do not want them to appear in my search. In its current form, I don't know how to eliminate these selected topics or if this is even possible. Any help on this matter would be most appreciated.

    Thank you
    Paula

    See previews on my site. There is a link to a blog Adobe describing how to exclude topics.

  • How to limit what is shown on the recording sessions

    Is it possible to stop for example the participant and poll pods that appears in the record that is just to show the presentation and have the audio during recording sessions?

    Any advice appreciated

    Thanks in advance

    When you are in the registration tool to edit, you can click on the settings button in the lower left corner and you'll be able to obfuscate the names of participants and you can hide the cat. Participant and Q & A pods. This does not give more real estate to the presentation, but it prevents these pods to be seen. You can draw attention to the button full screen which is at the top of the module sharing with the presentation in it. The record Viewer can click and only watch the presentations.

    The other alternative is to take the audio from the recording and use it to create a Presenter presentation. I've done several times, but this is not necessarily a quick process. But it does not give rise to a presentation that is just the set of slides and audio.

  • How to make a URL mapping on the variables contained in a constant of cluster? [Web service]

    I am trying to create a web service and I would be like at the URL mapping, some controls that I just completed in a cluster control.  I have three control identical cluster, each with a unique name - but they contain variables that do not have unique names. e.g. ClusterA.dog, ClusterB.dog, ClusterC.dog...

    How can I distinguish between these variables when trying to URL mapping?

    Thanks for any help.

    Hi 5thGen,.

    Unfortunately, the clusters are not supported in Web services. You must provide a unique name for each entry.

  • How is it, I can't convert the variable root to a MovieClip?

    In one of my classes customized for my program, I try to access the main scenario for the breast. The following is the code that I've used before, but for some reason any doesn't seem to work now. The full error I get (during execution, is not during the compilation) is

    [code]

    TypeError: Error #1034: Type coercion failed: cannot convert flash.display::Stage@28132041 to flash.display.MovieClip.

    to ButtonGame / onAddedToStage)

    at flash.display::DisplayObjectContainer/addChild()

    at flash.display::Stage/addChild()

    at RECOVER_CoinGame_fla::MainTimeline/frame2()

    [/ code]

    And my code is:

    [code]

    package {}

    import flash.display.MovieClip;

    import flash.events.Event;

    import flash.media.Sound;

    import flash.events.MouseEvent;

    SerializableAttribute public class ButtonGame extends MovieClip

    {private var _root:Object;}

    private var buttonSound1:Sound;

    public void ButtonGame (btnX:int, btnY:int, btnWidth:int, btnHeight:int, btnString:String)

    {

    addEventListener (MouseEvent.CLICK, clickHandler);

    addEventListener (Event.ADDED_TO_STAGE, onAddedToStage);

    }

    function onAddedToStage(e:Event):void

    {

    _root = MovieClip (root); Code. that the error refers.

    buttonSound1 = _root._resource. CoinSound;

    removeEventListener (Event.ADDED_TO_STAGE, onAddedToStage);

    }

    private void clickHandler(e:MouseEvent):void

    {

    buttonSound1.play ();

    }

    }

    }

    [/ code]

    And this same exact code worked in another class, but for some reason any, it seems not work for it.

    Please help I have been stuck on this for about an hour, tried many different things and internet research.

    -Thank you

    Alright.

    the problem is that you add to your instance of ButtonGame to the scene:

    stage.addChild (yourButtonGameinstance);

    in this case, the highest display for your instance of ButtonGame object is the scene.

  • How to understand the time VI?

    Hello

    I use LV 8.6, and I'm curious to know how to understand statistics 'VI time' under the 'profile Performance and memory window.

    I let one of my screws "continuous run" for about 5 seconds, but in the profile window, time of VI out 1.17 seconds, while the SubVIs time is 0. If I understand well of the Help window, 'VI time' represents the time spent executing the code of the VI, what happens for the other 4 seconds? It is confusing to me because I did similar tests on other screws (with no subVIs), and it seems the faster of the VI, more time to VI is.

    Thank you very much.

    The time you see reported is the total of all the slices of the CPU used by the code.

    If the VI took 1 msec to start upward, then did a waiting for 1 second and then outputs, you should expect the total duration of about 1-5 ms alothough the run time in total was much more than that.

    Ben

  • How to automatically load the variable attributes in an Essbase app?

    Hi gurus,

    E.M.P. 11.1.2 Oracle 11 database as repository and staging area, EPMA as tool to update the metadata in the Planning, Essbase and HFM applications.

    Question: One of our Essbase cubes, to a dimension of variable attributes (in addition to the scenario and year dimensions).
    What are the tools that we could use to automatically load the dimension?
    I understand that EPMA cannot handle the variable attributes.
    We would like to use the rules of classic schema generation, but I don't know if it works or how to do it.

    Any help will be appreciated,
    Thank you
    Daniela

    I think you might be to look Studio if you want to build variable attributes.

    See you soon

    John
    http://John-Goodwin.blogspot.com/

Maybe you are looking for