Flex SWFLoader Event.COMPLETE not triggering - apache-flex

While trying to load a Bitmap onto a SWFLoader the Event.COMPLETE event is not being triggered
mySWFLoader.source = new Bitmap(Bitmap(someEvent.content).bitmapData);
but if I use a URL as source the complete event is triggered:
mySWFLoader.source = "http://example.com/123.jpg";
Is there some kind of restriction while using Bitmap as source?

I believe if you use data that already exists in memory (which your Bitmap would) then no load operation would happen. It should be usable immediately after construction. I know attaching movies in AS2 worked like that. If it was part of the library you could use it right away and no loading events would happen.

Use
mySWFLoader.addEventListener(Event.ADDED,handleSwfLoadComplete);
It fires when the content is actually created and added to the display list.
I encountered the same issue. The problem is that when you use Bitmap or Class as source, the content is populated only after the Bitmap or class was instantiated.
This happens in swfLoader.loadContent which eventually adds the newly created content to the displayList as the loader's child, and eventually dispatches the ADDED event.

Related

returnedObject property

I'm programming in Flex Builder Burrito for an mobile application.
I'm trying to get a variable from navigator.PopView()
and i found the following site: adobe View and ViewNavigator
On that page is written that you can get to an returnedObject:
The ViewNavigator will save this object internally, and the new view can access it from with the navigator.returnedObject property.
The problem is when I want to acces the returnedObject flash builder doesn't seem to find that even the package isn't found.
I've found my problem on an other site.
There it's plain simple explained.
Do the override public function createReturnObject():Object.
On the page where it needs to be send back.
Then on the popped view, you can acces it by returnedObject.
On same page next lines are
The property is a ViewReturnObject
which contains the object that was
returned
and the context in which the removed view was pushed (See Setting
the View Context).
ViewNavigator.poppedViewReturnedObject
is guaranteed to be set by the time
the new view
receives the add event and will be destroyed after the view receives its
viewActivate
event.
and also a NOTE
Note, the return object is only stored when a view is popped of
the navigation stack
or replaced through the use of the pop and replace navigation
operations (e.g.,
replaceView, popView, etc...). It will be cleared after the new view
receives its
ViewNavigatorEvent.VIEW_ACTIVATE event.
I think should try function to get popuped view poppedViewReturnedObject of ViewNavigator
Its description is also on same page
public function get poppedViewReturnedObject():ViewReturnObject
Hopes that help

How to set an event listener for mx:image to kick in after image loads

Is there a way to dispatch an event after Flex loads an mx:image? I'm loading image externally and don't know the width/height until it's loaded. I get an exception when I call width/height to the image before loading.
you should use loader, in this case, like i have used in the below mentioned code
private var loader:loader = new Loader();
loader.load(new URLRequest(rp_product.dataProvider[i].#source));
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,productLoadingComplete);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,productLoadingError);
rp_product.dataProvider[i].#source, here rp_product is my repeater's id,
you simply give the image source here which u want to load, now you have productLoadingComplete() method, and productLoadingError() methods available, even if you want to something on image progess, so use this code :
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,onImageLoadProgress);
in this way, you can load an external image, i hope this is wht u wre luking for
you can attach listener for flash.events.Event.COMPLETE event. it is fired when image loading is complete.

FLEX: swfloader component not firing complete event

enter code hereBeen really frustrating just trying to load a swf from a swfloader in Flex and then accessing it's content. I'm sure once I figure out how to do it once then it'll be fine, but I've gone thorugh a bunch of tutorials and somethings not right. Here's my flex code:
and the as code:
public function initHeaderSwf():void
{
trace("INITIATIED");
//trace(headerSwf.content['weekNo'].text = "TWRTWERWEWE");
headerSwf.addEventListener(Event.COMPLETE, onHeaderLoaded);
}
private function onHeaderLoaded(evt:Event):void
{
trace("LOAD YOU JERK! = " + headerSwf.content['weekNo'].text);
}
Here's the problem:
The swf loads, there is no problem there. I see it in my compiled swf. but the complete event doesn't fire. CreationComplete will fire, and then I try, after that, to make a event listener for loading the actual swf, that doesn't fire. I've tried it a variety of different ways with no luck.
All I am trying to do is change a text field in the loaded swf. I imagine this might be a problem with the sequence of things loading or something like that, but not sure.
When are you adding the event listener? Is it possible you are adding the listener after the event has already fired?

