A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: [RESOLVED] Sticky setFocus & non-functioning tabs

  1. #1
    Member
    Join Date
    Aug 2014
    Posts
    51

    resolved [RESOLVED] Sticky setFocus & non-functioning tabs

    Hi fruitbeard and all else,

    I am back with some more problems in AS2.0

    Find attached a small snipped of code. It creates two run time input boxes.
    The first box is named TypeA & the 2nd TypeB

    Once it does that it gives an initial text value of "Go" to TypeA and then calls a timer to display the 2 boxes which remain on screen for a duration of 9 seconds and are then refreshed so to speak i.e. the value of TypeA is set back to go and the boxes are displayed again.

    The problems that I face.

    1. I wanted the program to end if i typed "end" in TypeA box. It does not end. Some silly mistake that I cannot find in the logic.

    2. Because of the way the timers are set, the time taken by the boxes to appear is 9 seconds. What should happen is that the boxes should appear immediately and then they should refresh every 9 seconds. The first 9 seconds of wait makes the program appear to hang.

    3. The very first time the program is run, Go appears and focus is set to it as can be seen. However if I try and use the tab-key to alternate between the 2 boxes, it does not do so . This tabbing has no effect. It however starts to tab through the flash IDE. Further it does not permit the usage of the back slash key to clear GO. If I directly type something when "GO" appears on the first run, the typed text does not automatically replace "GO" as it should ( just like the backspace key fails so do all the keyboard keys). If however I use the mouse once and click inside the box, the caret appears inside the box and the focus goes as also all of the problems that I mentioned in this paragraph above .

    So how can I achieve this programmatically so that it behaves like I want it to even the first time with the focus on "GO". I mean that Go should be over written by the keys I type & the backspace should delete "GO" & the tab should work normally alternating between the two boxes.

    Please help. Thanks loads
    Attached Files Attached Files
    Last edited by ajoo; 09-05-2014 at 11:09 AM. Reason: forgot to attach the file

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,785
    Hi,

    I shall take a look now, the tab key will work if you publish swf and then select Control -> disable keyboards shortcuts

  3. #3
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,785
    I understand it but what on earth is all sw / 3 - bw / 3,.57 * sh - bh / 2,bw - 50,bh this about??, I'm sure you have your reasons though.

  4. #4
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,785
    Hi,

    Without really knowing what your trying to achieve!!

    If you add the extra frame 10 to your file with a stop(); and maybe an image or box to show that it is frame 10.
    PHP Code:
    stop();

    var 
    sw 550;
    var 
    sh 400;
    var 
    bw 200;
    var 
    bh 80;

    createTextFields()

    function 
    createTextFields():Void
    {
        
    this.createTextField("TypeA",10,sw bw 3,.57 sh bh 2,bw 50,bh);
        
    this["TypeA"].tabIndex 1;
        
    this["TypeA"].border true;
        
    this["TypeA"].borderColor 0xFF0000;
        
    this["TypeA"].background true;
        
    this["TypeA"].type "input";
        
    this["TypeA"].maxChars 5;
        
    this["TypeA"].restrict "A-z";

        
    this.createTextField("TypeB",11,* (sw 3) - bw 3,.57 sh bh 2,bw 50,bh);
        
    this["TypeB"].tabIndex 2;
        
    this["TypeB"].border true;
        
    this["TypeB"].borderColor 0xFF0000;
        
    this["TypeB"].background true;
        
    this["TypeB"].type "input";
        
    this["TypeB"].maxChars 4;
        
    this["TypeB"].restrict "A-z";

        var 
    tfInptxt:TextFormat = new TextFormat();
        
    tfInptxt.size 28;
        
    tfInptxt.font "Arial";
        
    tfInptxt.align "center";

        
    this["TypeB"].setNewTextFormat(tfInptxt);
        
    this["TypeA"].setNewTextFormat(tfInptxt);

        
    boxID setInterval(write500);
    }

    function 
    write()
    {
        
    clearInterval(boxID);
        if (
    TypeA.text == "end")
        {
            
    clearInterval(writeID);
            
    clearInterval(boxID);
            
    gotoAndStop(10);
            return;
        }

        
    TypeA.text "Go";
        
    Selection.setFocus(TypeA);
        
    writeID setInterval(ans_rem_box8000);
    }

    function 
    ans_rem_box()
    {
        
    clearInterval(writeID);
        
    boxID setInterval(write500);

    and remember to disable Keyboard shortcuts in the cntrl-enter swf

  5. #5
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,785
    Hi,

    I'm still a little confused as to why you used all the formula to place your textfields?

    was just playing around, the code is essentially the same as above , just with the formula stuff added

    PHP Code:
    stop();

    var 
    sw:Number 550;
    var 
    sh:Number 400;
    var 
    bw:Number 200;
    var 
    bh:Number 80;

    createTextFields();

    function 
    createTextFields():Void
    {
        var 
    tx1:Number Math.floor((sw 3) - (bw 3));
        var 
    tx2:Number Math.floor(* (sw 3) - (bw 3));
        var 
    ty:Number Math.floor((.57 sh) - (bh 2));
        var 
    tw:Number bw 50;
        var 
    th:Number bh;

        
    trace("TypeA._x = " tx1);
        
    trace("TypeB._x = " tx2);
        
    trace("Both._y = " ty);
        
    trace("Both._width = " tw);
        
    trace("Both._height = " th);
        
        
    // *** End of mess
        
        
        //this.createTextField("TypeA",10, Math.floor((sw / 3) - (bw / 3)),Math.floor((.57 * sh) - (bh / 2)),bw - 50,bh);
        //this.createTextField("TypeA", 10, tx1, ty, tw, th);
        
    this.createTextField("TypeA",10,116,187,150,80);
        
    this["TypeA"].tabIndex 1;
        
    this["TypeA"].border true;
        
    this["TypeA"].borderColor 0xFF0000;
        
    this["TypeA"].background true;
        
    this["TypeA"].type "input";
        
    this["TypeA"].maxChars 5;
        
    this["TypeA"].restrict "A-z";

        
    //this.createTextField("TypeB",11, Math.floor(2 * (sw / 3) - (bw / 3)),Math.floor((.57 * sh) - (bh / 2)),bw - 50,bh);
        //this.createTextField("TypeB", 11, tx2, ty, tw, th);
        
    this.createTextField("TypeB",11,300,187,150,80);
        
    this["TypeB"].tabIndex 2;
        
    this["TypeB"].border true;
        
    this["TypeB"].borderColor 0xFF0000;
        
    this["TypeB"].background true;
        
    this["TypeB"].type "input";
        
    this["TypeB"].maxChars 4;
        
    this["TypeB"].restrict "A-z";

        var 
    tfInptxt:TextFormat = new TextFormat();
        
    tfInptxt.size 28;
        
    tfInptxt.font "Arial";
        
    tfInptxt.align "center";

        
    this["TypeB"].setNewTextFormat(tfInptxt);
        
    this["TypeA"].setNewTextFormat(tfInptxt);

        
    boxID setInterval(write500);
    }

    function 
    write()
    {
        
    clearInterval(boxID);
        if (
    TypeA.text == "end")
        {
            
    clearInterval(writeID);
            
    clearInterval(boxID);
            
    gotoAndStop(10);
            return;
        }

        
    TypeA.text "Go";
        
    Selection.setFocus(TypeA);
        
    writeID setInterval(ans_rem_box8000);
    }

    function 
    ans_rem_box()
    {
        
    clearInterval(writeID);
        
    boxID setInterval(write500);


  6. #6
    Member
    Join Date
    Aug 2014
    Posts
    51
    Hi fruitbeard,

    Once again I am logging in late bcoz I knew you would have replied and well you have 4 times !! Thanks loads, Will do as you suggested and revert tomorrow.

    The reason for all these sw / 3 - bw / 3,.57 * sh - bh / 2,bw - 50,bh was just to find the right placement for the boxes and to maintain the relative spacing if the screen size was to be changed later. These co-ordinates kindl of divide the screen into near 3 halves and place the two boxes near equally along the width of the screen. If you think that these are not great please suggest something better.

    Will revert with the results of your suggestions here.
    Have a nice day & thanks loads.

  7. #7
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,785
    Hi,

    No. 5

    Your calculations were wrong and it did not stay where you wanted it to upon changing swf dimensions, central basically.

    You can put the text inside a container and apply x,y to the container, anyway here is the file for you to plunder.

    Why so many little test type things, you must have some very odd little project going on.


    P.s remember the disable Keyboard shortcuts if it hasn't already sank in.

  8. #8
    Member
    Join Date
    Aug 2014
    Posts
    51
    Hi fruitbeard,

    Thanks again for the reply.

    I admit I had not tested the co-ordinates. It's a very rare phenomenon that a piece of complex code at times achieves exactly what is desired at the first go and that's what happened with these co-ordinates. I would like to look into them in detail later though. Thanks for checking it.

    The file for plunder did not let me do so. I got an invalid file format. I have Flash CS3. Kindly resend it.

    Thanks loads !! You are the best !

  9. #9
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,785
    Hi,

    Unfortunately I use CS6 and can only save as low as CS5

    Here is the code I have used with an empty clip with AS Linkage of textContainer

    PHP Code:
    stop();

    var 
    sw:Number 550;
    var 
    sh:Number 400;
    var 
    bw:Number 150;
    var 
    bh:Number 80;
    var 
    textSpacer:Number 30;

    var 
    textType:Array = new Array("TypeA""TypeB");
    var 
    maxChar:Array = new Array(54);
    var 
    xPos:Array = new Array(0, (bw textSpacer));

    createTextFields();

    function 
    createTextFields():Void
    {
        var 
    tfInptxt:TextFormat = new TextFormat();
        
    tfInptxt.size 28;
        
    tfInptxt.font "Arial";
        
    tfInptxt.align "center";

        
    attachMovie("textContainer","textContainer",0);
        var 
    textRef this["textContainer"];

        for (var 
    i:Number 0textType.lengthi++)
        {
            
    textRef.createTextField(textType[i],i,xPos[i],0,bw,bh);
            
    textRef[textType[i]].tabIndex i;
            
    textRef[textType[i]].border true;
            
    textRef[textType[i]].borderColor 0xFF0000;
            
    textRef[textType[i]].background true;
            
    textRef[textType[i]].type "input";
            
    textRef[textType[i]].maxChars maxChar[i];
            
    textRef[textType[i]].restrict "A-z";
            
    textRef[textType[i]].setNewTextFormat(tfInptxt);
        }

        
    textRef._x Math.floor((sw textRef._width) / 2);
        
    textRef._y Math.floor((sh textRef._height) / + (textRef._height 3));
        
    //textRef._y = Math.floor((sh - textRef._height) / 2);// for central;

        
    write();
    }

    function 
    write()
    {
        
    clearInterval(boxID);
        if (
    textContainer.TypeA.text == "end")
        {
            
    clearInterval(writeID);
            
    gotoAndStop(10);
            return;
        }

        
    textContainer.TypeA.text "Go";
        
    Selection.setFocus(textContainer.TypeA);
        
    writeID setInterval(ans_rem_box8000);
    }

    function 
    ans_rem_box()
    {
        
    clearInterval(writeID);
        
    boxID setInterval(write500);

    Last edited by fruitbeard; 09-06-2014 at 04:35 AM.

  10. #10
    Member
    Join Date
    Aug 2014
    Posts
    51
    Hi fruitbeard & all,

    Thanks again for the reply. So i created the textContainer, converted it to a movie and ran the program. It ran fine though the boxes were displaced out of the clip. One was inside it while the other divided the right side, lying half inside the box and half outside. I'll check the rest in detail later.

    The "end" worked fine and stopped the triggers completely. This "controls in containers is a great idea by fruitbeard" I shall explore it in length but later. For now this solves most of my issue and so a huge thanks again to fruitbeard for his awesome help, guidance and working examples. Will come back soon with more problems.

    Thanks !

  11. #11
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,785
    Hi,

    Im not sure why you have problems with the placing and stuff,

    This is CS3, perhaps you did something different!!

Tags for this Thread

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