dcsimg
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: two problems

  1. #1
    Junior Member
    Join Date
    Feb 2010
    Posts
    10

    two problems

    Problem: I used the following code to capture user's name however it will always ignore the first character user has entered, is there a way to solve it.
    <code>
    name_txt.addEventListener(TextEvent.TEXT_INPUT,inp utEventCapture);

    public function inputEventCapture(event:TextEvent):void {
    nameofPlayer1=name_txt.text;
    trace(nameofPlayer1);
    btnglow.mouseEnabled=true;
    btnglow.gotoAndPlay(2);
    btnglow.addEventListener(MouseEvent.CLICK,nextfram e);
    }

    </code>
    my second problem is adding eventlistener, I generated 7 characters using the code below, I hope to addeventlistener to each of the characters I generated, how can that be achived. All help appreciated
    <code>
    for (i=2; i<9; i++) {
    ClassReference=getDefinitionByName('b'+character) as Class;
    tempchar = new ClassReference();
    tempchar.x=(i-1)*95;
    tempchar.y=200;
    tempchar.name=characterarr[character]+i;
    trace(tempchar.name)
    addChild(tempchar);
    }

    </code>

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Code:
    name_txt.addEventListener(TextEvent.TEXT_INPUT,inputEventCapture);
    
    function inputEventCapture(event:TextEvent):void {
    	nameofPlayer1=name_txt.text+event.text;
    	trace(nameofPlayer1);
    	btnglow.mouseEnabled=true;
    	btnglow.gotoAndPlay(2);
    	btnglow.addEventListener(MouseEvent.CLICK,nextframe);
    }
    
    
    for (var i=2; i<9; i++) {
    	ClassReference=getDefinitionByName('b'+character) as Class;
    	tempchar = new ClassReference();
    	tempchar.x=(i-1)*95;
    	tempchar.y=200;
    	tempchar.name=characterarr[character]+i;
    	trace(tempchar.name);
    	addChild(tempchar);
    	tempchar.addEventListener(MouseEvent.CLICK,showName);
    }
    function showName(e:Event):void {
    	trace(e.currentTarget.name);
    }

  3. #3
    Junior Member
    Join Date
    Feb 2010
    Posts
    10
    thanks

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