game focusing on the sprite class

Hi, I'm tryin to set global focus to a specific class that already exists on the scene, after that I deleted a contextual dialog box on the screen. I pass the name of the class that was on the scene before the pop-up dialog box is displayed in the string to the popup class.

If public void PopupMenu(pClass:String)

Once I removed the pop-up dialog box, I want to restore developed in the previous class, so it can accept events key again.

How would I set the focus to an instance of an object on the stage. Currently, I have something like this:

Main.mainStage.focus = (InteractiveObject) (getDefinitionByName (prevClass));

but he returned this error: TypeError: Error #1034: Type coercion failed: cannot convert com.cox::IdleScreen$ in flash.display.InteractiveObject.

My IdleScreen class extends sprite, which is definitely on a higher level than InteractiveObject in the diagram to display objects. How can I set focus to this class on the stage?

I know it can be focused because I can do Main.mainStage.focus = this inside of the class and it works...

Mount the DisplayObject to InteractiveObject.

Main.mainStage.focus = Main.mainStage.getChildAt (2) as InteractiveObject;

Tags: Adobe Animate

Similar Questions

  • Confused about the extension of the Sprite class

    Howdy-

    I learn programming with object oriented ActionScript and am confused about the class Sprite and OO in general.

    My understanding is that the Sprite class allows you to group a set of objects that you can manipulate all the objects at the same time.

    I explored the Open Flash Chart code and note that the main class extends the Sprite class:

    Base/public class extends Sprite {}

    What this lets you do?

    Also, on a related note, how to draw, say, a line once I extended?

    Without extend Sprite I could write:

    var graphContainer:Sprite = new Sprite();

    var newLine:Graphics = graphContainer.graphics;

    ...

    And it works very well. Once I have extend the Sprite class, I'm lost. How can I modify this code so that it still draws a line? I tried:

    var newLine:Graphics = this.graphics;

    My understanding is that since I extend the Sprite class, I should still be able to call its method chart (or property? I have no idea). But, he screams at me, saying "1046: Type was not found or is not a constant of compilation: graphs.»

    A number of things.

    First of all, I would not use this approach in your table constructor. Setting the width and height only makes sense if you adjust the width and height of the existing content, and the table (Sprite) does not at this time here. If you want to give the table a 'size', you could do it like this:

    public function Chart (width: Number, height: Number) {}
    This.Width = width;
    This.Height = height;
    put in a background invisible to this size:
    this.graphics.beginFill (0,0);
    this.graphics.drawRect (0,0,width,height);
    }

    There are other ways, including putting in a form or a Sprite of child as a child for the background so that clear will not erase the background of the chart. This way you could have properties for the background in your table class and update the background as a child DisplayObject instance... a few ideas to think to...

    Then, after that, your chart should be functional...

    Then back in your scenario, you could do this:

    import graphics. Table;

    Stop()

    var myNewChart:Chart = new Chart (300,200)
    myNewChart.render ();
    addChild (myNewChart)

  • Older games focused on the Universal will run on recent Macs?

    I ask this because I recently stumbled on an old Mac game, I played 10 years. I'm tempted to buy a copy, so I can play again, but I don't know if it works on my machine of El Capitan. This is the game: http://www.amazon.com/Wingnuts-2-Mac/dp/B00009K780

    I know games PowerPC is more supported, but is universal games still OK?

    It depends on the game. Click here and look it up.

    (139960)

  • The label on the top of the Sprite event management

    Hi everyone, it's more of a general question of Actionscript, but Google does offer all the answers.

    So I made a custom component, element that extends the Sprite class. I draw things on the graphics in this class and then I add a Label to display text.

    In another class, where I create instances of the previous class, I add an EventListener for MouseEvent.Click.  In this function, there is this line:

    selectedElement = Element(event.target);
    

    In short, I want the variable selectedElement to contain the element on which click it. But I ran into problems, event.target is not always an instance of my class. If I click where the label is, event.target is a Label.

    How can I organize if click anywhere on my element, in particular on the label, it's the element of class that dispatches an event and not on its label. I think I need to intercept events of labels in some way, but no idea how to do this.

    Thank you in advance.

    Too bad, in the event class stopPropagation method has been what I was looking for.

  • Loss of the focus on the games

    Hey all!

    Whenever I play a game (wow, Hearthstone), the program lose focus every 5 to 20 seconds. It started happening when I downloaded the virus of air Navigator (Yes, I am a fool). I removed it from my pc (I think). So, I scan my pc with avast! and malwarebytes anti-malware, they both tell me my pc is clean, but this issue remains. When the program lose focus, task bar icons disappear and reappear quickly. If anyone can help me solve this problem, I would really appreciate it!

    Thank you!

    Hello

    Thanks for posting on Microsoft Communities.

    I'll be happy to help you with the problem you have with the computer. I understand the frustration when things do not work as it should.

    What is the brand and model of your computer?

    How sis you download the game on the computer?

    You have the same problem with all games?

    I suggest you check out the link below to check the compatibility of games with Windows 8.

    http://www.Microsoft.com/en-us/Windows/compatibility/WIN8/CompatCenter/home

    Method 1: Try to update the graphics card drivers and check if it works.

    Follow the steps to update the graphics driver:

    a. press the Windows key + X , and then click Device Manager.

    b. search for graphics cards.

    c. right-click on the graphics card and click Update driver software.

    Method 2: Install the game in Compatibility Mode.

    Follow the link below to install the game in Compatibility Mode.

    Make the programs more compatible with this version of Windows

    http://Windows.Microsoft.com/en-us/Windows-8/older-programs-compatible-version-Windows

    Please get back to us with the necessary information if the problem persists.

    If you have problems of Windows in the future, let us know and we would be happy to help you.

  • How can I play my old (early 90s) focused on the BACK of the games on my Vista PC?

    I have all the games strategy games Atomic of the V for victory and the world at war series.  I was able to install, but when I try to miss the DOS command prompt I get the message "this application does not support full screen... Click Close... ».  Is there a way I can run these games?  They gave me hours of entertainment at the time on my good old 486DX2 and now I'm pretty nostalgic for them.  You will appreciate all help!

    I think I have the solution you've been waiting for,

    To play your old dos based games you must download a program called DOSBOX.
    This program will allow your games be played on any version of windows including Vista.

    Give it a wirl, and soon you'll be crashing your way through these dos games like never before.

  • Code moves the timeline to the document class Error 1067

    Hey dudes encoder that I need help on some actionscript 3.

    Im trying to move a part of the timeline code in the document class. Here is the code to the timeline:

    Import Memory.MemoryGame;

    Add memory game

    var memoryGame:MemoryGame = new MemoryGame (this, "settings.xml");

    Here is my attempt to move in the Document class:

    Import Memory.MemoryGame;

    -----

    SerializableAttribute public class MemoryGame extends Sprite

    {

    private var memoryGame:MemoryGame;

    public void init(e:Event_=_null):void

    {

    memoryGame = new MemoryGame (this, "settings.xml");

    addChild (MemoryGame);

    }

    Then I get the error: ActionScript Error #1067: Implicit coercion of a value of type to a type unrelated flash.display.DisplayObject class

    Please help guys :-(

    No, I checked just because you have dc.addChild (this); which is meaningless, unless there is an object of class MemoryGame in your library.  You can delete that.

    change

    public void MemoryGame (dc:DisplayObjectContainer, xmlPath:String)

    {

    Save the params

    This.dc = dc;

    Add to the form

    dc.addChild (this);

    var r: Shape = new Shape();

    r.graphics.beginFill (0x000000);

    r.graphics.drawRect (0,0,800,500);

    r.graphics.endFill ();

    addChild (r);

    load the xml file

    loader = new BulkLoader ("memoryGame");

    loader.addEventListener (BulkProgressEvent.COMPLETE, LoaderComplete);

    loader.addEventListener (BulkLoader.ERROR, LoaderError, false, 0, true);

    Loader.Add (xmlPath, {id: "xmldata"});

    Loader.Start ();

    Add preloader

    g_preloader_back = new Shape();

    g_preloader_back. Graphics.beginFill (0x000000);

    g_preloader_back. Graphics.drawRect (0, 0, 200, 5);

    g_preloader_back. Graphics.endFill ();

    g_preloader_back.x = stage.stageWidth/2 - g_preloader_back.width / 2;

    g_preloader_back.y = stage.stageHeight/2 - g_preloader_back.height / 2;

    addChild (g_preloader_back);

    g_preloader_bar = new Shape();

    g_preloader_bar. Graphics.beginFill (0xFFFFFF);

    g_preloader_bar. Graphics.drawRect (0, 0, 196, 3);

    g_preloader_bar.y = stage.stageHeight/2 - g_preloader_bar.height / 2;

    addChild (g_preloader_bar);

    g_preloader_text = new QuickText (g_preloader_back.x, g_preloader_back.y + 10, 'Loading XML...', 10, 0, false, false, false, null);

    addChild (g_preloader_text);

    UpdatePreloader (null);

    Add the sound Manager

    soundManager = new KSGSound();

    }

    TO

    public void MemoryGame()

    {

    Save the params

    If you use "this.dc" anywhere else, replace it with 'this '.

    This.dc = dc;

    Add to the form

    dc.addChild (this);

    var r: Shape = new Shape();

    r.graphics.beginFill (0x000000);

    r.graphics.drawRect (0,0,800,500);

    r.graphics.endFill ();

    addChild (r);

    load the xml file

    var xmlPath:String = "settings.xml";

    loader = new BulkLoader ("memoryGame");

    loader.addEventListener (BulkProgressEvent.COMPLETE, LoaderComplete);

    loader.addEventListener (BulkLoader.ERROR, LoaderError, false, 0, true);

    Loader.Add (xmlPath, {id: "xmldata"});

    Loader.Start ();

    Add preloader

    g_preloader_back = new Shape();

    g_preloader_back. Graphics.beginFill (0x000000);

    g_preloader_back. Graphics.drawRect (0, 0, 200, 5);

    g_preloader_back. Graphics.endFill ();

    g_preloader_back.x = stage.stageWidth/2 - g_preloader_back.width / 2;

    g_preloader_back.y = stage.stageHeight/2 - g_preloader_back.height / 2;

    addChild (g_preloader_back);

    g_preloader_bar = new Shape();

    g_preloader_bar. Graphics.beginFill (0xFFFFFF);

    g_preloader_bar. Graphics.drawRect (0, 0, 196, 3);

    g_preloader_bar.y = stage.stageHeight/2 - g_preloader_bar.height / 2;

    addChild (g_preloader_bar);

    g_preloader_text = new QuickText (g_preloader_back.x, g_preloader_back.y + 10, 'Loading XML...', 10, 0, false, false, false, null);

    addChild (g_preloader_text);

    UpdatePreloader (null);

    Add the sound Manager

    soundManager = new KSGSound();

    }

  • Objects added to the Sprite/MC are not

    Hello everyone, I worked on a construction set and met a strange problem this morning, when instead of adding objects directly to the step that I had to add a Sprite (I also tried with a MovieClip) on the stage instead and they do not seem to. If anyone can see why this is happening, I will be eternally grateful, because it has left me speechless! And Yes, before anyone says, the MC/Sprite I add objects to a certainly added to the stage, I've made this mistake before and do not rely on what actually once again

    I essentially built the game levels using various different objects (rectangles, circles, etc.), built in the attached with sprites and Box2D physics engine to represent the user. During the creation of each of these object I provide a DisplayObjectContainer in which the sprite that represents the object should be placed. So far I've been simply supply my class of basic game as DisplayObjectContainer, with no problems whatsoever - everything is displayed properly. A new level design, however, it will take apply me a mask to the level (but not the GUI) so I decided to put all the objects level within a MovieClip or Sprite instead. I created the new sprite as such:

    levelObjects = new Sprite();
    levelObjects.x = levelObjects.y = 0; In order to ensure
    levelObjects.width = GameProperties.stageWidth;
    levelObjects.height = GameProperties.stageHeight;
    levelObjects.visible = true; In order to ensure
    addChild (levelObjects)

    and have provided this sprite for level objects like a DisplayObjectContainer instead of the base class. Everything is added to the stage that I can click on things and sounds associated with the objects game play correctly, but nothing is actually visible! As I mentioned above, I tried this using a MovieClip instead but got the same result. Anyone has an idea why this is happening and how I can fix this problem? Thank you for posting anything that might help, I have tried everything I can think so now I'm going to rack your brain rather haha

    Thanks in advance,

    Dinkyfish

    Cannot set the width and height of an empty object properties... I mean you can, but it will not work and curiously has an effect of making things do not appear.

  • Setting focus to the input text area

    I use MX 2004 and construction of a simple game where the contribution of users numbers in a dynamic text box. To limit the number of mouse clicks, I'm wanting to set the focus to the input box when that screen/page loads. Right now, we have to click on the area of input text field, enter their choices, then click on the submit button. I just want to type first, then click on the submit button.

    I set a variable to the text box of entry as "answer_box".

    I thought I remember a 'setFocus' or a 'onFocus' in ActionScript once before, but I can't find an example.

    Any help would be great!
    Thank you

    Thanks Rothrock. It worked. The 'Sélection' class allows you to define and control the text box where the insertion point.

    My text entry box is called, "years1.

    In the layer actions, the first line, I put - Selection.setFocus ("years1");

    Works perfectly. Thank you for pointing me in the right direction

  • Unable to make a call to the custom class

    Hi all

    I train to call the custom since the screen as below class, but its not picking up the custom class features and gives the result, I don't know if something is not in the below class or the way I call this method.

    package com.ge.bbcalendar;

    Import net.rim.device.api.ui.Color;
    Import net.rim.device.api.ui.Graphics;
    Import net.rim.device.api.ui.component.LabelField;

    public class TestClass extends {LabelField
    Private boolean brought;
    private string text;
    style long private;

    public {TestClass (String text, long style)

    Super();
    This.Text = text;
    This.style = style;
    }

    protected void onFocus (int direction) {}
    focused = true;
    Invalidate();
    super.onFocus (branch);

    }

    protected void onUnfocus() {}
    concentrate = false;
    Invalidate();
    super.onUnfocus ();
    }

    protected void paint (Graphics graphics) {}
    graphics.setColor (Color.WHITE);
    graphics.setBackgroundColor (0x544E4F);
    If {(targeted)
    graphics.setColor (Color.BLUE);
    }
    Graphics.Clear;
    Super.Paint (Graphics);
    }
    }

    Called as of the screen

    SerializableAttribute public class NativeScreen extends form {}

    final cas15 TestClass = new TestClass("",LabelField.FOCUSABLE);
    }

    What is the problem above?

    I suspect that your problem is the LabelField don't think it has any text to display.

    You really need this, I think

    public TestLabel (String text, long style) {}
    Super (Text, FOCUSABLE);

    ...

  • Extend the CellRenderer class

    I tried to extend the CellRenderer existing lightly change the behavior. However, I am having a very difficult time to do without actually looking at the CellRenderer class code. Its quite difficult to understand what methods override and what are the variables containing the required data. Is it possible to access the code? I do not use FlashBuilder.

    Thank you.

    Hey,.

    I wrote a sampling program that does what you need except im trying to figure out how to make the box event listeners. working on that now, but it's the code that should go you. I have class one main and one cell renderer. You got the general idea. I think the only thing that you missed the width and the implementation of the check box. When you use the this reference, you are referring to the cell itself and not the box. I think you might have mixed up who. This reference is to the current class as a whole and not only control access. Here is the code:

    ListTests.as

    package
    {
        import flash.display.Sprite;
        import flash.display.StageAlign;
        import flash.display.StageScaleMode;
        import flash.events.MouseEvent;
        import flash.text.TextFieldAutoSize;
    
        import qnx.ui.buttons.LabelButton;
        import qnx.ui.data.DataProvider;
        import qnx.ui.events.DataProviderEvent;
        import qnx.ui.listClasses.List;
        import qnx.ui.text.Label;
    
        [SWF(width="1024",height="600",backgroundColor="#CCCCCC",frameRate="30")]
        public class ListTests extends Sprite
        {
            private var myList:List;
            private var myDataProvider:DataProvider;
            private var myArray:Array;
    
            public function ListTests()
            {
                super();
    
                // support autoOrients
                stage.align = StageAlign.TOP_LEFT;
                stage.scaleMode = StageScaleMode.NO_SCALE;
    
                myList = new List();
                myArray = new Array();
    
                for (var i:int = 0; i < 10; i++)
                {
                    myArray.push({label: "Some extremely long text. - " + i});
                }
    
                myDataProvider = new DataProvider(myArray);
    
                myList.dataProvider = myDataProvider;
    
                myList.width = 500;
                myList.height = 600;
                myList.scrollable = true;
                myList.setSkin(MyCustomCellRenderer);
    
                addChild(myList);
    
                var newLabel:Label = new Label();
                newLabel.text = "Changes Here";
                newLabel.autoSize = TextFieldAutoSize.LEFT;
                newLabel.setPosition(600,0);
    
                addChild(newLabel);
    
            }
        }
    }
    

    MyCustomCellRenderer.as

    package
    {
        import flash.events.Event;
        import flash.events.MouseEvent;
        import flash.text.TextFieldAutoSize;
    
        import qnx.ui.buttons.CheckBox;
        import qnx.ui.buttons.LabelPlacement;
        import qnx.ui.listClasses.AlternatingCellRenderer;
        import qnx.ui.listClasses.List;
        import qnx.ui.text.Label;
    
        public class MyCustomCellRenderer extends AlternatingCellRenderer
        {
            /*
            * Place the object out here so that other methods can
            * access it
            */
            private var newCheckBox:CheckBox;
    
            public function MyCustomCellRenderer()
            {
                super();
    
                /*
                 * Add the checkbox here so we dont keep re-adding a check box
                 * whenever the onAdded method is called. other wise there
                 * would be a lot of objects for checkbox
                */
                newCheckBox = new CheckBox();
            }
            override protected function onAdded():void
            {
                super.onAdded();
    
                /*
                 * Do not want to use the label object at all. we want
                 * to fully customize our cell renderer. for some reason
                 * the label object is not considered a child object
                 * when the drawLabel method is called so we must
                 * removed it in this method where it is considered a
                 * child object
                */
                removeChild(label);
            }
            override protected function drawLabel():void
            {
                if (this.data)
                {
                    /*
                     * Sometimes this function is called prematurely when there
                     * is no data object available and it is null so we only
                     * do our custom label when there is a data object available
                    */
                    newCheckBox.width = 500;
                    newCheckBox.label = this.data.label;
                    newCheckBox.labelPadding = 10;
                    newCheckBox.labelPlacement = LabelPlacement.RIGHT;
                    newCheckBox.setPosition(10,10);
    
                    addChild(newCheckBox);
                }
            }
            override protected function onRemoved():void
            {
                super.onRemoved();
    
                /*
                * Remember to remove the checkbox object
                */
                removeChild(newCheckBox);
    
            }
        }
    }
    

    I will inform you of the event listener. I hope this helps!


    Update #1: Fixed several errors in the MyCustomCellRenderer.as file. Thank you ryantan for bring it to my attention!

  • Order of focus in the page start, with icons

    I'm doing a menu with icons on a start page.

    Let's say I have these clickable icons:

    [A] [B] [C]

    [D] [E] [F]

    [G] [H] [I]

    A, B, C are in a HFM.

    D, E, F are in other HFM.

    G, H, I in another separate HFM.

    Some examples so that you can understand my pain:

    -Imagine that we focus on the 'E' right now and scroll us down with the TrackBall. In a normal menu, one would expect the focus on "H". But, in this situation, because they are not inside the same manager, the system out of his manager and will focus on the first field of the next Manager, witch is here 'G '. This is not what I want.

    -Imagine that we focus on the 'E' now and scroll us right with the TrackBall. In a normal menu, one would expect the focus on 'F' 'E' and 'F' are inside the same manager, the system will focus on the other field which is here 'F' This is what I want.

    Now, here's what I want:

    I've set up a Visual menu with icons where users can scroll through one icon to another. My problem is that when I scroll upwards or downwards in the menu, instead of going to the next icon slot, it just goes to the first icon to the next handler.

    I tried this code...

     Field SelectedField = getField(getFieldAtLocation(x, y));
    

    Is there a way to loop in non-gestionnaire field?

    Here's the complete substitution

       protected boolean navigationMovement( int dx, int dy, int status, int time ) {      int direction;
    
          // DX -> Positive means going RIGHT, negative means going LEFT      if ( Math.abs(dx) > Math.abs(dy) ) {         if( dx > 0 ) {            // x += 1            direction = RIGHT;         } else {            // x -= 1            direction = LEFT;   }     // DY -> Positive means going DOWN, negative means going UP      } else {         if( dy > 0 ) {       // y -= 1     direction = DOWN;  } else {     // y += 1     direction = UP;         }      }
    
          Field FieldWithFocus = getLeafFieldWithFocus();      Screen active_screen = getActiveScreen();      int scrHeight = active_screen.getHeight();
    
          switch(direction) {         case DOWN:      for(int y=0; y < scrHeight; y++) {               int x = FieldWithFocus.getLeft() - (FieldWithFocus.getWidth()/2);               Field SelectedField = getField(getFieldAtLocation(x, y));               if (!SelectedField.equals(FieldWithFocus)) {                  SelectedField.setFocus();          }            }       break;     case UP:            for(int y=scrHeight; y < 0; y--) {               int x = FieldWithFocus.getLeft() - (FieldWithFocus.getWidth()/2);               Field SelectedField = getField(getFieldAtLocation(x, y));               if (!SelectedField.equals(FieldWithFocus)) {                  SelectedField.setFocus();           }            }       break;         case RIGHT:            for(int x=0; x < scrHeight; x++) {               int y = FieldWithFocus.getTop() - (FieldWithFocus.getWidth()/2);               Field SelectedField = getField(getFieldAtLocation(x, y));               if (!SelectedField.equals(FieldWithFocus)) {                  SelectedField.setFocus();               }            }     break;         case LEFT:            for(int x=scrHeight; x < 0; x--) {           int y = FieldWithFocus.getTop() - (FieldWithFocus.getWidth()/2);          Field SelectedField = getField(getFieldAtLocation(x, y));         if (!SelectedField.equals(FieldWithFocus)) {             SelectedField.setFocus();          }      }             break;                       }
    
             return true;      }   }
    

    Someone has a method to change the order of control within several managers focus, so you can help me.

    I finally was able to develop a solution. Boolean th table defines where are my items, as a game of battleship. If (0.1) == True then an object is supposed to be there on the screen.

    /**
    We need to buid a multidimensional to define table of Boolean where are our fine objects in focus
            
    Button
    Index (index table)
    |
    V
            
    0 | T T T T T
    1. T F F F F
    2. F F F F F
    3. F F F T T
    ---------------
    0 1 2 3 4<- hfm="" index="" (first="" index="" in="">
            
    ex:
    If (bool_objects [0] [0]) {}
    Code here...
    }
            
    **/
    final boolean [] [] bool_objects = {}
    {true, true, false, false},
    {true, false, false, false},
    {true, false, false, false},
    {true, false, false, true},
    {true, false, false, true}
    };

    Now, assuming that we have this chart, we need code so that each button works:

    protected boolean navigationMovement (int dx, int dy, int, int time status) {}
    System.out.println ("Focus" + coord [0] + "," + coord [1] + "") ");"
    If (Math.abs (dx) > Math.abs (dy)) {}
    If (dx > 0) {direction = RIGHT ;} else {direction = LEFT ;}}
    } else {}
    If (dy > 0) {direction = down ;} else {direction = UP ;}
    }
                    
    int coordx = coord [0], coordy = coord [1];
                    
    {Switch (direction)}
    box BOTTOM:
    for (int y = coordy + 1; y)< bool_objects[coordx].length;="" y++)="">
    If (bool_objects [coordx] [y]) {}
    Coord [1] = y;
    BMP [(5*y) + coordx]. SetFocus(); break;
    }
    }
    break;
    case to the TOP:
    for (int y = coordy-1; y > = 0; y-) {}
    If (bool_objects [coordx] [y]) {}
    Coord [1] = y;
    BMP [(5*y) + coordx]. SetFocus(); break;
    }
    }
    break;
    case RIGHT:
    for (int x = coordx + 1; x)< bool_objects.length;="" x++)="">
    If (bool_objects [x] [coordy]) {}
    Coord [0] = x;
    BMP [(5*coordy) + x]. SetFocus(); break;
    }
    }
    break;
    case to the LEFT:
    for (int x = coordx-1; x > = 0; x--) {}
    If (bool_objects [x] [coordy]) {}
    Coord [0] = x;
    BMP [(5*coordy) + x]. SetFocus(); break;
    }
    }
    break;
    }
    Returns true;
    }

    This code is catch the movement of the trackball and check if an object exists in this direction. If so, then setFocus on it, nothing else.

  • Analog Sprite class

    Hello world.

    In MIDlets there is a Sprite class, which allows to draw a sequence of images (and other useful things).

    At a BB API something like that? I looked through the documentation, but found nothing .

    Can I use a MIDlet 'classic' class Sprite to draw pictures on the screen of BB (in object method)?

    Thank you

    magfed

    Thank you all.

    I made my own Sprite class. But anyway thank you all for your messages.

    class CMySprite {    private Bitmap m_Image;    private int m_FrameWidth;    private int m_FrameHeight;    private int m_XCenter = 0;    private int m_YCenter = 0;    private int m_CurrentFrame = 0;    private int m_FramesCount;        /**     * Constructor     *      * @param Bitmap - bitmap is the row sequence of frames     * @param int - with of each frame     */    CMySprite(Bitmap image, int frameWidth){        m_FrameWidth = frameWidth;        m_FrameHeight = image.getHeight();        m_Image = image;        m_FramesCount = image.getWidth() / frameWidth;    }        /**     * Set coordinates of the center of frame to be painting on the screen     *      * @param int - x coordinate of center point if the frame at the screen     * @param int - y coordinate of center point if the frame at the screen     */    public void setCenterFramePosition(int xCenter, int yCenter){        m_XCenter = xCenter;        m_YCenter = yCenter;    }        /**     * Set zero-based number of frame to be painting on the screen     *      * @param int - zero-based number of frame to be painting on the screen     */    public void setFrame(int frameNum){        m_CurrentFrame = (frameNum >= m_FramesCount) ? 0 : frameNum;    }        /**     * Switch to the next frame of the frame sequence. If the     * next frame greater than frames count, the next frame is the      * first frame.     */    public void nextFrame(){        if((++m_CurrentFrame) >= m_FramesCount)            m_CurrentFrame = 0;    }        /**     * Switch to the previous frame of the frame sequence. If the     * previous frame less than 0, the previous frame is the      * last frame.     */    public void prevFrame(){        if((--m_CurrentFrame) < 0)            m_CurrentFrame = 0;    }        /**     * Paints the sprite frame     *      * @param net.rim.device.api.ui.Graphics - graphic context.     */    public void paint(Graphics g){        g.drawBitmap(m_XCenter - m_FrameWidth / 2,                     m_YCenter - m_FrameWidth / 2,                     m_FrameWidth,                     m_FrameHeight,                     m_Image,                     m_FrameWidth*m_CurrentFrame,                     0);    }};
    

    That, to the paint of the display method:

    Bitmap myFrames = Bitmap.getBitmapResource("img/frames.png");CMySprite tmpSprite = new CMySprite(myFrames, 100, 100);tmpSprite.setFrame(0);tmpSprite.setCenterFramePosition(50, 50);tmpSprite.paint(g);tmpSprite.nextFrame();tmpSprite.setCenterFramePosition(50, 150);tmpSprite.paint(g);tmpSprite.nextFrame();tmpSprite.setCenterFramePosition(50, 250);tmpSprite.paint(g);
    
  • Storm cannot focus on the field that wasn't a show on the first screen

    Hi all

    I have an application works very well on all devices except the device of the storm.

    If there are field mutil-focus on the screen, if the fields are not display when the display is launched,

    even if you move the screen to show, it can be still not developed.

    my request:

    /*
     * App.java
     *
     * © , 2003-2005
     * Confidential and proprietary.
     */
    
    import net.rim.device.api.ui.*;
    import net.rim.device.api.ui.container.*;
    import net.rim.device.api.ui.component.*;
    
    /**
     *
     */
    public class App extends UiApplication{
        public static void main(String arg[]){
            UiApplication app = new App();
            app.enterEventDispatcher();
        }
        public App() {
            pushScreen(new AScreen());
        }
        public class AScreen extends MainScreen
        {
            private VerticalFieldManager vfm = new VerticalFieldManager();
            public AScreen()
            {
                super(NO_VERTICAL_SCROLL);
                PartScrollableManager man = new PartScrollableManager(true);
                this.add(man);
                man.addHeadField(new ButtonField("Head"));
                for(int i=0;i<2;i++){
                    man.addBodyField(new LabelField("label"+String.valueOf(i),Field.USE_ALL_HEIGHT|Field.USE_ALL_WIDTH|Field.FOCUSABLE));
                }
                man.addBodyField(vfm);
                addField();
                for(int i=3;i<10;i++){
                    man.addBodyField(new LabelField("label"+String.valueOf(i),Field.USE_ALL_HEIGHT|Field.USE_ALL_WIDTH|Field.FOCUSABLE));
                }
                //man.addFootField(new ButtonField("Foot"));
                //man.addFootField(new EditField("Foot",""));
            }
    
            private void addField()
            {
                for(int i=0;i<9;i++){
                    vfm.add(new EditField(String.valueOf(i),""));
                }
            }
    
            public boolean trackwheelClick(int status,int time){
                Field f = this.getLeafFieldWithFocus();
                if(f instanceof ButtonField){
                    synchronized(UiApplication.getEventLock()){
                        if(vfm.getFieldCount()==0){
                            addField();
                        }else
                            vfm.deleteAll();
                    }
                    return true;
                 }
                 return false;
            }
        }
    }
    
    /*
     * PartScrollableManager.java
     *
     * © , 2003-2005
     * Confidential and proprietary.
     */
    
    import net.rim.device.api.ui.component.*;
    import net.rim.device.api.ui.container.*;
    import net.rim.device.api.ui.*;
    import net.rim.device.api.system.Display;
    
    /**
     *
     */
    public class PartScrollableManager extends VerticalFieldManager{
    
        private int MANGER_HEIGHT = Display.getHeight();
        private VerticalFieldManager headManager;
        private VerticalFieldManager footManager;
        private VerticalFieldManager bodyManager;
        private boolean isBorder;
        int rheight = 0;
        public PartScrollableManager(boolean border) {
            super(USE_ALL_HEIGHT | USE_ALL_WIDTH | NO_VERTICAL_SCROLL);
            isBorder = border;
            headManager = new VerticalFieldManager(USE_ALL_WIDTH |NO_VERTICAL_SCROLL);
            footManager = new VerticalFieldManager(USE_ALL_WIDTH |NO_VERTICAL_SCROLL);
            bodyManager = new VerticalFieldManager(USE_ALL_WIDTH |VERTICAL_SCROLL){
                protected void sublayout(int width,int height)
                {
                    int count = this.getFieldCount();
                    int h = 0;
                    for(int i=0;ithis.getHeight()) return super.touchEvent(ev);
                if(ev.getEvent()==TouchEvent.DOWN){
                    try{
                        setFocus(ev.getX(1),ev.getY(1),0);
                    }catch(Throwable ex){
                        System.out.println("ex : " +ex.toString());
                    }
                }
                boolean result = super.touchEvent(ev);
                int size = ev.getMovePointsSize();
                if(size>=2){
                    int vheight = this.getVirtualHeight();
                    int dheight = this.getVisibleHeight();
                    int xs[] = new int[size];
                    int ys[] = new int[size];
                    int ts[] = new int[size];
                    ev.getMovePoints(1,xs,ys,ts);
                    int dy = ys[size - 1] - ys[0];
                    verticalScroll = Math.min(Math.max(verticalScroll - dy, 0), rheight - dheight);
                    try{
                        setVerticalScroll(verticalScroll);
                    }catch(Throwable ex){
                        System.out.println("ex : " +ex.toString());
                    }
                }
                return result;
            }
    
            };
            this.add(headManager);
            this.add(bodyManager);
            this.add(footManager);
            headManager.add(new SeparatorField());
            footManager.add(new SeparatorField());
        }
    
        private void drawBorder(Graphics g)
        {
            int color = g.getColor();
            g.setColor(Color.BLACK);
            XYRect rect = g.getClippingRect();
            g.drawRect(0,0,rect.width,rect.height);
        }
    
        public void addHeadField(Field f){
            headManager.insert(f,headManager.getFieldCount()-1);
        }
        public void addFootField(Field f){
            footManager.add(f);
        }
    
        public void addBodyField(Field f){
            bodyManager.add(f);
        }
        public void setHeight(int height){
            MANGER_HEIGHT = height;
        }
        protected void sublayout(int width,int height)
        {
           layoutChild(headManager,width,height);
           layoutChild(footManager,width,height);
           layoutChild(bodyManager,width,height);
           setPositionChild(headManager,0,0);
           setPositionChild(bodyManager,0,headManager.getHeight());
           setPositionChild(footManager,0,Display.getHeight()-footManager.getHeight());
           setExtent(Display.getWidth(),MANGER_HEIGHT);
        }
    }
    

    What is wrong with my code?

    any advice would be appreciated.

    Hi guys,.

    I found the reason.

    for touchscreen, when setExtent, you define the actual size, so when you scroll, it will work correctly.

    Otherwise, so just set as visiable, it will never be setFocus on the field which is visible beyond.

    I guess RIM internal API regal setExtent is life-size on the touch screen, not even as no touchscreen.

    It is visiable size and size of the actual content.

    See you soon.

  • How do I do to make the manager class to run the drawFocus method?

    Hello world.

    Please let me question.

    I want to have the handler class to do drawFocus.

    Development is not won if "FOCUSABLE" is specified to the constructor for the handler class. You know the method of the handler class drawFocus method?

    Moreover, I want to express a given from the list of mail in the handler class.

    JDE 4.6.0 component package

    I solved for oneself.

    The following figure is a thing I wanted to do.

    http://picasaweb.Google.co.jp/LH/photo/9wNNUNZam8MKyV9h1FTquw?feat=DirectLink >

    (Because the image was not displayed by the preview, the link was introduced. "I'm sorry.)

    First of all, I've arranged it at the head of the 'FOCUSABLE' NullField handler class. (The handler class can judge the acquisition of the development of this event.)

    The handler class has a class variable that shows the status of the presence of development.

    And "focusChanged' FocusChangeListener method is mounted.

    The handler class to draw the rectangle in the method object referring to the value of the variable in class to come.

    I want to do there.

    I want to close this question hereby.

    Thank you to save expensive time, Mark.

Maybe you are looking for