-
1. Re: Impossible to instantiate a loaded .png image
Andrei1 Mar 16, 2011 8:43 PM (in response to barpos)"Moving a loader instance to a movieclip containter returns a coercion error."
What's the code?
" Moving the loaded image object to a MC container does not produce any errors, but remains as a bitmap object."
You load image - so it will be always Bitmap and there is no way to make anything out of it.
" bitmapdata.draw() method seems to require either a bitmap or bitmapdata destination object. I need a symbol instance."
You cannot create Flash IDE symbols at runtime because, well, symbol is something that pertains exclusively to Flash authoring environment and Flash IDE specific compiler. Granted, resulting from Flash IDE compilation swf does contain symbols but they are pretty much static after compilation and are pretty much extensions of other DisplayObjects (MovieClip, Shape, etc.)
Even if one could create symbols at runtime - what would be a benefit? After all, why bother when there are much better ways to deal with display objects of all kinds in AS3. This is not to mention that it would be redundant.
-
2. Re: Impossible to instantiate a loaded .png image
barpos Mar 17, 2011 6:05 AM (in response to Andrei1)Hi,
Ok, I tested the idea once again, but at a smaller scale in a separate .FLA file. And, I get no errors now, but all of the traces I put in my code reports a false value.
var frontWheelLoader:Loader = new Loader();
frontWheelLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, frontWheelLoadComplete);
frontWheelLoader.load(new URLRequest("FrontWheel.png"));function frontWheelLoadComplete(event:Event):void
{
var container:MovieClip = new MovieClip();
container.addChild(frontWheelLoader);
trace("frontWheelLoader: " + frontWheelLoader is DisplayObject);
trace("frontWheelLoader: " + frontWheelLoader is MovieClip);
trace("frontWheelLoader: " + frontWheelLoader is Bitmap);
trace("frontWheelLoader: " + frontWheelLoader.content is DisplayObject);
trace("frontWheelLoader: " + frontWheelLoader.content is MovieClip);
trace("frontWheelLoader: " + frontWheelLoader.content is Bitmap);
}Regards!
Ron
-
3. Re: Impossible to instantiate a loaded .png image
barpos Mar 17, 2011 7:19 AM (in response to Andrei1)Ok, I think I have _finally_ found a viable solution. Well, at least it is working in my sample FLA. <crossed fingers>
I found this solution in the ActionScript.org forum. It's an Australian guy who posted the solution, in 2008. One needs to use the Bitmap() function when grabbing the loaded image. See the code below:
var container:MovieClip = new MovieClip();
var frontWheelLoader:Loader = new Loader();
frontWheelLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, frontWheelLoadComplete);
frontWheelLoader.load(new URLRequest("FrontWheel.png"));
function frontWheelLoadComplete(event:Event):void
{
var loadedBitmap:Bitmap = Bitmap(event.target.content);
container.addChild(loadedBitmap);
addChild(container);
theTween.addTarget(loadedBitmap);
}
If you see any flaws in my code, let me know ...
Regards,
Ron
-
4. Re: Impossible to instantiate a loaded .png image
Andrei1 Mar 17, 2011 7:37 AM (in response to barpos)This is called casting - Loader content is cast to Bitmap datatype. Using Bitmap() function implies that new instance of Bitmap object is created via calling constructor method Bitmap() - new Bitmap().
-
5. Re: Impossible to instantiate a loaded .png image
barpos Mar 17, 2011 10:00 AM (in response to Andrei1)Thanks for the explanation, but I have to tell you that when I include the "new" operator, I get an error:
TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::Bitmap@2ccbc151 to flash.display.BitmapData.
at RonaldTest_fla::MainTimeline/frontWheelLoadComplete() -
6. Re: Impossible to instantiate a loaded .png image
Andrei1 Mar 17, 2011 5:23 PM (in response to barpos)I don't know what theTween does but, perhaps, this is what you need to do:
theTween.addTarget(loadedBitmap.bitmapData);
-
7. Re: Impossible to instantiate a loaded .png image
barpos Mar 17, 2011 5:33 PM (in response to Andrei1)theTween is an instance of an existing tween in a MC. When a display object is passed to its addTarget() method, it makes the object animate as set in the tween.
It is working with loadedBitmap as we speak. I did not include the new operator. It wasn't suggested anyway.
Thank you for your time,
Ron

