Class not found : openfl.display.Sprite

NOTA

  • Posts: 318
My Shitoki::  how do I get rid of this error -Class not found : openfl.display.Sprite



import openfl.display.Sprite;
import openfl.Assets;
import openfl.display.Bitmap;

import openfl.display.BitmapData;
import openfl.display.PNGEncoderOptions;
import openfl.utils.ByteArray;
import openfl.geom.Rectangle;
import haxe.io.Output;
import sys.io.FileOutput;

class Main extends Sprite {
      
   public function new ()
   {   
      super ();   
      var _bit = new openfl.display.Bitmap(Assets.getBitmapData( 'assets/robot.jpg'));
      this.addChild(_bit);
      saveImage(_bit.bitmapData,"/path/to/your/Desktop/test.png");
   }

   public function saveImage(image:BitmapData, outputFile:String):Void
   {
      #if (cpp || neko)

         var path;
         // path = Sys.getCwd();
         // path = path.substr(0, path.indexOf('Export')) + "test2.png";

         path = outputFile;

         #if openfl_legacy
            var imageData:ByteArray = image.encode('png', 1);
         #else
            var imageData = image.encode (image.rect, new PNGEncoderOptions ());
         #end
         
         var fo:FileOutput = sys.io.File.write(path, true);
         try {

            fo.writeBytes(imageData, 0, imageData.length );
            
            #if openfl_legacy
               // fo.writeBytes(imageData, 0, imageData.length );
            #else
               // fo.writeBytes(imageData, 0, imageData.length );
            #end

            trace( "save path done: " + path );
         } catch (e:Dynamic){
            trace("Error writing file " + path + ": " + e);
         }
         fo.close();
      #end
   }   
}


« Last Edit: March 28, 2020, 08:15:26 am by NOTA »

yoplalala

  • *
  • Posts: 1611
are you using Stencyl ?  If you're using Stencyl , I don't see where there is problem. If it's outside of stencyl.
It is easier to create an openfl project and work inside of it like this https://www.openfl.org/learn/haxelib/tutorials/displaying-a-bitmap/

NOTA

  • Posts: 318
Yep, in stencyl...

yoplalala

  • *
  • Posts: 1611
can you post the full log ?


Luyren

  • *
  • Posts: 2422
You either have some faulty code on SceneEvents_0 on line 71, or you deleted that scene but are still trying to transition to it (that's but a guess though).
Code: [Select]
2020-03-27 09:51:52,918 ERROR [Thread-16] stencyl.sw.util.StreamGobbler: [nme.bat] Source/scripts/SceneEvents_0.hx:71: characters 15-36 : Class not found : openfl.display.Sprite
2020-03-27 09:51:52,937 ERROR [Thread-16] stencyl.sw.io.write.resource.HXWriter: Events for 's1':  Class not found : openfl.display.Sprite
from scripts.SceneEvents_0
line: 71
columns: 15-36
My Stencyl resources are available here: https://luyren.itch.io/
Cutscenes, RPG Elements, Particles, Map System and many more.
Twitter

yoplalala

  • *
  • Posts: 1611
Where is written your code ? Is it in a code block  or a code scene ?

NOTA

  • Posts: 318
Where is written your code ? Is it in a code block  or a code scene ?
only one scene.
In an import block.

yoplalala

  • *
  • Posts: 1611
Hum,
I added the code in an import block in a scen and it worked.  (You can try with a nnew blank game)
So it must be something else.

NOTA

  • Posts: 318
Hum,
I added the code in an import block in a scen and it worked.  (You can try with a nnew blank game)
So it must be something else.
K, thanx. I'll try again.

NOTA

  • Posts: 318
Hum,
I added the code in an import block in a scen and it worked.  (You can try with a nnew blank game)
So it must be something else.
When you say it worked, do you mean it compiled ok, or you were able to export an image?

yoplalala

  • *
  • Posts: 1611
It compiled and didn't find the image and didn't find robot.jpg as I didn't have it.

NOTA

  • Posts: 318

« Last Edit: March 28, 2020, 07:51:28 am by NOTA »