0 Replies Latest reply on Apr 6, 2010 8:43 AM by jimmyoneshot

    Struggling to Get My Snapshot Application Working

    jimmyoneshot Level 1

      I have an app in which I want users to be able to load a website into a html component and then take a snapshot of this html component, save it as a jpeg and upload it to the net.


      At the moment I have it so that if a user enters an image name a text input allowing them to enter a url to search for via the html component is enabled. When they enter a url and click 'GO' a website is loaded into the html component. They can then click 'Create Image' next to the image name  they have just entered and this will save the image in assets/images/<whatevernametheuserenteredfortheimage>.jpg


      What I want now is when they click the Upload Image button this will upload THAT SPECIFIC IMAGE that they have just created WITHOUT them having to browse for it. Basically I want users to be able to just enter an image, name look for a site, snapshot the site and then save and upload the image. Is this possible and if so how? I know how to do it using the browse method but I'm unsure how to do it by allowing the user to actually name the image for upload.


      Here's my small app so far:-


      <?xml version="1.0" encoding="utf-8"?>



      xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">






      import mx.graphics.codec.JPEGEncoder;


      import mx.graphics.ImageSnapshot;



      private function takeSnapshot(event:Event) :void{


      var imageBitmapData:BitmapData = ImageSnapshot.captureBitmapData(linkviewer) ;


      var s:Object = new Bitmap(imageBitmapData);


      var jpgEncoder:JPEGEncoder = new JPEGEncoder( 60 );


      var ba:ByteArray = jpgEncoder.encode(imageBitmapData);


      var filename:String = "mynewpic";


      var enteredimagename:String = imagenameentry.text;


      var file:File = File.applicationDirectory.resolvePath(('assets/images/')+enteredimagename+('.jpg'));


      var wr:File = new File(file.nativePath);


      var stream:FileStream = new FileStream();

      stream.open( wr, FileMode.WRITE);

      stream.writeBytes ( ba, 0, ba.length );










      <mx:HTML id="linkviewer" width="650" height="650" horizontalScrollPolicy="off" verticalScrollPolicy="off" x="10" y="40" visible="true" backgroundColor="#000000"/>



      <mx:Image id="imagesnapshotpreview" x="668" y="10" width="353" height="303"/>



      <mx:Label text="Enter Image Name:" x="668" y="321"/>



      <mx:TextInput id="imagenameentry" x="791" y="321"/>



      <mx:Label text=".jpg" x="952" y="323"/>



      <mx:Button label="Create Image" click="takeSnapshot(event)" enabled="{imagenameentry.text.length>0}" x="986" y="321" />



      <mx:TextInput id="urlentry" text="http://" enabled="{imagenameentry.text.length>0}" x="10" y="10" width="585"/>



      <mx:Button label="GO" enabled="{imagenameentry.text.length>0}" click="linkviewer.location=urlentry.text" x="603" y="10" width="57"/>



      <mx:Button label="Upload Image" x="823" y="374" />