Help With Loading an Image In AIR

I need to load an image (GIF) with AIR using File and FileStream, but can't figure out how to do it. I need to load the image into a Bitmap or BitmapData object, so I can't use the loader class. Here's what I have so far:
import flash.display.*;
import flash.events.*;
import flash.filesytem.*;
import flash.net.FileFilter;
import flash.utils.ByteArray;
import flash.geom.Rectangle;
var file:File = File.documentsDirectory;
var myImage:BitmapData;
var myFilter:FileFilter = new FileFilter("GIF Image","*.gif");
file.addEventListener(Event.SELECT,loadImage);
file.browseForOpen("Open",[myFilter]);
function loadImage(e:Event):void{
var stream:FileStream = new FileStream();
stream.open(file,FileMode.READ);
var bytes:ByteArray = new ByteArray();
stream.readBytes(bytes);
stream.close();
//By the way, this image is a special format and will always be 160 by 160 pixels.
myImage = new BitmapData(160,160);
bytes.position = 0;
myImage.setPixels(new Rectangle(0,0,160,160),bytes);
addChild(new Bitmap(myImage));
However, this never works. I always get this error:
Error #2030: End of file was encountered.
I don't quite understand why. Help would be much appreciated.

I already know how to do that, but I specifically stated in my post that I can't use the Loader class. The reason for that is that my program is an image manipulation program, and I need to load the data into a BitmapData object. However, since I originally made my post, I have found some more information. I used trace() to find out the length of the ByteArray I was loading the data into, and then the position after trying to create the BitmapData object, like so:
import flash.display.*;
import flash.events.*;
import flash.filesytem.*;
import flash.net.FileFilter;
import flash.utils.ByteArray;
import flash.geom.Rectangle;
import flash.errors.EOFError;
var file:File = File.documentsDirectory;
var myImage:BitmapData;
var myFilter:FileFilter = new FileFilter("GIF Image","*.gif");
file.addEventListener(Event.SELECT,loadImage);
file.browseForOpen("Open",[myFilter]);
function loadImage(e:Event):void{
     var stream:FileStream = new FileStream();
     stream.open(file,FileMode.READ);
     var bytes:ByteArray = new ByteArray();
     stream.readBytes(bytes);
     stream.close();
     trace(bytes.length); //Outputs: 4631
     //By the way, this image is a special format and will always be 160 by 160 pixels.
     myImage = new BitmapData(160,160);
     bytes.position = 0;
     try{
          myImage.setPixels(new Rectangle(0,0,160,160),bytes);
     } catch(e:EOFError){
          trace(bytes.position); //Outputs: 4628
     addChild(new Bitmap(myImage));
As the comments show, though the ByteArray is 4631 bytes, it is only read up until byte number 4628. Then it throws an error. Any idea what's going on?

Similar Messages

  • Help with loading multiple images via LoadVars

    Hello everybody.
    I need a hand loading multiple images using the LoadVars
    method with a text file. I can get it to load 1 image but not
    anymore than that. I am aware of other methods like using
    components but I am looking for a method where I can access and
    change all data from 1 text file (there will be text variable text
    within the file aswell to, but I am more concerned with the images
    at the moment).
    Anyway on to the issue. I have created a much simple .fla
    file that outlines my problem.
    The movie contains 3 layers:
    - top layer contains AS
    - middle layer contains an empty movie clip with the
    instance name of mcImage1
    - bottom layer contains an empy movie clip with the instance
    name of mcImage2
    The AS layer contains the following code:
    imagedata = new LoadVars()
    imagedata.load("data.txt")
    imagedata.onLoad = function(ok){
    if(ok){
    mcImage1.loadMovie(this.Image1)
    mcImage2.loadMovie(this.Image2)
    } else trace("Problem Loading")
    In the same folder of my .swf file I have a text file called
    data.txt which contains the following
    &Image1=image1.gif
    &Image2=image2.gif
    Also in the same folder of my .swf file I have two images
    image1.gif and image2.gif.
    When I run the flash the image2.gif is imported correctly.
    image1.gif does not appear.
    You can download my source files and all images here
    http://www.myrealpage.com/projects/var_test/var_test.zip
    Any help that can be shed on this problem is much
    appreciated.
    Thanks
    Matt

    Glad to help. It is just that I see so many folks who have
    two different parts of a problem smushed together – each
    problem isn't so hard on its own, but together they are difficult
    to wrap your head around. Always try and break down each step of
    the problem and it will help you in the end.
    That being said, I'm not quite so sure on this next problem.
    I don't do so much timeline stuff along with the Actionscript. I
    can get tricky. So this I don't quite have as much of clear mental
    picture of what you are describing. But here are some questions
    that I would ask – either of myself if I was doing it or of
    you.
    Is there a stop() on frame one to wait for the
    LoadVars.onLoad? Does the onLoad then say to play?
    If not, what happens if we get to Frame 10 before the
    LoadVars has even finished? That could be a problem.
    Remember that the LoadVars object is an actual object that
    will exist until it is deleted or removed in various ways. You can
    access it at any time after it is loaded. The onLoad event handler
    is just that thing you want to happen immediately after it is
    loaded.
    So my design would probably be.
    LoadVars on Frame 1.
    Where I am stopped.
    In the onLoad handler load the first image and tell the
    timeline to play
    On frame 10, the LoadVars object will still exist (unless
    you've deleted it)
    Get the variable out of the LoadVars and load the image.
    If you want to check this. Put a stop() in frame 10 and run
    it in the testing environment. When it gets to that frame, go to
    the debug menu and List Variables. You should see that your
    LoadVars object is still there.
    Does that answer your question or am I totally missing the
    point?

  • Help with Dreamweaver flash image viewer

    Hi all
    Would like some help with Dreamweavers Flash image viewer.
    Everything is working properly except when i try to link a picture, and have set the imagelinkTarget value to _blank the link always navigates away from my site and does not open in a new window.
    I have tried all the values for the imageLinkTarget and nothing works..
    Here is my code
    <script type="text/javascript">
    AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0, 28,0','width','190','height','190','src','images/ad1','quality','high','flashvar s','flashlet={imageLinkTarget:\'_blank\',captionFont:\'Verdana\',titleFont:\'Verdana\',sh owCo ntrols:false,frameShow:false,slideDelay:5,captionSize:14,captionColor:#000000,ti tleSize:10,transitionsType:\'Fade\',titleColor:#333333,slideAutoPlay:true,imageU RLs:[\'images/image1.jpg\',\'images/image2.jpg\',\'images/image3.jpg\',\'images/ image4.jpg\'],slideLoop:true,frameThickness:2,imageLinks:[\'http://www.bowlsaustralia.com.au\',\'http://www.smh.com.au\'],frameColor:#333333,bgColor:# FF9966,imageCaptions:[\'Bowls Australia\',\'Sydney Morning Herald\']}','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFl ash','flash_component','ImageViewer.swc','movie','images/ad1' ); //end AC code
    </script><noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0, 28,0" width="190" height="190">
              <param name="flash_component" value="ImageViewer.swc" />
              <param name="movie" value="images/ad1.swf" />
              <param name="quality" value="high" />
              <param name="FlashVars" value="flashlet={imageLinkTarget:'_blank',captionFont:'Verdana',titleFont:'Verd ana',showControls:false,frameShow:false,slideDelay:5,captionSize:14,captionColor :#000000,titleSize:10,transitionsType:'Fade',titleColor:#333333,slideAutoPlay:tr ue,imageURLs:['images/image1.jpg','images/image2.jpg','images/image3.jpg','image s/image4.jpg'],slideLoop:true,frameThickness:2,imageLinks:['http://www.bowlsaustralia.com.au','http://www.smh.com.au'],frameColor:#333333,bgColor:#FF9 966,imageCaptions:['Bowls Australia','Sydney Morning Herald']}" />
              <embed src="images/ad1.swf" quality="high" flashvars="flashlet={imageLinkTarget:'_blank',captionFont:'Verdana',titleFont:' Verdana',showControls:false,frameShow:false,slideDelay:5,captionSize:14,captionC olor:#000000,titleSize:10,transitionsType:'Fade',titleColor:#333333,slideAutoPla y:true,imageURLs:['images/image1.jpg','images/image2.jpg','images/image3.jpg','i mages/image4.jpg'],slideLoop:true,frameThickness:2,imageLinks:['http://www.bowlsaustralia.com.au','http://www.smh.com.au'],frameColor:#333333,bgColor:#FF9 966,imageCaptions:['Bowls Australia','Sydney Morning Herald']}" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFl ash" type="application/x-shockwave-flash" width="190" height="190"> </embed>
            </object>
    </noscript>
    any help would be greatly appericated
    Ken

    I just googled and found lots of folks with the same problem.  One fellow wrote this as a soluton:
    "All you have to do is
    remove the values from the imageLinks in the flash element. That
    should fix it."
    Does it?
    E. Michael Brandt
    www.divahtml.com
    www.divahtml.com/products/scripts_dreamweaver_extensions.php
    Standards-compliant scripts and Dreamweaver Extensions
    www.valleywebdesigns.com/vwd_Vdw.asp
    JustSo PictureWindow
    JustSo PhotoAlbum, et alia

  • Need help with loading images in executable Jar

    Hi,
    I've developed an application using netbeans that needs to load and display images.
    I use netbeans Clean and Build function to create an executable Jar file. When I run the executable Jar file it runs fine but when I come to a section of the application that needs images it freezes and can't load the images.
    When I then return to netbeans the part of the program that did successfully run before Clean and Build doesn't work anymore and I get an error message saying Uncaught error fetching image:
    I use,
    URL url = getClass().getResource("images/image1.png");
    Image image1 = Toolkit.getDefaultToolkit().getImage(url);to load an image.
    Can someone tell me why, when I clean and build my project to create a JAR, my images fail to load.
    Should I be storing the images in a specific folder or something??
    Thanks

    I've opened the JAR using winzip and, for some reason, the JAR hasn't preserved my file structure. So, when I try to look for an image as follows:
    URL url = getClass().getResource("images/file1.png");
    Image img= Toolkit.getDefaultToolkit().getImage(url);The folder doesn't exist and so it can't find the image.
    Can someone tell me how to keep my file structure when I create the JAR or an alternative way to find the images within the JAR file.
    Cheers

  • Help with load xml driven swf in another swf

    Hello people ... (sorry for my Google transalte English)
    ... I am desperate, tapping in place last week.
    In fact, i make flash CD presentation in Adobe Flash CS5 AS2 (with minimal use of ActionScript). It  occurs to me the next problem ... need to load flash image gallery that i already have created, in new presentation file. Gallery  was created in Flash Slideshow maker and as products I have. Swf,. Xml  and folders with thumbnails and picture (no. Fla file).
    The concept of the presentation (as root is concerned) should look like in uploaded picture "izgled otvorenog cd-a". In each of the folder on cd presentation (as on picture) is a Flash presentation controlled by their xml file whose name I must not change. Exe file "Prezentacija 2011" is a presentation (Flash Projector) that i try to make. In the same presentation i create frames and for each of the frames added action:
    loadMovie ("02_Kapije/kapije.swf", "kapije_ucitavanje");
    kapije_ucitavanje._x = 23;
    kapije_ucitavanje._y = 167;
    stop ();
    (Of course, for each item varies loadMovie root and instance name).
    The problem is that presentations can't find xml file, apparently because they do not have the appropriate root. When  all the files of the one gallery set in the same folder with  the "Presentation 2011.exe" file, everything works normally (  however, as i said, i cannot change the name of Xml file and that disturb the concept of my CD presentation).
    How can I drive loaded swf file from the above script to use Xml file in its folder?
    HELP PLEASE!!!
    P.S. ...and it looks so easy

    you're welcome.
    p.s.  please mark helpful/correct responses.

  • Help with creating thumbnail images

    Hi there
    I need some help with a webpage that displays images.
    I am capturing an internal xml file ..and want to display:
    An Image or images with a width of 130 px and height of 130
    px
    My problem is that when our users upload the pictures to the
    website ..they are not resized ..and they would not know how to use
    a program to do this.
    Is there a code or way to take the uploaded picture file and
    reduce it to a size of 130 x 130 in the existing page?
    It currently is displaying the full size image(s) which are
    take up 2 screens.
    thanks for your time ..Rob

    > Is there a code or way to take the uploaded picture file
    and reduce it to
    > a
    > size of 130 x 130 in the existing page?
    In the HTML you can just give it a width and height of those
    values.
    However, the full image is still loaded by the browser, so if
    the image is
    large, it's still going to be a bandwidth hog.
    Ideally, you'd resize on the server at time of upload. This
    can be done with
    various components depending on the particular back-end
    server/scripting
    language.
    -Darrel

  • Help with exporting and image size or boundaries?

    I am trying to slide the cat into the scene a little at a time foir an animation project I am working on. However, when I export the image the back ground of the image expands with a checkered back ground( showing here in white) and shows the whole cat.
    How do I just show a little of the cat on the image at a time when exporting. I am trying to give the impression that the cat is walking into the room. I do not want to have to cut the cat up.
    I would be thankful for any suggestions.

    Provide the name of the program you are using so a Moderator may move this message to the correct program forum
    This Cloud forum is not about help with program problems... a program would be Photoshop or Lighroom or Muse or ???

  • Please help with Load Variables / ASP

    Hello,
    I am using Load Variables to retreive a variable from an ASP
    page, (which uses a response.write) to output the variable
    getfile.onRelease = function()
    myData = new LoadVars();
    myData.onLoad = function(success){
    if(success) {
    getfile_txt.text = this.strString;
    } else {
    getfile_txt.text = "error";
    myData.load("sendFile.asp");
    stop();
    the problem is that the output says "undefined", but when I
    access the .asp page through my web browser I get the expected
    result of the variable which is "Test1.Doc"
    if any1 can help with this, i would be massivley thankful,
    thanks.

    p.s strString is the variable that I am trying to pass from
    the ASP page.

  • Help with array of Images - is it possible?

    Hi, i need to do this thing with tiles in my game such like this:
    Image tile[] = new Image[600]
    //building map:
    for (Y...){
    for(X...){
    if(tiles[tilenum].equals(null)){
    tile = Image.createImage("/"+tileset+"/Tile" + tilenum + ".gif");
    tiles[tilenum] = tile;
    }else{
    tile = tiles[tilenum];
    it doesn't work, because Image object has no constructor.. I don't know how to solve it. Can you help me?
    Edited by: __LB__javuje on Oct 29, 2008 11:58 AM

    - it isn't the problem, *.gif works perfectly. But thanks, your note is helpful, i'll redraw images to png:).
    To Daryll.Burke - I think, that my style of writing on this forum wasn't the main problem. If you want to help me, please focus to problem itself and not on details ;). I have rewritten everything, hope that it will be more readable for you.
    edit.: I have read my note from yesterday second time, and i think, i wouldn't understand it too, so sorry, man;)
    Main problem (or definition of "doesn't work, as you said) is, that every time i try to compare *tile[tilenum]* (where tilenum is from interval <0;600) ) with *null* object, NullPointerException is thrown.
    {code}Image tile[] = new Image[600]
    //building map:
    void tileBuild(...){
    for (Y...){
    for(X...){
    try{
    if(tiles[tilenum].equals(null)){
    tile = Image.createImage("/"tileset"/Tile" + tilenum + ".gif");
    tiles[tilenum] = tile;
    }else{
    tile = tiles[tilenum];
    }catch(Exception ex){
    }{code}
    I realy don't know how to solve it..
    Edited by: __LB__javuje on Oct 30, 2008 6:39 AM

  • Need Help With Waveform-driven Image Effects

    Hi,
    I've been working on a full-dome 3D animation for a couple of years now and I'm looking for someone to help with a custom plug-in for After Effects, Photoshop and/or Combustion. I need to be able to drive filters and effects like Brush Strokes and 'sketchy' noise with the waveform from an audio file. I've been using a very poor mans workflow in which I've mapped the waveform by breaking it up into vertical ranges of varying intensities and then applying respective levels of the effects and filters to the sequential images based on where they fall in the waveform ranges. So for the test Ive done, I've been literally applying Photoshop actions to very small packets of still images from rendered sequences, and it has been dizzyingly time-consuming. Ideally I would want to be able to do this dynamically with a motion graphics package, but really I'm looking for as much help as I can get.
    This project began as my master's thesis and I'm working on it during the free time I have between teaching and freelance work; I don't have much money but I am willing to pay for help with this goal. There is still a lot of 3D work that I still need to do and the rendering process will be slow, so this wouldn't be a job with strict or tight deadlines. The final images will be very large (3200x3200) and with the growth in the full-dome market, these sizes could easily increase. If anyone is interested or could help me with this endeavor in any way, please respond to [email protected] Thank in advance to anyone who reads this.
    Max

    See the SDK_Backwards sample to see how to acquire audio data from a layer. This is the same access method used by AE's own waveform drawing plug-ins. Feel free to contact me directly with any questions.

  • Help with CS4 tabbed image mode?

    How does one drag a layer from one image to another in tabbed mode?
    I'm forcing myself to work with the tabbed image interface as I assume someone thought this new feature was a good idea.
    I often drag or shift+drag layers from one image to another, whether it be adjustments or image elements that need to be placed (in register) as a layer in another open image.
    But when I use the tabbed interface mode any attempt to drag a layer from one tab to another does not work.
    What am I missing???
    Thanks
    Russell

    Yeah I noticed the same limitation.. they making floating document mode extra ****(UI interface that doesn't adhere to System OS visual style, documents that no longer move with the main PS UI, like when you adjust the mainframe size or move the window floating docs would get moved and stay within the UI, unless you dragged and floating doc outside the main ui frame, which was good, but now it seems floating docs always live outside the mainframe and appear above docked although open panel UIs.. not to mention the new theme looks like complete and utter dogshit.. but oh well.. CS5 might get some more work.. maybe they'll bring back the pallete well.. ******* adobe noobs.
    I too liked to drag & drop of layer objects onto another document its common thing I do when working in photoshop.. I just can't believe how lame Adobe are that they couldn't allow this functionality seeing as a tabbed UI is the default setup now..
    seems like the only way around it is to use the now **** floating document mode... or use one of the splitview modes.. course those are crap, but at least you can D&D layer objects, and then switch back the single doc tab.
    lets not get into the flakey **** opengl support and functionality.

  • Help with loading image in Air

    Hello there, hope you can help me with this situation.  Getting into FlexSDK/AirSDK development.  I am very familiar with Flex development using Flash Builder 4, however, I would like to get into development using the the two(2) SDK development tools mentioned above especially from an AIR development perspective.  Coming along pretty good, and ran into one problem that driving me nuts: I have an image in a folder called AirSamples/Air/HelloWorld/southwest.jpg.     I tried to bind the image to the image tag by issuing the following:
      <mx:Image source="@Embed('AirSamples/Air/HelloWorld/southwest.jpg')" /> in my mxml file (HelloWorld.mxml). Let assume this is the only component tag in the file.
    When I go to the command prompt and issue the command: amxmlc Helloworld.mxml,  it compiles without an error. When I issue adl HelloWorld-app.mxml   from the command line prompt, it loaded in Flash Player, however,  the graphic symbol came up indicating that a graphic was there, but no graphic. Can you offer any suggestions as to how I can make this work even if I have to use ActionScript.
    Jerry McLeod

    I already know how to do that, but I specifically stated in my post that I can't use the Loader class. The reason for that is that my program is an image manipulation program, and I need to load the data into a BitmapData object. However, since I originally made my post, I have found some more information. I used trace() to find out the length of the ByteArray I was loading the data into, and then the position after trying to create the BitmapData object, like so:
    import flash.display.*;
    import flash.events.*;
    import flash.filesytem.*;
    import flash.net.FileFilter;
    import flash.utils.ByteArray;
    import flash.geom.Rectangle;
    import flash.errors.EOFError;
    var file:File = File.documentsDirectory;
    var myImage:BitmapData;
    var myFilter:FileFilter = new FileFilter("GIF Image","*.gif");
    file.addEventListener(Event.SELECT,loadImage);
    file.browseForOpen("Open",[myFilter]);
    function loadImage(e:Event):void{
         var stream:FileStream = new FileStream();
         stream.open(file,FileMode.READ);
         var bytes:ByteArray = new ByteArray();
         stream.readBytes(bytes);
         stream.close();
         trace(bytes.length); //Outputs: 4631
         //By the way, this image is a special format and will always be 160 by 160 pixels.
         myImage = new BitmapData(160,160);
         bytes.position = 0;
         try{
              myImage.setPixels(new Rectangle(0,0,160,160),bytes);
         } catch(e:EOFError){
              trace(bytes.position); //Outputs: 4628
         addChild(new Bitmap(myImage));
    As the comments show, though the ByteArray is 4631 bytes, it is only read up until byte number 4628. Then it throws an error. Any idea what's going on?

  • Problem with loading an image via HTTP

    Hallo,
    When using the JBCL TransparentImage control i can load images
    from my local HD. But when i use setImageURL it won't work. I
    looked at the sources and it seems to me that the problem lies
    within the default toolkit. The following code works when using
    a local file. Via HTTP the Observer get's one notification with
    just the error-flag set.
    URL url=new URL("http://localhost/mxtj_inetmaps/mp_map1.gif");
    // String sFileName="c:\\mapinfo\\inetmap\\mp_map1.gif";
    Toolkit tk=Toolkit.getDefaultToolkit();
    Image i=tk.getImage(url);
    // Image i=tk.getImage(sFileName);
    MyObserver mo=new MyObserver();
    tk.prepareImage(i, -1, -1, mo);
    Could someone help me, how to show a Web-Image within a control ?
    Bye Heiko.
    null

    Hi,
    There is no getImage that accepts the parameters in the order in which you have given them. Try this:
    getImage( getCodeBase(), "flower.gif" );
    Regards,
    Manfred.

  • Help with Photoshop Cs6 Image size

    I am using Photoshop Cs6 on a MacBook Pro with retina display.  I'm working on an image that is 72 dpi and 1000 pixels wide by 300 pixels tall.  When I hook my laptop up to my external monitor, the image is a nice size.  However, when I disconnect it and look at it on my laptop it is way to small.  I have to zoom in on the image on my laptop to see the detail and then the graphics are distorted.  Can you please help me?

    Ask in the PS forum.
    Mylenium

  • Help with a weird problem: MB Air, Internet, and Cinema Display

    I have the first MacBook Air, running the latest Leopard release.
    I use an Airport Extreme with Verizon FIOS.
    I have no problems connecting with the Internet (knock on wood) on the Air. However, when I use a 23-inch Cinema Display (not the most recent CD) with the Air my Internet connection slows to a crawl, or I can't connect at all. I unplug the CD from the Air, and I can connect to the Internet again quickly.
    Any idea what the problem is?
    The Air works well with the CD. The only problem is when I use the Air connected to the CD and access the Web.
    Thanks in advance for any help.

    The Air is plugged in, and all appears to be OK with the Air's power. Same with the Cinema Display. The Air appears to have the power to render properly on the Cinema Display but not enough juice left to engage its built-in wi-fi to access the web? I am at a complete loss on this one. Will be calling Apple support or stopping by the Genius Bar, as I have one other item (different computer) I must deal with.
    Thanks.

Maybe you are looking for

  • What does error (-53) mean?

    When I try to sync music onto my ipod, I get this "error (-53) and it stops syncing. I have no idea what is worng with it. Can somebody help me please?

  • PS CS5 Crashing in Merge to HDR

    PS CS5 has started crashing in Merge to HDR Pro again.  I thought I had it fixed.  None of the other problems are back, though, so maybe I do have what was happening before fixed.  The crash report is the same for each crash this time, and it always

  • Making the field "company code" mandatory

    Hi SAP experts, is it possible to make the field : company code, a mandatory one in the initial screen of XD01 transaction (create customer)? How? Best regards, Bahia.

  • My mouse now has 2 modes. I must constantly reset it (open/close StartMenu) between webpage control and Firefox control. How to fix?

    Once a Firefox control (toolbar button, URL entry, Searchbox Entry) is invoked, the mouse will no longer operate in the web window (other than moving around) or move scroll bars. Can't select anything, enter data, click links, etc. To switch to the "

  • Price list for items

    Hi my client's one item is sold at different prices.so he want to use price list.how to alot price in the price list and whats the procedure for doing.please explain it instead of giving any thread link. Thanks in advance.