A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Displaying Score in the textfield

  1. #1
    Registered User
    Join Date
    Aug 2013
    Posts
    2

    Displaying Score in the textfield

    I am developing an android drag and drop game..I have a dynamic textfield name score1. when I use the command trace the score calculates correctly according to its calculation formula..but when i want to display it to the textfield it don't appear..can anyone help me?

    Code:
    stop();
    import flash.text.TextFormat;
    import flash.text.TextField;
    
    //Score
    var score:Number=0;
    
    
    
    btn_nextCO1.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndPlayFromFrame);
    
    function fl_ClickToGoToAndPlayFromFrame(event:MouseEvent):void
    {
    	item1_mc.visible=false;
    		item2_mc.visible=false;
    		item3_mc.visible=false;
    		item4_mc.visible=false;
    		item5_mc.visible=false;
    		item6_mc.visible=false;
    		item7_mc.visible=false;
    		item8_mc.visible=false;
    		item9_mc.visible=false;
    	gotoAndPlay(345);
    }
    
    
    
    import flash.events.MouseEvent;
    import flash.display.MovieClip;
    import flash.text.TextFormat;
    
    //right_mc.visible=false;
    //wrong_mc.visible=false;
    
    var orig1X:Number=item1_mc.x;
    var orig1Y:Number=item1_mc.y;
    var orig2X:Number=item2_mc.x;
    var orig2Y:Number=item2_mc.y;
    var orig3X:Number=item3_mc.x;
    var orig3Y:Number=item3_mc.y;
    var orig4X:Number=item4_mc.x;
    var orig4Y:Number=item4_mc.y;
    var orig5X:Number=item5_mc.x;
    var orig5Y:Number=item5_mc.y;
    var orig6X:Number=item6_mc.x;
    var orig6Y:Number=item6_mc.y;
    var orig7X:Number=item7_mc.x;
    var orig7Y:Number=item7_mc.y;
    var orig8X:Number=item8_mc.x;
    var orig8Y:Number=item8_mc.y;
    var orig9X:Number=item9_mc.x;
    var orig9Y:Number=item9_mc.y;
    
    item1_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragTheObject);
    item1_mc.addEventListener(MouseEvent.MOUSE_UP, item1Release);
    item2_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragTheObject);   
    item2_mc.addEventListener(MouseEvent.MOUSE_UP, item2Release);   
    item3_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragTheObject);    
    item3_mc.addEventListener(MouseEvent.MOUSE_UP, item3Release);    
    item4_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragTheObject);    
    item4_mc.addEventListener(MouseEvent.MOUSE_UP, item4Release);
    item5_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragTheObject);    
    item5_mc.addEventListener(MouseEvent.MOUSE_UP, item5Release);
    item6_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragTheObject);    
    item6_mc.addEventListener(MouseEvent.MOUSE_UP, item6Release);
    item7_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragTheObject);    
    item7_mc.addEventListener(MouseEvent.MOUSE_UP, item7Release);
    item8_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragTheObject);    
    item8_mc.addEventListener(MouseEvent.MOUSE_UP, item8Release);
    item9_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragTheObject);    
    item9_mc.addEventListener(MouseEvent.MOUSE_UP, item9Release);
    
    
    done_btn.addEventListener(MouseEvent.CLICK, checkAnswers);
    reset_btn.addEventListener(MouseEvent.MOUSE_UP,reset);
    
    item1_mc.buttonMode=true;
    item2_mc.buttonMode=true;
    item3_mc.buttonMode=true;
    item4_mc.buttonMode=true;
    item5_mc.buttonMode=true;
    item6_mc.buttonMode=true;
    item7_mc.buttonMode=true;
    item8_mc.buttonMode=true;
    item9_mc.buttonMode=true;
    
    function dragTheObject(event:MouseEvent):void
    {
    	var item:MovieClip=MovieClip(event.target);
    	item.startDrag();
    	var topPos:uint=this.numChildren-1;
    	this.setChildIndex(item,topPos);
    }
    
    function item1Release(event:MouseEvent):void
    {
    	var item:MovieClip=MovieClip(event.target);
    	item.stopDrag();
    	if (dropZone1_mc.hitTestPoint(item.x,item.y))
    	{
    		item.x=dropZone1_mc.x;
    		item.y=dropZone1_mc.y;
    		score+=10;
    		//score1.text=String(score);
    		score1.text=""+score.toString();
    		trace(score);
    	}
    	else
    	{
    		item.x=orig1X;
    		item.y=orig1Y;
    		score-=10;
    		score1.text=""+score.toString();
    		trace(score);
    	}
    };
    
    function item2Release(event:MouseEvent):void { 
        var item:MovieClip=MovieClip(event.target); 
        item.stopDrag();   
        if (dropZone2_mc.hitTestPoint(item.x,item.y)) { 
            item.x=dropZone2_mc.x; 
            item.y=dropZone2_mc.y; 
    		score+=10;
    		score1.text=""+score.toString();
    		trace(score);
        } else { 
            item.x=orig2X; 
            item.y=orig2Y; 
    		score-=10;
    		score1.text=""+score.toString();
    		trace(score);
        } 
    };    
    
    function item3Release(event:MouseEvent):void { 
        var item:MovieClip=MovieClip(event.target); 
        item.stopDrag();   
        if (dropZone3_mc.hitTestPoint(item.x,item.y)) { 
            item.x=dropZone3_mc.x; 
            item.y=dropZone3_mc.y; 
    		score+=10;
    		score1.text=""+score.toString();
    		trace(score);
        } else { 
            item.x=orig3X; 
            item.y=orig3Y; 
    		score-=10;
    		score1.text=""+score.toString();
    		trace(score);
        } 
    }; 
    
    function item4Release(event:MouseEvent):void { 
        var item:MovieClip=MovieClip(event.target); 
        item.stopDrag();   
        if (dropZone4_mc.hitTestPoint(item.x,item.y)) { 
            item.x=dropZone4_mc.x; 
            item.y=dropZone4_mc.y; 
    		score+=10;
    		score1.text=""+score.toString();
    		trace(score);
        } else { 
            item.x=orig4X; 
            item.y=orig4Y; 
    		score-=10;
    		score1.text=""+score.toString();
    		trace(score);
        } 
    };
    
    function item5Release(event:MouseEvent):void { 
        var item:MovieClip=MovieClip(event.target); 
        item.stopDrag();   
        if (dropZone5_mc.hitTestPoint(item.x,item.y)) { 
            item.x=dropZone5_mc.x; 
            item.y=dropZone5_mc.y; 
    		score+=10;
    		score1.text=""+score.toString();
    		trace(score);
        } else { 
            item.x=orig5X; 
            item.y=orig5Y;
    		score-=10;
    		score1.text=""+score.toString();
    		trace(score);
        } 
    };
    
    
    function item6Release(event:MouseEvent):void { 
        var item:MovieClip=MovieClip(event.target); 
        item.stopDrag();   
        if (dropZone6_mc.hitTestPoint(item.x,item.y)) { 
            item.x=dropZone6_mc.x; 
            item.y=dropZone6_mc.y; 
    		score+=10;
    		score1.text=""+score.toString();
    		trace(score);
        } else { 
            item.x=orig6X; 
            item.y=orig6Y; 
    		score-=10;
    		score1.text=""+score.toString();
    		trace(score);
        } 
    };
    
    
    function item7Release(event:MouseEvent):void { 
        var item:MovieClip=MovieClip(event.target); 
        item.stopDrag();   
        if (dropZone7_mc.hitTestPoint(item.x,item.y)) { 
            item.x=dropZone7_mc.x; 
            item.y=dropZone7_mc.y; 
    		score+=10;
    		score1.text=""+score.toString();
    		trace(score);
        } else { 
            item.x=orig7X; 
            item.y=orig7Y;
    		score-=10;
    		score1.text=""+score.toString();
    		trace(score);
        } 
    };
    
    function item8Release(event:MouseEvent):void { 
        var item:MovieClip=MovieClip(event.target); 
        item.stopDrag();   
        if (dropZone8_mc.hitTestPoint(item.x,item.y)) { 
            item.x=dropZone8_mc.x; 
            item.y=dropZone8_mc.y; 
    		score+=10;
    		score1.text=""+score.toString();
    		trace(score);
        } else { 
            item.x=orig8X; 
            item.y=orig8Y; 
    		score-=10;
    		score1.text=""+score.toString();
    		trace(score);
        } 
    };
    
    function item9Release(event:MouseEvent):void { 
        var item:MovieClip=MovieClip(event.target); 
        item.stopDrag();   
        if (dropZone9_mc.hitTestPoint(item.x,item.y)) { 
            item.x=dropZone9_mc.x; 
            item.y=dropZone9_mc.y; 
    		score+=10;
    		score1.text=""+score.toString();
    		trace(score);
        } else { 
            item.x=orig9X; 
            item.y=orig9Y; 
    		score-=10;
    		score1.text=""+score.toString();
    		trace(score);
        } 
    };
    
    function checkAnswers(event:MouseEvent):void { 
        if (dropZone1_mc.hitTestPoint(item1_mc.x,item1_mc.y) && 
                dropZone2_mc.hitTestPoint(item2_mc.x,item2_mc.y) && 
                dropZone3_mc.hitTestPoint(item3_mc.x,item3_mc.y)&&
    			dropZone4_mc.hitTestPoint(item4_mc.x,item4_mc.y)&&
    			dropZone5_mc.hitTestPoint(item5_mc.x,item5_mc.y)&&
    			dropZone6_mc.hitTestPoint(item6_mc.x,item6_mc.y)&&
    			dropZone7_mc.hitTestPoint(item7_mc.x,item7_mc.y)&&
    			dropZone8_mc.hitTestPoint(item8_mc.x,item8_mc.y)&&
    			dropZone9_mc.hitTestPoint(item9_mc.x,item9_mc.y)
    			) {
           // wrong_mc.visible = false;
            //right_mc.visible = true;
    		item1_mc.visible=false;
    		item2_mc.visible=false;
    		item3_mc.visible=false;
    		item4_mc.visible=false;
    		item5_mc.visible=false;
    		item6_mc.visible=false;
    		item7_mc.visible=false;
    		item8_mc.visible=false;
    		item9_mc.visible=false;
    		gotoAndPlay(346);
        } else {
           // wrong_mc.visible = true;
            //right_mc.visible = false;
    		item1_mc.visible=false;
    		item2_mc.visible=false;
    		item3_mc.visible=false;
    		item4_mc.visible=false;
    		item5_mc.visible=false;
    		item6_mc.visible=false;
    		item7_mc.visible=false;
    		item8_mc.visible=false;
    		item9_mc.visible=false;
    		
    		
    		gotoAndPlay(346);
        }
    }
    
    function reset(event:MouseEvent):void { 
        item1_mc.x=orig1X; 
        item1_mc.y=orig1Y;     
        item2_mc.x=orig2X; 
        item2_mc.y=orig2Y;
        item3_mc.x=orig3X; 
        item3_mc.y=orig3Y; 
    	item4_mc.x=orig4X; 
        item4_mc.y=orig4Y;
    	item5_mc.x=orig5X; 
        item5_mc.y=orig5Y;
    	item6_mc.x=orig6X; 
        item6_mc.y=orig6Y;
    	item7_mc.x=orig7X; 
        item7_mc.y=orig7Y;
    	item8_mc.x=orig8X; 
        item8_mc.y=orig8Y;
    	item9_mc.x=orig9X; 
        item9_mc.y=orig9Y;
           
        //right_mc.visible=false; 
        //wrong_mc.visible=false;
    
    	
    };
    /* Click to Go to Frame and Play
    Clicking on the specified symbol instance moves the playhead to the specified frame in the timeline and continues playback from that frame.
    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.
    */
    
    btn_backO.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndPlayFromFrame_11);
    
    function fl_ClickToGoToAndPlayFromFrame_11(event:MouseEvent):void
    {
    	item1_mc.visible=false;
    		item2_mc.visible=false;
    		item3_mc.visible=false;
    		item4_mc.visible=false;
    		item5_mc.visible=false;
    		item6_mc.visible=false;
    		item7_mc.visible=false;
    		item8_mc.visible=false;
    		item9_mc.visible=false;
    	gotoAndPlay(325);
    }

  2. #2
    Senior Member
    Join Date
    Nov 2001
    Posts
    1,145
    It's hard to tell what the issue is without seeing the textfield in the .fla. Are you getting any error messages? If you have the wrong path you'll get an error. Is the font the same color as the background? Covered? Is there an issue with a loaded font?

    Programming wise, you need to clean up your code too. A simple rule that might help is that when you look at your code (simply look at the words), you shouldn't see anything repeating. For example, in your first function you see this reapeating "item1_mc.visible=false;" with only the number changing. So replace the only part that changes with a variable and use a "for" loop:

    Code:
    for(var i:int = 0; i < 10; i++){
    		this["item" + i + "_mc"].visible = false;
    	}
    See how the above code doesn't repeat? I know I could find better words for what I'm trying to say.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center