Fork me on GitHub
Not signed in (Sign In)

Welcome, Guest

Want to take part in these discussions? Sign in if you have an account, or apply for one below

    • CommentAuthorluedfe
    • CommentTimeJan 8th 2010
     
    Hi,

    I'm trying to load images as particles. Although I found this description

    var emitter:Emitter2D = new Emitter2D();
    var renderer:DisplayObjectRenderer = new DisplayObjectRenderer();
    addChild( renderer );

    renderer.addEmitter( emitter );
    emitter.counter = new Steady( 100 );
    var imgClass:ImageClass = new ImageClass( MyBall , 10, 10 ); // MyBall is exported class of ball.png


    emitter.addInitializer( imgClass );
    emitter.addInitializer( new Position( new LineZone( new Point( -5, -5 ), new Point( 505, -5 ) ) ) );
    emitter.addInitializer( new Velocity( new PointZone( new Point( 0, 65 ) ) ) );

    emitter.addAction( new Move() );
    TypeError: Error #1034: Type Coercion failed: cannot convert MyBall@10906281 to flash.display.DisplayObject.
    at org.flintparticles.twoD.renderers::DisplayObjectRenderer/addParticle()

    I'm not abel to figgure out how to load the image itself.. how can I export a png as a class? Heven't done that yet.
    • CommentAuthorluedfe
    • CommentTimeJan 8th 2010
     
    can someone give me complete code?
    • CommentAuthorgordeaoux
    • CommentTimeJan 9th 2010
     
    The simplest way is to import the png into your library, make a movie clip that contains your png, in the linkage properties for the movieclip, set the class to imgClass, and you should be good to go. So there's no coding needed in Flash CS3/4.

    You could also look into image loading in the flash docs if you want to load the whole thing programmatically.
    http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/display/Loader.html#includeExamplesSummary
    • CommentAuthorluedfe
    • CommentTimeJan 9th 2010 edited
     
    can someone show me a complete code. I have tried everything and nothing seems to work. I'm sorry.
    I tried loading images via bitmapdata, linking directly in the flashfile. nothing works
    • CommentAuthorgordeaoux
    • CommentTimeJan 11th 2010 edited
     
    Change this line:

    emitter.addInitializer( imgClass );


    to this:

    emitter.addInitializer( new ImageClass ( imgClass ) );


    import your image into your flash library. Make a movieclip out of it, in the properties panel for your movie clip, check "Export for Actionscript" and type "imgClass" in the Class field. The Base Class line should auto fill to "flash.display.MovieClip".

    If all of your code is in Frame 1 of your timeline, everything should work fine.

    Here's an example:

    http://www.fallendoor.com/test/example/imgClassExample.zip
    • CommentAuthorRichard
    • CommentTimeJan 12th 2010
     
    When you export an image in Flash it is exported as a BitmapData. You need to get this into a bitmap to use it as a particle. To do this, you need a simple class that extends Bitmap and uses your library item as its bitmapData property. Something like this (I haven't tested this so there ay be bugs in it)...

    package
    {
    public class MyBallBitmap extends Bitmap
    {
    public function MyBallBitmap
    {
    // parameters are the width and height of the image
    bitmapData = new MyBall( 10, 10 );
    }
    }
    }


    Then use this in your ImageClass initializer

    var imgClass:ImageClass = new ImageClass( MyBallBitmap );
    emitter.addInitializer( imgClass );
    • CommentAuthorcambaz
    • CommentTimeJan 15th 2010
     
    what if i want to load images from the net tru actionscript.

    how can we use images as particles without making them into a movieclip???
    • CommentAuthorRichard
    • CommentTimeJan 16th 2010
     
    You need to create an image class, probably extending Bitmap, that will use the loaded image as its bitmap data.
  1.  
    You can do it without using Flash CS3/4!
    load the bitmap first,
    store it in a cache class, and if you want to emit the same bitmap several times,
    I mean more than 1 instance of the same bitmap at the same time on screen,
    return it from the cache class like this:

    private static var _bitmap : Bitmap;

    static public function get bitmap() : Bitmap {
    return new Bitmap(_bitmap.bitmapData.clone());
    }

    do a class that extends MovieClip,
    something like this:

    public class BitmapClass extends MovieClip {
    public function BitmapClass () {
    super();
    addChild(BitmapCacher.bitmap);
    }
    }

    now when you add the initializer, use the ImageClass,
    and the argument will be the BitmapClass itself, and NOTan instance of it:

    addInitializer( new ImageClass( BitmapSeedClass ));

    Hope it's clear enough.