Complete / Progress events aren't firing for Image control with embedded content

I've got the following MXML tag:
<mx:Image id="image" width="100%" height="100%"
source="#Embed('../assets/Test.swf')"
complete="completeHandler(event)"
progress="progressHandler(event)"/>
But for some reason my completeHandler / progressHandler functions aren't being called. The reason I need the complete event is because I want to manipulate the bitmap data once the image has loaded. In creationComplete the bitmap data is still null. Why aren't these events firing?
Edit: The asset is correctly showing in my application - so I know the asset is in the right location (the embed guarantees that at compile time anyway).
Check your asset path. Most probably, the swf is not at the right path or is not getting copied to an assets folder in the debug-build/release-build directory.
So, you just have to add the Event.COMPLETE listener to the loader.contentLoaderInfo directly instead of to the loader. I can't believe this isn't int he docs.
If you're using an embedded asset, the width / height properties are available immediately on the source object:
var mySource:Object = new embeddedClass();
m_myWidth = mySource.width;
m_myHeight = mySource.height;
m_image = new Image();
m_image.source = mySource;
So, you have to create an instance of the source first, then set the source on your image object.
That seems to be the expected behavior here!
From the documentation:
The progress event is not guaranteed to be dispatched. The complete event may be received, without any progress events being dispatched. This can happen when the loaded content is a local file.
So I think this part can explain why no progress events are being caught in your example.
Dispatched when content loading is complete. Unlike the complete event, this event is dispatched for all source types.
Note that for content loaded via Loader, both ready and complete events are dispatched.
For other source types such as embeds, only ready is dispatched.
It clearly says that you should listen for READY events instead of COMPLETE when dealing with embedded sources ;)

Error #2099: The loading object is not sufficiently loaded to provide this information

I have a Flash app made up of AS3 components that I am trying to run in Flex.
In Flash, after the main component is added to the stage, the loader object (loaderInfo.loader) is null which is fine and I handle that.
In Flex, on the applicationComplete event I add the the main component to the stage and the loader object's getter throws an exception - Error #2099: The loading object is not sufficiently loaded to provide this information.
Also, the INIT event, which is dispatched when the properties and methods of a loaded SWF file are accessible, is not firing which is probably part of the problem. But I can't figure out why it is not being dispatched.
Any ideas why the same code has two different results?
Mmm, that seems like a frustrating problem. When you say "main component", I presume you mean the document class in Flash?
I'm not sufficiently knowledgeable about flex to comment on the problem you described, but I can suggest that you try using ADDED_TO_STAGE instead of INIT as your event...
public class MainFlashClass extends Sprite {
public function MainFlashClass() {
addEventListener(Event.ADDED_TO_STAGE, onInit);
}
public function onInit(e:Event):void {
removeEventListener(Event.ADDED_TO_STAGE, onInit);
// do your initialisation code here
}
}
This might work for both scenarios. I've found ADDED_TO_STAGE to be more helpful because it always gets fired, whether the class is already loaded when the swf is executed (like the document class), or if it's being loaded with a Loader.
I'm not sure if this is what's going on with INIT event, but I do know that in flash player 9, which I'm assuming is the version of your SWF? There's a bug with referencing the loader through its own evt target. Basically if you are loading something and you try and access properties of the loader though evt.target.loaderInfo.loader it never can find itself and throws the error you described in your question. I believe it's a known bug for flash player 9 that was fixed with the release of CS4 and flash player 10.
Here's a link to a thread describing some of the problem, hopefully it helps
http://www.actionscript.org/forums/showthread.php3?t=137599
You definitely need to post code so we an see better.
With that said, after addChild are you attempting to grab the loaderInfo for the "main component" or for your mx:Application?
Pseudo
//onApplicationComplete event handler
var myswf:SWFLoader = new SWFLoader();
myswf.load(...);
addChild(nmyswf);
trace(myswf.loaderInfo.loader);
//end onApplicationComplete
Is that what you're doing? If so, you need to add an event listener to your "main component" (assuming an externally loaded swf) to find out when Event.COMPLETE happens.
var myswf:SWFLoader = new SWFLoader();
myswf.addEventListener(Event.COMPLETE, onMySWFComplete);
//..rest of code
Hope that helps. If not, post code.

Resources