Try to compensate a bitmap drawing

I have a loaded image and I want to cut a number of rectangles to use on my screen. I can copy the top-left corner with no problems, but if I try to compensate for my rectangle to copy it seems that copies that result are empty.

The method to work is graphicLoaded and if I use any x, y offset I get 25 copies of the top left corner. But if I use a shift, a single chart. I know that I must look at this evil, but can not understand. Any help would be appreciated.

package
{
import flash.display.MovieClip;
import flash.display.DisplayObject;
import flash.display.Sprite;
import flash.display.Loader;
Import 12345678910111213import;
import flash.display.BitmapData;
import flash.geom.Rectangle;
import flash.events. *;
flash.net import. *;
/**
* ...
* @author Chris
*/
SerializableAttribute public class GraphicTest extends MovieClip
{
private var background: DisplayObject, in the foreground: DisplayObject;
private var url: String = "spintest.jpg";
private var loader: Loader = new Loader ();
private var layout: Array = new Array();

public void GraphicTest()
{
If (stage)

{

init (new Event ("Event"));
}
on the other
{

addEventListener (Event.ADDED_TO_STAGE, init);
}
}

private void init(e:Event):void
{
removeEventListener (Event.ADDED_TO_STAGE, init)
loader.contentLoaderInfo.addEventListener (Event.COMPLETE, graphicLoaded);

Loader.Load (new URLRequest (url));

}

private void graphicLoaded(event:Event):void
{

var doWidth:Number = 128;
var doHeight:Number = 96;
var bmp:Bitmap;
var bd:BitmapData;
var x: Number, y: Number;
var cliprect:Rectangle;
for (x = 0; x < 5; x ++)
{
layout [x] = new Array();
for (y = 0; y < 5; y ++)
{

BD = new BitmapData (doWidth, doHeight, true, 0xffffff);
BMP = new Bitmap (bd);

clipRect = new Rectangle (x * doWidth, y * doHeight, doWidth, doHeight);
trace (clipRect);
EDI Draw (charger, null, null, null, cliprect, false);


BMP.x = x * doWidth;
BMP.y = y * doHeight;


addChild (bmp);

layout [x] [y] = bmp;

}
}

stage.addChild (this);
Background = loader;

}

}

}

The cliprect to draw() is a Rect. _destination_... not a Rect. source try to replace the line to draw with this copyPixels line:

bd.copyPixels (loader, clipRect, new Point (0, 0));

Tags: Adobe Animate

Similar Questions

  • Error when you try to insert the bitmap file

    Hello!

    I have a problem with the symbol editor in Multisim 11.  When I try to insert a bitmap the entire program crashes.

    I would like to have the symbol Opamp in multisim. See: http://commons.wikimedia.org/wiki/File:Normsymbol_OPV.svg

    How can I do this?

    Thank you!

    mikcon

    Hi Mikcon,

    I have install Multisim 11.0 take your symbol and resize it and saved as a bitmap.

    Then I opened the component wizard and try to create a new component with your symbol of OPV and everything works fine without errors or accidents.

    Here some screenshots for you:

    So most likely your Multisim Installation is corrupted.

    Please try to repair your Multisim and again test this issue.

    Kind regards
    Oleg Scherling, mengg | Engineering applications. National Instruments | NIG. |

  • Try to resize a bitmap - FASTJPEG: progressive decoding is not supported

    Hi all

    I went through the forums and tried many examples to remedy this, but none of them have worked.

    I download a .jpg file from a URL of site Web, internal to our society, to get a photo of the employee.

    I then use the code to resize the image to 100 x 100, no matter what the image is the size I need to resize to 100 x 100.

    The last code I tried is as follows:

    EncodedImage image = EncodedImage.createEncodedImage(imageBytes, 0, imageBytes.length); 
    
            int currentWidthFixed32 = Fixed32.toFP(image.getWidth());
            int currentHeightFixed32 = Fixed32.toFP(image.getHeight());
    
            int width = 100;
            int height = 100;
    
            int requiredWidthFixed32 = Fixed32.toFP(width);
            int requiredHeightFixed32 = Fixed32.toFP(height);
    
            int scaleXFixed32 = Fixed32.div(currentWidthFixed32, requiredWidthFixed32);
            int scaleYFixed32 = Fixed32.div(currentHeightFixed32, requiredHeightFixed32);
    
            image = image.scaleImage32(scaleXFixed32, scaleYFixed32);
    
            return image.getBitmap();
    

    However, it is not hidden image and gives me the following error:

    FASTJPEG: Progressive decoding is not supported

    It does not for all images, only some of them.  I discovered that the images in this case on images jpeg at 300 dpi, while those who work well is 96 dpi.  Is this the reason why?  Is there a way that these images can be resized properly, even if they are 300 dpi?

    I have not control how these images are saved in our society, I just have to get them via Http and resize them to display nicely on the Blackberry screen.

    Thanks for any help you can give.  I will continue to try other things as much as possible.

    Kind regards

    David

    If you work with OS 5.0 +, you can try the native Bitmap scaling methods provided.

  • Bitmap drawing

    Hello

    I'm a newbie to blackberry experience a custom UI control. I would like to know if it is possible to draw a bitmap to a x and position there and stretch that bitmap to a desired width and height.  Also I am interested to know if I could change the color of the pixels of the bitmap image. Code snippets would be great! Thank you!

    The following link to solve your problem of Bitmap scale

    http://supportforums.BlackBerry.com/T5/Java-development/zoom-on-bitmap-field/m-p/501235#M101442

    and according to the function change the color of the pixel in the Bitmap to set the RBG value.

    This function returns the new Bitmap with different colors.

    public static Bitmap generateHitBitmap(Bitmap passBitmap) {
             Bitmap retBitmap;  // Altered, tinted bitmap being returned
             int[] argbData; // Array holding the ARGB data
             int redData;  // The red value of a pixel
    
             // Create a new, empty bitmap with the same dimensions
             retBitmap = new Bitmap(passBitmap.getType(), passBitmap.getWidth(), passBitmap.getHeight());
    
             // Prepare the ARGB array
             argbData = new int[passBitmap.getWidth() * passBitmap.getHeight()];
    
             // Grab the ARGB data
             passBitmap.getARGB(argbData, 0, passBitmap.getWidth(), 0, 0, passBitmap.getWidth(), passBitmap.getHeight());
    
             // Loop through each pixel in the array
             for (int lcv = 0 ; lcv < argbData.length ; lcv++) {
                // Get the red data by masking out the 2nd byte
                redData = (argbData[lcv] & 0x00FF0000) >> 16;
    
                // Increase the red value by 80 (maximum of 255)
                redData += 80;
                if (redData > 255) redData = 255;
    
                // Shift it back to the right place, and set it back into array
                redData = redData << 16;
                argbData[lcv] = (argbData[lcv] & 0xFF00FFFF) + redData;
             }
    
             //  Set the return Bitmap to use this altered ARGB array
             retBitmap.setARGB(argbData, 0, passBitmap.getWidth(), 0, 0, passBitmap.getWidth(), passBitmap.getHeight());
    
             return retBitmap;
          }
    

    Thank you

    Vivek Kumar Srivastava

  • Sprite small large bitmap drawing

    Hello

    I have a circSprite spirte I draw on a large drawingBitmapbitmap.

    drawingBitmapData = new BitmapData (800, 600, true, 0);

    drawingBitmap = new Bitmap (drawingBitmapData);

    stage.addChild (drawingBitmap);

    var circSprite:Sprite = new Sprite();

    circSprite.graphics.beginFill(0xFF0000,0);

    circSprite.graphics.drawRect (0,0,160,160);

    circSprite.graphics.endFill ();

    circSprite.graphics.beginFill(0xFF00FF,1);

    circSprite.graphics.drawCircle (40,40,40);

    circSprite.graphics.endFill ();

    mat: matrix var new matrix());

    drawingBitmapData.drawWithQuality (circSprite, Matt, null, null, null, true, StageQuality.MEDIUM);

    I would like to move the circSpirte to another post (100 100) - how can I do this?

    Thank you!

    Rolf

    update of the matrix:

    var rect:Rectangle = new Rectangle (0,0,800,600);

    var bgColor:uint = 0xffffff;  //<- use="" your="" stage="">

    mast. TX += 3;

    drawingBitmapData.fillRect (rect, bgColor);  //<- to="" make="" it="" look="" like="" the="" previously="" drawn="" object(s)="" were="">

    drawingBitmapData.drawWithQuality (circSprite, Matt, null, null, null, true, StageQuality.MEDIUM);

  • Transparency of the overlay of bitmap

    I'm trying to superimpose images 3 as follows:

    Background

    Created in a manner Dynamics grapimage

    Brands

    I need the dynamicallly graphic design to be transparent, only if I can see the background image, but the problem that I am running is whenever I set the alpha on 8-bit bitmap, everything I draw on it looks like transparent also.

    I tried searching, but nothing appear that contributes to this, someone has an idea how to do this?

    Basically, my goal is to start with a transparent background (instead of any color) and then paint over it with no transparency.

    Any idea?

    I think he wants to shoot on three separate bitmaps and then paint a bitmap on the other where the two bitmaps albums start with transparent backgrounds. You can push a new graphic context before setting your alpha and then it pop before painting what we don't affect alpha. You try to start with a fresh bitmap with a fully transparent background is probably going to be more work than you think. I do not remember that it works as expected, the last time I tried (you can search the forums because I know I've posted on this before). Then Yes, you should probably not try to use three bitmaps, but one instead and then draw the all in order as suggested above.

  • Resizing a bitmap using .scaleImage32 instead of .setScale

    I have a simple piece of code that I created and which takes a string (the name of the image), gets the image and reszies it and outputs a Bitmap file.

       public static Bitmap scaleBitmap(String imagename)
        {
            EncodedImage ei = EncodedImage.getEncodedImageResource(imagename);
            ei.setScale(2); 
    
            Bitmap bmp = ei.getBitmap();
            return bmp;
        }
    

    The problem is that .setScale is obsolete, and although still works, I want to make sure I use the latest features, so my app works in all areas. I want also to the scale not by half. I can't get .scaleImage32 to work tho.

       public static Bitmap scaleBitmap(String imagename)
        {
            int numerator = Fixed32.toFP(1);
            int denominator = Fixed32.toFP(2);
            int scale = Fixed32.div(numerator, denominator);
    
            EncodedImage ei = EncodedImage.getEncodedImageResource(imagename);
            ei.scaleImage32(scale, scale);
            Bitmap bmp = ei.getBitmap();
            return bmp;
        }
    

    I'm using it wrong?

    I test on the 8830 and the 9000. the results are the same on both, if resizes no problem, the scaleImage does not work.

    Try this:

    private Bitmap getScaledBitmapImage(String imagename)
        {
    
            EncodedImage image = EncodedImage.getEncodedImageResource(imagename); 
    
            int currentWidthFixed32 = Fixed32.toFP(image.getWidth());
            int currentHeightFixed32 = Fixed32.toFP(image.getHeight());
    
            int width = image.getWidth() /2;
            int height = image.getHeight() /2;
    
            int requiredWidthFixed32 = Fixed32.toFP(width);
            int requiredHeightFixed32 = Fixed32.toFP(height);
    
            int scaleXFixed32 = Fixed32.div(currentWidthFixed32, requiredWidthFixed32);
            int scaleYFixed32 = Fixed32.div(currentHeightFixed32, requiredHeightFixed32);
    
            image = image.scaleImage32(scaleXFixed32, scaleYFixed32);
    
            return image.getBitmap();
        }
    

    Concerning

    Bika

  • How to get the external Bitmap of URL object

    Hi all!

    I'm a developer starting with components of BlackBerry, I try to get a Bitmap of the outer object
    URL, but my getImage method does not work correctly. I think that the problem lies in the getImage method. just at the moment where I try to
    create form of Bitmap bytes. Note: J2me with the Image object, that it works!

    could someone help me please?

    Sorry for my bad English & thank you for helping me!

    Code:

    SerializableAttribute public class MainForm extends form {}

    private String url = "http://user-xxxx/json.js";
    private String [] imageURLs = new String [5];

    public MainForm() {}

    try {}
    getJSON (url);
    } catch (IOException e) {}
    e.printStackTrace ();
    }

    try {}
    Add (GetImage(this.imageURLs[0]));
    } catch (Exception e) {}
    e.printStackTrace ();
    }
    }

    Public Sub getJSON (String url) throws IOException {}
    StringBuffer sb = new StringBuffer();
    InputStream is = null;
    HttpConnection hc = null;
    try {}
    long bytesLength = 0;
    int ch = 0;
    HC = (HttpConnection), Connector.open (url);
    is = hc.openInputStream ();
    bytesLength = hc.getLength ();
    If (bytesLength! = - 1) {}
    for (int i = 0; i)< byteslength;="" i++)="">
    If ((ch = is.read (())! = - 1) {}
    SB. Append ((Char) ch);
    }
    }
    } else {}
    While ((ch = is.read (())! = - 1) {}
    bytesLength = is.available ();
    SB. Append ((Char) ch);
    }
    }
    parseJSON (sb.toString ());
    } {Finally
    is. Close();
    HC. Close();
    }
    }

    {} public void parseJSON (String sb)
    try {}
    JSONObject jo = new JSONObject (sb);
    If (jo! = null) {}
    JSONObject channel = jo.getJSONObject ("channel");
    If (channel! = null) {}
    JSONArray points = channel.getJSONArray("item");
    If (items! = null) {}
    for (int i = 0; i)< items.length();="" i++)="">
    JSONObject point = items.getJSONObject (i);
    this.imageURLs [i] = item.getString ("image");
    }
    }
    }
    }
    } catch (Exception e) {}
    e.printStackTrace ();
    }
    }

    I think that the problem lies in this method.

    public BitmapField getImage (String url) throws Exception {}
    InputStream inputStream = Connector.openInputStream (url) (InputStream);
    Bitmap image = null;
    BitmapField bf = null;
    try {}
    ByteArrayOutputStream Baos = new ByteArrayOutputStream();
    int ch;
    While ((ch = inputStream.read ())! = - 1) {}
    Baos.Write (ch);
    }
    Byte [] imageData = baos.toByteArray ();
    Image = Bitmap.createBitmapFromBytes (imageData, 0, imageData.length, 1);
    BF = new BitmapField (image);
    } {Finally
    If (inputStream! = null)
    inputStream.close ();
    }
    return (bf == null? null: bf);
    }

    public String [] getImageURLs() {}
    Return this.imageURLs;
    }

    }

    Finally my fatal mistake was in archive JSON, I change the URL of the images of http://localhost/image.jpg to
    http://user-xxx/image.jpg (MDS - CS available in http://localhost URL: 8080 /), and now it works!

    Ted and arkadyz, your suggestions have been very helpful for me, thank you very much!

    Final code:

    Class MainMIDlet

    Import net.rim.device.api.ui.UiApplication;

    SerializableAttribute public class MainMIDlet extends UiApplication {}

    public MainMIDlet() {}
    MainForm mf = new MainForm();
    pushScreen (mf);
    }

    Public Shared Sub main (String [] args) {}
    MainMIDlet mm = new MainMIDlet();
    mm.enterEventDispatcher ();
    }
    }

    Class MainForm

    import java.io.ByteArrayOutputStream.
    import java.io.IOException;
    import java.io.InputStream;

    Import javax.microedition.io.Connector;
    Import javax.microedition.io.HttpConnection;

    Import org.json.me.JSONArray;
    Import org.json.me.JSONObject;

    Import net.rim.device.api.system.EncodedImage;
    Import net.rim.device.api.ui.component.BitmapField;
    Import net.rim.device.api.ui.component.LabelField;
    Import net.rim.device.api.ui.container.MainScreen;

    SerializableAttribute public class MainForm extends form {}

    private String url = "http://user-xxx/json.js";
    private String [] jsonTitles = new String [5];
    private String [] jsonImages = new String [5];
    private LabelField lf = null;
    private BitmapField bf = null;

    public MainForm() {}

    try {}
    getJSON (url);
    } catch (IOException e) {}
    e.printStackTrace ();
    }

    LF = getLabelField(this.jsonTitles[0]);
    Add (LF);

    try {}
    BF = getBitmapField(this.jsonImages[0]);
    } catch (Exception e) {}
    e.printStackTrace ();
    }
    Add (BF);

    }

    Public Sub getJSON (String url) throws IOException {}
    StringBuffer sb = new StringBuffer();
    InputStream is = null;
    HttpConnection hc = null;
    try {}
    long bytesLength = 0;
    int ch = 0;
    HC = (HttpConnection), Connector.open (url);
    is = hc.openInputStream ();
    bytesLength = hc.getLength ();
    If (bytesLength! = - 1) {}
    for (int i = 0; i)< byteslength;="" i++)="">
    If ((ch = is.read (())! = - 1) {}
    SB. Append ((Char) ch);
    }
    }
    } else {}
    While ((ch = is.read (())! = - 1) {}
    bytesLength = is.available ();
    SB. Append ((Char) ch);
    }
    }
    parseJSON (sb.toString ());
    } {Finally
    is. Close();
    HC. Close();
    }
    }

    {} public void parseJSON (String sb)
    try {}
    JSONObject jo = new JSONObject (sb);
    If (jo! = null) {}
    JSONObject channel = jo.getJSONObject ("channel");
    If (channel! = null) {}
    JSONArray points = channel.getJSONArray("item");
    If (items! = null) {}
    for (int i = 0; i)< items.length();="" i++)="">
    JSONObject point = items.getJSONObject (i);
    this.jsonTitles [i] = item.getString ("title");
    this.jsonImages [i] = item.getString ("image");
    }
    }
    }
    }
    } catch (Exception e) {}
    e.printStackTrace ();
    }
    }

    public getLabelField (String title) {} LabelField
    LabelField lf = new LabelField (title);
    return of lf;
    }

    public BitmapField getBitmapField (String url) throws IOException {}
    InputStream is = Connector.openInputStream (url) (InputStream);
    BitmapField bf = null;
    try {}
    ByteArrayOutputStream Baos = new ByteArrayOutputStream();
    int ch;
    While ((ch = is.read (())! = - 1) {}
    Baos.Write (ch);
    }
    imageData Byte = baos.toByteArray ();
    BF = new BitmapField (EncodedImage.createEncodedImage (imageData, 0,))
    (imageData.length) .getBitmap ());
    } {Finally
    If (is! = null) {}
    is. Close();
    }
    }
    return (bf == null? null: bf);
    }

    }

  • How to convert byte [] EncodedImage rgb565 or bitmap data

    Hi all I am playing a video and I want to get snapshot of video as

    Byte [] byteArr = videoControl.getSnapshot ("encoding = rgb565");

    I try to get the Bitmap as

    image = EncodedImage.createEncodedImage (byteArr, 0, byteArr.length);

    image bitmap = image.getBitmap ();

    but she throws an Exception as IllegalArgumentException.

    I get a table of double length than screenWidth * ScreenHeight, perhaps because of the rgb565

    How can I convert a byte [] bitmap.

    I solve the problem to get the bitmap by building as

    image bitmap = new Bitmap (Bitmap.ROWWISE_16BIT_COLOR, Graphics.getScreenWidth (), Graphics.getScreenHeight (), byteArr);

  • Focus on the bitmap image in a HorizontalFieldManager

    Hello

    I have a bitmap in a HFM, I did focusable (bitmap).

    Problem is when the bitmap is concentrated, the HFM together in turn blue, as if she was herself focused.

    I try to put the bitmap in a value for money that I put in the HFM to limit the focus to the HFM, but it did not work.

    No idea how I can do?

    There is the code:

    HorizontalFieldManager imageHfm = new HorizontalFieldManager(Field.USE_ALL_WIDTH) { protected void paint(Graphics graphics) {        graphics.setBackgroundColor(0x000000);        graphics.clear();        super.paint(graphics);    }};VerticalFieldManager imageVfm = new VerticalFieldManager(Field.FIELD_RIGHT);        Bitmap loginButton = new Bitmap(Bitmap.getBitmapResource("login1.png"), DrawStyle.RIGHT) {            public boolean trackwheelClick(int status, int time) {                connectionWrapper();                return true;            }            };        imageVfm.add(loginButton);        imageHfm.add(imageVfm);
    

    Hello

    While the size of your equal to your bitmapField HorizontalFieldManager().

    You can do this way

    HorizontalFieldManager rowManager = new HorizontalFieldManager() {}
                     
    ' public void sublayout (int width, int height) {}
    Super.sublayout (LooknFeel.Width, bitmap.getBitmapResource("SignIn.png"). GetHeight());
    setExtent (LooknFeel.WIDTH, Bitmap.getBitmapResource("signin.png").getHeight ());
    }
                     
                     
    {} public void paint (Graphics g)
    g.setBackgroundColor (Color.BLACK);
    g.fillRect (0,0,LooknFeel.WIDTH,getHeight ());
    g.Clear ();
    Super.Paint (g);
    }
               
    };

    Here I had only set the height according to my bitmap, you must set the width and height.

    Please let me know if it solves your problem or not.

  • How can I re size bitmap while keeping the original my png transparency?

    Greetings and regards other developers, a few quick details, I use the blackberry JDE 5.0 and Eclipse.  I am for programming multiple phones Storm2 and all models of the torch.  The display area is different between some of the phones of 480 x 360 to 800 x 480.

    I created a method of resizing of the images based on the ratio of aspect here.

    public static Bitmap AspectRatio(Bitmap bm)
          {
            int widthRatio = (int)(360 / bm.getWidth());
            int width = (int)(Utility.SCREEN_WIDTH / widthRatio);
            int heightRatio = (int)(480 / bm.getHeight());
            int height = (int)(Utility.SCREEN_HEIGHT / heightRatio);
            Bitmap temp = new Bitmap(width, height);
            bm.scaleInto(temp, Bitmap.FILTER_BILINEAR);
            return temp;
          }
    

    This method works very well until I have try with my transparent Bitmaps.

    The transparent part of the my bitmaps are black and im not sure how to keep transparent.

    Example below.

    Front

    After

    How to keep my opacity after stretching?

    Thanks in advance.

    Not your problem.  Try this code that works for me:

    http://supportforums.BlackBerry.com/T5/Java-development/resizing-transparent-bitmaps/Ta-p/703239

  • How load and access bitmap images?

    Hey there!

    After a few days of frustration and of searching the Web, I finally understand how to make a sheet of sprite and animate it.  I understand the classes and how to import external actionscript files that contain in my Flash project.  The problem is, I can't understand how to name and load a bitmap from the folder and pass on my functions as arguments.  > _ <

    How load and access an external bitmap in Actionscript 3.0?

    I use a class that I found online here: http://www.bensilvis.com/?p=229

    The problem comes when I try to access my bitmap parts, while he tries to do here: http://www.bensilvis.com/?p=317

    var currentSprite : SpriteSheet = new SpriteSheet (sheet, 20, 20) ;


    It is the only line that confuses me because it uses a variable "sheet", which is a bitmap, and I don't know how to set a name / my external bitmap image as such.

    SpriteSheet(tileSheetBitmap:Bitmap, width:Number = 16, height:Number = 16)
    • tileSheetBitmap: the bitmap of the sprite sheet that we will use
    • width: the width of the tiles in the map
    • height: the height of the tiles in the map

    Thank you!  < 3

    you use the loader class to load a bitmap.  When the loading is complete you can cast content loader as a bitmap for the help of the compiler with more coding.

  • the file size reduction of Essbase cube/pag bitmap compression

    We see some huge pag files in our essbase cube and Oracle had suggested to change the bitmap image compression to see if this will help. (we currently have "no compression")
    That said, what is the difference between the use of ELA versus bitmap encoding for BSO cubes?
    I would like to hear the experiences of others.
    (we currently have "no compression")

    ^ ^ ^ You're going to be very happy. Very, very happy.

    You can read the database administrator Guide - just search for "comrpession.

    It's here: http://download.oracle.com/docs/cd/E17236_01/epm.1112/esb_dbag/dstalloc.html

    There are a bunch of updates in custody and the rules concerning the 'better' compression method - it does say I use almost always ELA as the method that seems most effective wrt the disk space. It is logical that this method examines each block and apply the most effective method: pair ELA, bitmap, or Index value. I can't see a difference in calculation between bitmap and ELA.

    How the hell did you in the position of no compression in the first place?

    Kind regards

    Cameron Lackpour

    Published by: CL on July 18, 2011 10:48
    Oops, a couple things:
    (1) after you apply the change of compression in environmental assessments or via MaxL, you must stop and then restart the database for the setting to take effect.
    (2) you must export the database, clear out and reloaded using the new compression method - #1 change affects only new blocks if you could have a mixture of compressed and uncompressed to your db, bliocks which will do nothing for the storage space.
    (3) the only way to really know which method is the most effective is to compare the calculation (remember to write on the disk which could be a little slower than now) and the compression methods is to do it. Try it as a bitmap and note time calc of sampling and file size IND and PAG, so try as ELA and do the same thing.

  • Add a graphic of the bitmap to a movieclip in the code

    Hi, I'm new to programming and as3 and I try to add a bitmap to a clip in the code. However, I have difficulties to get the location of the bitmap image to go where I want to because it is inside the movieclip and it just shows upward to movieclip instead of the coordinates 0,0 I want him: here is a part of the code so you can see what I mean:

    imageBitmapData3 = new Länder (63, 53);

    _player = new Bitmap (imageBitmapData3);

    _gameLevel.addChild (_player);
    _player.x = 145;
    _player.y = 90;

    -Instead of projection upward at 145, It 90 appears just to the movieclip, _gamelevel, 0,0.


    does anyone know how I could get it to do what I want it to do? I want to add inside the mc because I need it to go with the background of _gameLevel when I move it.

    Thank you

    Hello

    your code looks fine to me - you could try adding a breakpoint after _player.y = 90 and see if the bitmap is in the right place when the breakpoint is reached, in this case, there must be some code elsewhere it's later change of x / y to zero?

  • You can pass a bitmap between two custom classes?

    I have two custom as3, TriviaGame and TriviaQuestion classes, and I try to retrieve a bitmap stored in TriviaQuestion and have found it impossible to date.

    It seems that the root of my problem, is that this bitmap is somehow void in my GetImage function, even if it is class that has been defined previously in ImageLoaded() data. The only time where I am able to access the information of the bitmap (in order to add it to the display) is inside ImageLoaded().

    In TriviaQuestion.as, loading the image:

    private function XMLLoadedHandler (e:Event):void
            {
                xml = new XML(e.target.data);
                
                // grab title
                titleFormat = new TextFormat( font, 25, color, true, null, null, null, null, "center" );
                titleText = CreateText( xml[0].attribute("title"), titleFormat, (stageProps.stageWidth/2), (0 + margins), (stageProps.stageWidth) );
                
                // get questions/answers
                var qList:XMLList = xml.item;
                totalQuestions = qList.length();
                questions = new Array();
                
                for ( var i:int = 0; i < totalQuestions; i++ )
                {
                    var myItem:XML = xml.item[i];
                    var temp:TriviaQuestion = new TriviaQuestion();
                    
                    // set question class data
                    temp.SetQuestion( myItem.question );
                    if ( "image" in myItem )
                    {
                        temp.SetImageProps( myItem.image, myItem.image.attribute("position") );
                    }
                    var answers:XMLList = myItem.answer;
                    temp.SetAnswers( answers );
                    temp.SetHint( myItem.hint, xml[0].attribute("ptsPerHint") );
                    temp.SetFact( myItem.fact );
                    temp.SetPotentialPoints( xml[0].attribute("ptsPerQuestion") );
                    
                    questions[i] = temp;
                }
                
                AssembleQuestion();
            }
    

    In TriviaQuestion.as, set the class data:

    public function SetImageProps( url:String, attr:String ):void
             {
                imgLoader = new Loader;
                imgLoader.contentLoaderInfo.addEventListener( Event.COMPLETE, ImageLoaded, false, 0, true );
                imgLoader.load( new URLRequest( url ) );
                
                position = attr;
            }
            
            public function ImageLoaded(e:Event):void
            {
                bitmap = LoaderInfo(e.target).content as Bitmap;
            }
    
    

    In TriviaGame.as MakeQuestionSprite()

    private function MakeQuestionSprite( s:Shape ):void
             {
                if ( "image" in xml.item[currentQuestion] )
                {
                    var myPos:String = questions[currentQuestion].GetPosition();
                    var myImg:Bitmap = questions[currentQuestion].GetImage();
                    errorText.text = "Img: " + myImg.width;
                }
                var myQ:String = questions[currentQuestion].GetQuestion();
                questionText = new TextField();
                questionFormat = new TextFormat( font, 15, color, null, null, null, null, null, "center" );
                
                if ( "image" in xml.item[currentQuestion] )
                {
                    if ( myPos == "right" )
                    {
                        myImg.x = stageProps.stageWidth - margins - myImg.width;
                        //myImg.y = margins + s.y + (s.height / 2);
                        //myImg.visible = true;
                        //questionText = CreateText( myQ, questionFormat, margins, myImg.y, (stageProps.stageWidth - margins - myImg.width) );
                    }
                    //questionSprite.addChild( myImg );
                }
                else
                {
                    questionText = CreateText( myQ, questionFormat, margins, (margins + s.y + s.height / 2), (stageProps.stageWidth - margins) );
                }
                
                questionSprite.addChild( questionText ); 
            }
    
    
    

    In TriviaQuestion.as, GetImage

    public function GetImage ():Bitmap
             {
                var copy:Bitmap = new Bitmap( bitmap.bitmapData.clone() );
                return copy;
            }
    
    

    You could try to copy your bitmap image until it's ready. When I did this test he kept fail with the same messages that you receive, even after a different syntax in many trials. But when I split the TriviaQuestion test class and added an event listener (see the text in bold below) for once the charger has been filled, then I was able to recover the new bitmap. My two examples classes are based on your examples:

    TriviaGame

    package {}
    import flash.display.Sprite;
    Import TriviaQuestion;
    Import 12345678910111213import;
    import flash.display.BitmapData;
    import flash.display.DisplayObject;
    import flash.display.Loader;
    import flash.events.Event;

    SerializableAttribute public class TriviaGame extends Sprite {}

    questions of private var: Array;
    private var q1:TriviaQuestion;

    public void TriviaGame() {}
    issues = new Array();
    Q1 = new TriviaQuestion();
    questions.push (Q1);

    MakeQuestionSprite();
    }

    private void MakeQuestionSprite (): void {}
               var myTriviaQuestion:TriviaQuestion = issues [0];
    myTriviaQuestion.addEventListener ("Ready", addNewBitmap);

    this.addChild (myTriviaQuestion);
    }

    private void addNewBitmap(e:Event):void {}
    var mybitmap:Bitmap = issues [0]. GetImage ();
    MyBitmap.x = 400;
    this.addChild (mybitmap);

    }

    } / / end of class
    }

    ----------------------------------------

    TriviaQuestion

    package {}
    Import 12345678910111213import;
    import flash.display.Loader;
    import flash.events.Event;
    import flash.net.URLRequest;
    import flash.display.LoaderInfo;
    import flash.display.Sprite;
    import flash.display.BitmapData;
       
    SerializableAttribute public class TriviaQuestion extends Sprite {}
       
    private var imgLoader:Loader;
    public var bitmap2:Bitmap;
    private var position: String;
    private var _copy:Bitmap;
       
    public void TriviaQuestion() {}
    SetImageProps ("frog4.jpg");
    }
       
    public void SetImageProps (url: String, attr:String = "" "): void
    {
    imgLoader = new loader;
    imgLoader.contentLoaderInfo.addEventListener (Event.COMPLETE, ImageLoaded, false, 0, true);
    imgLoader.load (new URLRequest (url));
           
    position = attr;

    }
           
    public void ImageLoaded(e:Event):void
    {
    bitmap2 = new bitmap;
    bitmap2 = Bitmap (e.target.loader.content);
    addFrog();
              this.dispatchEvent (new Event ("Ready"));
    }

    public function addFrog (): void {}
    this.addChild (bitmap2);

    var frog: Bitmap = GetImage ();
    Frog.x = 200;
    this.addChild (frog);
    }
           
    public function getBitmapData (): BitmapData {}
    Return bitmap2.bitmapData.clone ();
    }

    public function getLoader (): {charger
    Return imgLoader;
    }

    public void GetImage (): Bitmap
    {
    var copy: Bitmap = new Bitmap (bitmap2.bitmapData.clone ());
    return the copy;
    }

    } //end of class
    }

    Post edited by: waterlovinguy

Maybe you are looking for

  • Bing Bar at the top of the Web page

    When I updated to the latest version of firefox, at the top of most Web pages, excluding the pages like google and youtube, I'll get a "Bing Search" at the top. So, it's boring, but also if you go over it, he brought, not Bing. So, I thought it was m

  • Pavilion all-in-one 23-q112: pavilion all-in-one 23-q112

    I just need to know how to remove the rear to improve my memory

  • Symbol of period of blackBerry Smartphones in email 7250

    I'm new in this world of blackberry, I bought a used 7250 which seems to work except the symbol of period very well (.).  When I'm in the email and try to enter my email address which is [email protected] the instructions for the symbol of the era s

  • Search in the journal table

    HelloI'm looking in a logging table (T1)(a) the early line for each 'name '.(b) these names without any entry in the table of logging. Possible names are defined in table T2.I have a solution (see below), but I think that there must be a more adequat

  • Ranging from CO - HzPuiAddressCreateUpdateCO

    Hello worldAttempts to extend the HzPuiAddressCreateUpdateCO class for validation fails. Don't get the error "No method with the signature - no method with the signature - initSuggestionTransient()" when you run the page that has HzPuiAddressCreateUp