Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




Object LoaderInfo Parent?



I need to figure out what instance of a LoaderInfo object called an IOError. Basically, I'm attaching like 100 thumbnail frames and if there is an error on one of them I pop in a default image.The issue I'm having is that although I can detect an error, I'm not sure which of the 100 thumbnails threw it, does that make sense?
ActionScript Code:
for (var z = 0; z < xL; z++)    {        var item:ItemTemplate = new ItemTemplate();        holderMC.addChild(item);        itemA.push(item);        item.y = objHeight;        var imgPath:String = new String("thumbnails/" + imgList[z] + ".jpg");        imgRequest = new URLRequest(imgPath);        imgLoader = new Loader();        configureListeners(imgLoader.contentLoaderInfo)        item.addChild(imgLoader);        imgLoader.load(imgRequest);    }
and then the error handling:
ActionScript Code:
function configureListeners(dispatcher:IEventDispatcher):void {    dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);}function ioErrorHandler(event:IOErrorEvent):void{    trace (event.target)}
I need to trace the item that contains the imgLoader that threw the error, so I can turn the invisible hidden thumbnail on, if that made any sense at all...



KirupaForum > Flash > ActionScript 3.0
Posted on: 10-19-2007, 09:28 PM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

How Do I Find The LoaderInfo's Related Object?
I don't know if this is even possible, or if I'm going the right way about this.

Here's what I've got:


ActionScript Code:
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, imageProgressHandler);

function imageProgressHandler(event:ProgressEvent):void {
    var percent:uint = Math.floor(event.bytesLoaded / event.bytesTotal * 100);
    trace(event.target); // output - [object LoaderInfo]
}

What's the path from LoaderInfo to loader? (LoaderInfo doesn't recognise 'parent') Or how can I get to loader in this function?

LoaderInfo Get Values From EMBED And OBject Tag (not FlashVars)
hi
i try get values from object and embed tags like bgColor and allowFullScreen
but i cant find how i can it
loaderInfo.parameters return only flashVars
if some body know it please help
thank you

Sonettic Cinema Project





























Edited: 01/09/2008 at 03:42:08 AM by Roman Bambura

Parent Object
Hi all.

I have written a cript that has about 480 lines of code and I'm trying to prevent it from multiplying, so I came around an issue I need to sole (but couldn't).

The easiest way of explaining the situation is, I'm trying to find the parent of an object, like

parent_obj = new Object();
parent_obj.child_obj = new Object();
var cur:Object = new Object();
cur = parent_obj.child_obj;

How can I reach "parent_obj" from "cur" (or from "parent_obj.child_obj")? I have 13 functions that call one another (sometimes itself after a variable change) and I'm using the object as the parameter. There's one condition that all these functions need the parent object as the 2nd parameter, but...

Thanks in advance.

Parent Object
appData.account.addresses

appData is an Object
account is of Account Class
addresses is an array collection

If I am working with an address in the addresses collection. How do I get the owner of the addresses. Is there a parent object call?

Getting An Object's Parent
I've made a class that extends the TextInput object and when I create a new instance of it, I would like to be able to call a function in it's parent container (another class that extends MovieClip).

I don't know what I am doing wrong, but trace(this.parent) returns "null".
Is it possible to determine the parent movieclip in which the textinput resides?

Thanks in advance.

Shortened code example:


Code:
// parent
public class FieldRow extends MovieClip {
public function FieldRow() {
// i create an instance of my custom TextInput class
var field:fTextShort = new fTextShort();
addChild(field);
}
}

// child
public class fTextShort extends TextInput {
public function fTextShort() {
trace(this.parent); // returns null
}
}

Dynamically REMOVING Children From Parent Containers? MovieClip(this.parent.parent...
EDIT: actually, this isn't really dynamic... it should be really simple!

I can get a nested swf to add a movie to the root timeline, but in order to replace it with a new movie, AS3 first requires that I clear the old one. I can't figure it out!

This does not work, though it is the exact same format I use to add a movie to the root successfully:

Code:
MovieClip(this.parent.parent.parent).removeChild(MovieClip(this.parent.parent.parent).loadMovie)
Any idea why this doesn't work?

Finding Parent Object
I have a custom object called module. Within module is an array called mod_lo. Each element in mod_lo is a new lo_object.

This is an over-simplified version, but for example:

code:

_global.module = new function() {
this.mod_number = 0;
this.mod_name = "module 1";
this.mod_lo = new Array();
for(i=0;i<4;i++) {
this.mod_lo[i] = new lo(i);
}
}

_global.lo = new function(lonum) {
this.lo_number = lonum;
this.loname = "some name"
}



Now I have a MC that's has lo as a prototype, and is created with attachMovie, with the initObject being a specific lo.

Is there a way to detect the mod_number of the module that the lo is in?

Parent Coding Object?
i have a dilemma, and i think that i might be missing something really simple.

if i want to get to graphical parents, i just use parent keyword


BUT if i want to call methods from a parent coded obj that doesn't work.. maybe there's another keyword i don't know about. the only way i can figure it out is to pass in a reference to the object

this does NOT work


Code:
package
{
import flash.display.MovieClip;

import tester;

public class Shitz extends MovieClip
{
private var p_T:tester;

public function Shitz()
{
trace('started!');
p_T = new tester();
}
public function shit():void
{
trace('i shat');
}
}
}
and the class inside that class...


Code:
package
{
public class tester
{
public function tester()
{
parent.shit();
}
}
}
soooo... if i actuall change it to this, this works...

EDIT: forgot the error msg... here it is

1120: Access of undefined property parent.


Code:
package
{
import flash.display.MovieClip;

import tester;

public class Shitz extends MovieClip
{
private var p_T:tester;

public function Shitz()
{
trace('started!');
p_T = new tester(this);
}
public function shit():void
{
trace('i shat');
}
}
}
and the class inside the main one


Code:
package
{
public class tester
{
public function tester(parentCodeObj)
{
parentCodeObj.shit();
}
}
}

that works like a charm... BUTTT is this the proper way to do this sort of thing? it seems like there would be a better way! thanks in advance!

Get A Function's Parent Object?
In general, is there any way to refer to a function's parent object? If 'foo' is a function of 'obj', how do I refer to 'obj' from within 'foo'? Something like this:

PHP Code:



obj = new Object ();
obj.foo = function () {
  // how do I refer to 'obj' from here?
} // end obj.foo () 




More specifically, when an object's method invokes another function, that function can refer to the object method by arguments.caller. Is there anyway to refer to the instance which invoked that method in the first place? Something like this scenario:

PHP Code:



Foo = function (params) {
    this.init.apply (this, arguments);
} // end Foo constructor ()

Foo.prototype.init = function (params) {
    fud ();
} // end init () method

function fud () {
    this.caller = arguments.caller;
    trace (this.caller == Foo.prototype.init); // true
    // is there anyway to refer to the instance of Foo 
    // which invoked fud () .....?
} // end fud ()

var myFoo = new Foo (); 

How To Communicate With Sound Object From MC Of The Parent Swf?
Hi guys. My question is how do you communicate with sound object in an MC that sits on the timeline of the parent swf? This is done from an external swf which is loaded through a container mc of that parent swf.

Reference To An Object In Parent Class
Hello.

I don't know how to get a reference to an object in the main class from inside a movieclip instanciated during design time.


I have a main.fla file with a main.as class associated. I create en object called engine which contain all the logic.
main.as class :

ActionScript Code:
package {
    // required for flash file and output display
    import flash.display.MovieClip;
    import flash.events.*;

    import pixseed.engine_v1.*;

    // Flash CS3 Document Class.
    public class Main extends MovieClip {
        var engine:Engine;
        public function Main() {
            engine = new Engine("http://127.0.0.1/test/amfphp/gateway.php");
        }
    }
}

In the same main.fla file, I have a MovieClip on the stage called LoginPage wich is associated to a class defined in LoginPage.as. I want to get a reference to the object engine declared in man.as.
LoginPage.as :

ActionScript Code:
package {
    import flash.display.MovieClip;
    import flash.text.TextField;
    import flash.events.*;

    import pixseed.engine_v1.*;
   
    // Flash CS3 Document Class.
    public class LoginPage extends MovieClip {
        var engine:Engine;
        public function LoginPage() {
            // !!! HERE IS THE BUG !!!
            engine=_parent.engine;
           
            // Bouton ok, on tente le log
            function btOk_onRelease(ev:MouseEvent) {
                trace("click bt login");
                engine.user.login(inputEmail.text,this.inputPassword.text);
            }
            btOk.addEventListener(MouseEvent.CLICK, btOk_onRelease);
        }

    }
}

I know the _parent doesn't work but il lokks like what I want to do.

My questions :
- How can I get a reference to the object engine created in main Movieclip ?
- Do you think the way my application is designed is right ? I put all comon function in one object "engine" so I just give a reference to this object everywhere I need it.

Hope it is clear thank you for your answers.

How To Communicate With Sound Object From MC Of The Parent Swf?
Hi guys. My question is how do you communicate with sound object in an MC that sits on the timeline of the parent swf? This is done from an external swf which is loaded through a container mc of that parent swf.

Change A Clips Parent Object
Hi there everyone,

got a bit of a tricky one here [well, it could be an easy one, but I have no idea where to start on this one]

Lets say I have two objects on a stage, one named mcA and mcB, within mcA I have another object [called subA] which contains a few small objects, a AS class and some other stuff like components etc...

Is there a way for me to replicate that exact object [subA] inside mcB without loosing any data and such? is this posible?

So basically I want to make a copyClip function, that has the ability to copy/move objects from one object/clip to another.....

Any Ideas?

TA !

Trying To Execute Functions With Parameters On Parent Object
I have created a component that uses two classes to build a dynamic option tree from an XML file. The first class creates instances of the second class and forms a set of optionButtons within optionButtons until the entire XML file has been processes. When an option button is clicked, the AS checks to see if the clicked option has any subOptions. If so, it expands them; if not I want the AS to execute a method on the root object and pass the chosen option as a parameter. I can access properties and alter properties of the root object, but I cannot execute any of it's methods.

Any ideas as to why not?

To see the component in action and browse the xml go to:
www.russwood.net/preview/test/

Thanks a ton to all who reply.

Problems When Resizing The Parent Of A Textfield Object
I've created a sprite which contains a textfield instance. This instance is filled with htmltext from an xml file. Now, if I dynamically resize the container sprite (by scaling it) the text in the textfield starts "running". Words shift lines etc.
Does anybody know how I can prevent that from happening???

Variable Access/modification On The Parent Object...
Howdy...

Is it true that I cannot access/modify a variable defined in the parent object from the child object if the parent is Sprite???

If I change the datatype of the parent to MovieClip, I can modify the public variable by using MovieClip(parent).some_arr.push("whatever"); but the same code does not work if the parent is set to Sprite...

Why is it if that is the case??? Is there any workaround in that case???

Thanks...

Acessing A Loaded .swf's Parent Display Object
Hello.

In this website I'm currently developing I have a main.swf with only a preloader. I preload several .xml files and the content.swf. The content.swf acts on some of the .xml files and creates a custom gallery, deciding which images it needs to load. Now, I figure that I can use the same preloader in the main.swf to show the loading progress for these images before removing it and adding the content.swf to the display list. But for that I need to access main.swf's properties - namely, the preloader - from the content.swf.

How can I do this? Thank you.

Loaded Object's Stage / Parent / Root Null?
What I'm trying to do is pretty simple: load a swf, and then have the loaded swf position something based on the stage width & height. But when I use the Loader object to load something, it seems to be unable to figure out its stage, or its parent. What am I doing wrong?


ActionScript Code:
package com.project
{
    import flash.display.Loader;
    import flash.display.MovieClip;
    import flash.events.Event;

    public class Preloader extends MovieClip
    {
        private var mainLoader:Loader = new Loader();
        private var mainLoaderRequest:URLRequest = new URLRequest('main.swf');
        private var mainLoaderInfo:LoaderInfo = LoaderInfo(mainLoader.contentLoaderInfo);;

        public function Preloader():void
        {
            addChild(mainLoader);
            mainLoader.load(mainLoaderRequest);
            mainLoaderInfo.addEventListener(Event.COMPLETE, handle_mainLoader_complete);
        }

       
        private function handle_mainLoader_complete (evt:Event):void
        {
            addChild(mainLoader);
        }
    }
}
package com.project
{
    import flash.display.MovieClip;

    public class Main extends MovieClip
    {
        public function Main():void
        {
            trace(root); // returns [Object Main]
            trace(parent); // returns null
            trace(this); // returns [Object Main]
            trace(stage); // returns null
            trace(root.stage); // returns null
            trace(this.stage); // returns null
        }
    }
}

Acessing A Loaded .swf's Parent Display Object's Properties
Hello.

In this website I'm currently developing I have a main.swf with only a preloader. I preload several .xml files and the content.swf. The content.swf acts on some of the .xml files and creates a custom gallery, deciding which images it needs to load. Now, I figure that I can use the same preloader in the main.swf to show the loading progress for these images before removing it and adding the content.swf to the display list. But for that I need to access main.swf's properties - namely, the preloader - from the content.swf.

How can I do this? Thank you. http://www.vivoeusebio.com

Scroll Pane Component As Parent Object In Script
I have an animated diagram with several mc's nested within it. It is very large in pixel width, and I want the user to be able to scroll across it to see the activity. So I decided to use a scroll pane. What happens to my mc hiearchy when I reference it as an mc from the scroll pane "Scroll content" property? I'm having difficulty using the action script at the root to control those objects now nested in the scroll pane.

Thanks...

LoaderInfo
I have added an swf using loadMovie in as2. The swf is written in as3. I need to know how I can get the url parameters I have passed to my swf in as3. Any help would be appreciated.

Get URL From LoaderInfo IOErrorEvent
Ok... this seems quite strange to me.

I'm loading an image with Loader class, adding a listener to its LoaderInfo object like this:

ActionScript Code:
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
var req:URLRequest = new URLRequest("myUrl.jpg");
loader.load(req);
Then of course I have a function ioErrorHandler.
How can I get the url within that error handler?
The IOErrorEvent doesn't have something like a url property, nore does the LoaderInfo has one.
Well, I just though of getting my Loader object back within the error handler like this:

ActionScript Code:
function ioErrorHandler(event:Event){
    trace(event.target.loader);
}
But well... I get runtime error #2099. The Loader object is not available in ioErrorEvent.
Do I really need to parse the url from IOErrorEvent.message?

LoaderInfo.loaderURL
Hi all, just a quick one this time!! this handy piece of code


Code:
tf.appendText(String(loaderInfo.loaderURL));
requests what page i am on eg file:///D:/as3-structure/functions/flashVars.swf

which is great but is there a way of finding out what the html page is called that the movie is embeded in, other than force feeding it the html page names via flash vars

Any idea would help loads cheers
Sam

LoaderInfo.bytesTotal
For some reason, I can't get bytesTotal to return its value when I upload my swf on a server, it works on my HDD and in the Flash environment. Here's the code.

stop();
function loadProgress(erogressEvent):void {
if (e.bytesLoaded == e.bytesTotal) {
nextFrame();
} else {
trace(e.bytesLoaded, e.bytesTotal);
}
};
loaderInfo.addEventListener(ProgressEvent.PROGRESS , loadProgress);

Oh, and I've changed the permitions to 777.

AS3 Preloading And LoaderInfo
Hello,

I'm utilizing the same technique in the "Preloading in ActionScript 3" video so I have a preloader SWF and a contents SWF. My contents SWF has some visual resources and loads the whole class base for my web site. My problem is that my contents SWF needs to use the loaderInfo.parameters object and the loaderInfo.url value in order to function correctly but I am unsure how to reference these values from within the contents SWF document class.

Can anyone tell me if what I'm trying to do is possible? My first thought was to use parent.loaderInfo.parameters but this gives me undefined values.

Thanks.

LoaderInfo And ProgressEvent.PROGRESS
Hi.

I'm working on a project where I have to preload several .swfs. I created a custom class (myLoader) that extends the Loader class and adds it a few string variables with data I need. To each instance's contentLoaderInfo I add event listeners for ProgressEvent.PROGRESS and assign the same event handler function.

The problem is, I need to access the myLoader instance from the event handler, but so far I haven't been able to, not until it finishes loading.

I'm not an expert on the AS3 event model, but the ProgressEvent.PROGRESS is not a bubbling event so I don't think I can listen to it from the Loader instance itself, for example.

I'm really stumped with this, don't know why the LoaderInfo object can't access the Loader immediately, since the Loader instance creates it in the first place. The url property returns "null" also.

Any help in this matter is very appreciated.


Code:
//Event handler.
private function _progressHandler ($evt:ProgressEvent):void {
trace ($evt.target);
trace ($evt.currentTarget); // both return [object LoaderInfo]

trace ($evt.target.loader);
trace ($evt.currentTarget.loader); //both return Error #2099: The loading object is not sufficiently loaded to provide this information.

trace ($evt.target.url);
trace ($evt.currentTarget.url); //both return null
}

LoaderInfo.Event.COMPLETE
i am using Document class to setup my preloader like code below

but the event (Event.COMPLETE) not fire every time,
and i found that it only happen on IE Flash Player(ActiveX control) when IE have cache on the swf.
is that a bug?







Attach Code

function myBaseClass(){
this.stop();
this.loaderInfo.addEventListener(Event.COMPLETE, loaderInfo_on_complete);
}

private function loaderInfo_on_complete(event:Event):void{
this.nextFrame();
}

LoaderInfo And ProgressEvent.PROGRESS
Hi.

I'm working on a project where I have to preload several .swfs. I created a custom class (myLoader) that extends the Loader class and adds it a few string variables with data I need. To each instance's contentLoaderInfo I add event listeners for ProgressEvent.PROGRESS and assign the same event handler function.

The problem is, I need to access the myLoader instance from the event handler, but so far I haven't been able to, not until it finishes loading.

Any help in this matter is very appreciated.

Using LoaderInfo To Get Params From HTML
Hi All

Working my way throught the new things in AS3. One problem is getting <params> passed to the .swf from the HTML file. I can make it work if the code is embedded via Actions on frame 1, but not when the code is in an external .as file! The example I'm playing with is the 'Dynamic video playlist'...

http://www.adobe.com/devnet/flash/articles/video_playlist.html

and the amendments I've made in the VideoPlaylist.as file are as <=====ADDED below...

ALL HELP/COMMENTS MUCH APPRECIATED, thank you
ROBERT

package {
import flash.display.MovieClip;
import flash.display.LoaderInfo; <=====ADDED
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.Event;
import fl.controls.listClasses.CellRenderer;
import fl.controls.ScrollBarDirection;

public function VideoPlaylist():void {
// Load the playlist file, then initialize the media player.
xmlLoader = new URLLoader();
xmlLoader.addEventListener(Event.COMPLETE, initMediaPlayer);

//xmlLoader.load(new URLRequest("playlist.xml")); <=====ADDED commented out

var playlist = this.loaderInfo.parameters.xmlfile; <=====ADDED
xmlLoader.load(new URLRequest(playlist)); <=====ADDED argument change

etc etc...

The error report is...
TypeError: Error #2007: Parameter url must be non-null.
at flash.net::URLStream/load()
at flash.net::URLLoader/load()
at VideoPlaylist()


And the HTML code is this for the xmlfile parameter I'm trying to read in...

<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="

LoaderInfo/flashvars Not Working
i have a file named: 394354.html

In it is the following code:

codebase="http://download.macromedia.com/pub/s...ersion=9,0,0,0" width="900" height="900" id="LoaderExample" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="allowFullScreen" value="false" />
<param name="movie" value="LoaderExample.swf?notes=394354" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /> <embed src="LoaderExample.swf?notes=394354" quality="high" bgcolor="#ffffff" width="900" height="900" name="LoaderExample" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />


I tried to access the Query string via:

var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters;
the_text.text = paramObj.notes;

That is part of the source in the LoaderExample.swf.
And all I get is a "Parameter text must be non-null" error. I've alternatively tried the FlashVars method using additional <param> and <object> tags but i get the same error. What is going on with Actionscript 3? is this a bug? What am I doing wrong? Do the 5 or 6 tutorials i've read leave some important detail out ?

BaseClass Preloader Using LoaderInfo
Hi all,

I've googled this to death but can't get any solutions to work!

All I want to do is add preloading onto my main base class for my project. I am simply trying:

Code:
package Classes{
import flash.display.MovieClip;
import flash.events.*;
public class loadTest extends MovieClip {
public function loadTest() {
this.loaderInfo.addEventListener(ProgressEvent.PROGRESS, showProgress);
}
private function showProgress(myEvent:ProgressEvent):void {
trace("Loading");
}
}
}
I export, then CTRL+RETURN to simulate a download, but my progressUpdate event is not triggered until I reach 100% - obviously that's not going to make for a very successful preloader. What am I doing wrong?

Many thanks
Lar

LoaderInfo And ProgressEvent.PROGRESS
Hi.

I'm working on a project where I have to preload several .swfs. I created a custom class (myLoader) that extends the Loader class and adds it a few string variables with data I need. To each instance's contentLoaderInfo I add event listeners for ProgressEvent.PROGRESS and assign the same event handler function.

The problem is, I need to access the myLoader instance from the event handler, but so far I haven't been able to, not until it finishes loading.

Any help in this matter is very appreciated. http://www.vivoeusebio.com

LoaderInfo.parameters Accessible By Loader?
Imagine swf 'a' using the Loader Class to load swf 'b'.

Does swf 'b' have access to parameters that were passed into swf 'a' in the html?(without swf 'a' explicitly informing swf 'b' of the parameters)

for example, i have tried the following:







Attach Code

//swf a:

var testParm:String="no parameter passed";
if (this.root.loaderInfo.parameters.hasOwnProperty("testParm")) {
testParm=this.root.loaderInfo.parameters.testParm;
}
var testBox:TextField=new TextField();
testBox.text="swf a: "+testParm;
testBox.width=200;
this.addChild(testBox);
var ldr:Loader = new Loader();
var url:String = "swfb.swf";
var urlReq:URLRequest = new URLRequest(url);
ldr.y=100;
addChild(ldr);
ldr.load(urlReq);
----------------------------------------------------------
//swf b:

this.root.loaderInfo.addEventListener(Event.COMPLETE,completed);
function completed(event:Event):void {
var testParm:String="no parameter passed";
if (this.root.loaderInfo.parameters.hasOwnProperty("testParm")) {
testParm=this.root.loaderInfo.parameters.testParm;
}
var testBox:TextField=new TextField();
testBox.text="swf b: "+testParm;
testBox.width=200;
this.addChild(testBox);
}
----------------------------------------------------------
the parameter being passed in the html:

swfa.swf?testParm=the parameter works!

----------------------------------------------------------

swf b doesn't see the parameters passed into swf a.

thanks!
craig

How Can I Work With LoaderInfo.content While Loading?
I'm trying to implement the display of a loading swf into a papervision scene, as outlined by Paul Spitzer in his devnet about video in papervision. This requires updating a bitmapdata object to reflect the playhead position of the swf being loaded.

In my code snippet, you can see that all I am ultimately trying to do is trace out the object being loaded, by referring to loaderInfo.content. But if I try to run this code, I repeatedly get the dreaded:

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

At 50% load, I believe I should be able to access loaderInfo.content. Is there a better way to work with loaderInfo.content whilst loading an external swf?

Thanks for any help.







Attach Code

setupVideo();
function setupVideo():void {
var url: String = "beach_vid.swf";
var request: URLRequest = new URLRequest(url);
var loader: Loader = new Loader();

var loaderInfo: LoaderInfo = loader.contentLoaderInfo;
loaderInfo.addEventListener(ProgressEvent.PROGRESS, handleLoadProgress);

loader.load(request);
}

function handleLoadProgress(event: ProgressEvent):void {
var percent: Number = event.bytesLoaded / event.bytesTotal * 100;
if (percent >= 50) {
var loaderInfo: LoaderInfo = event.target as LoaderInfo;
var video = loaderInfo.content;
trace(video);

loaderInfo.removeEventListener(ProgressEvent.PROGRESS, handleLoadProgress);
}
}

























Edited: 01/21/2008 at 02:01:39 PM by jeddhorvath

LoaderInfo IOErrorEvent - Retrieve Loader
I have a Loader with an IOErrorEvent listener added to its contentLoaderInfo.
How can the listener function retrieves Loader object by the target?

var ldr:Loader = new Loader();
ldr.addEventListener(e:IOErrorEvent.IO_ERROR, LoadError);
.....
function LoadError(e:IOErrorEvent)
{
var x:Loader = LoaderInfo(e.target).loader;
....
}

I get runtime error #2099.
I need to retrieve loader object because I have to remove its listeners after error occurred and I have to get its position in an Array.

thanks a lot

Weird Behavior With ProgressEvent And LoaderInfo
I have this code (im learning and testing as3 right now)

Code:

package {
   
   import flash.display.MovieClip;
   import flash.display.Loader;
   import flash.display.LoaderInfo;
   
   import flash.events.Event;
   import flash.events.ProgressEvent;
   
   import flash.net.URLRequest;
   
   
   public class Main extends MovieClip {
      
      public function Main(){
         var loader:Loader = new Loader();
         addChild(loader);
         var request:URLRequest = new URLRequest("http://dummyurl.com/image.jpg");
         loader.load(request);
         loader.loaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress);
      }      
      
      private function onProgress(e:ProgressEvent):void{
         var l:LoaderInfo = LoaderInfo(e.target);
         trace(l.bytesLoaded + " / " + l.bytesTotal + " percent " + l.percentLoaded);
      }
   }
}

#1 It doesnt display the correct size in bytes... but some weird number which look correct but when i view the properties of the image, it has a different size.
#2 The percentLoaded is asking me to use the LoaderInfo type, but as you can see I am already doing that.

I used the example from the Help Panel in CS3 and placed the code in the actions panel and everything worked ok, but now that its in a separate class file i doenst work right.

This is the code from the Help Panel if you are wondering

Code:

import fl.containers.ScrollPane;

var url:String = "http://www.helpexamples.com/flash/images/image1.jpg";

var myScrollPane:ScrollPane = new ScrollPane();
myScrollPane.setSize(320, 240);
myScrollPane.move(10, 10);
myScrollPane.addEventListener(ProgressEvent.PROGRESS, progressHandler);
myScrollPane.addEventListener(Event.COMPLETE, completeHandler);
myScrollPane.load(new URLRequest(url));
addChild(myScrollPane);

function progressHandler(event:ProgressEvent):void {
    var bLoaded:int = event.bytesLoaded;
    var bTotal:int = event.bytesTotal;
    var pctLoaded:int = int(event.currentTarget.percentLoaded);
    trace("progress: " + bLoaded + " of " + bTotal + " bytes loaded (" + pctLoaded + "%)");
}

function completeHandler(event:Event):void {
    trace("complete:");
}

Object Created In A Frame's Actions Telling Parent Frame To Delete It?
I've got an object (an instantiation of my own class that extends Sprite) being created in the actions for a frame, like this:


Code:
import Scripts.CFoobar;

var foobar:CFoobar = new CFoobar();
addChild(foobar);

stop();
CFoobar then creates and manages some buttons, etc. At a certain point, CFoobar knows it's time has come, and it wants to be deleted, and have the frame go to another frame.

What's the best way to have it do this?

Refer To "parent Object" In Listener Function
Hi there!

I just want to set the attribute of the new Test object instance from inside the listener function.
"this" refers to the XML object in this case, not to the new Test object...
Any help?


ActionScript Code:
class Test {
    var attribute:Number;
   
    function Test(file:String){
        var myXML:XML = new XML();
        myXML.load(file);
       
        myXML.onLoad = function(success){
            if(success){
                //set attribute here
            }
        }
    }
}

LoaderInfo.loader Flex/Flash Differences?
Hi!

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?

AS3 - Problem With Root.loaderInfo.parameters.myVar
I'm trying to load flashvars into an as 3.0 movie but every time I compile it I get an error "there's no property with the name 'root'".


var mediaDir:String = root.loaderInfo.parameters.mediaDir;
var targetCar:String = root.loaderInfo.parameters.targetCar;

Is there something I'm missing here? Do I need to import a method or something.

Thanks with any help with this,

Joe

LoaderInfo.loader Flex/Flash Differences?
Hi!

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?

Root.loaderInfo.parameters And Untyped Member Access
I used to get variables that were added from SWFObject by using _level.variableName. I learned taht I now need to use root.loaderInfo.parameters to access these same varaibles but I am getting a warning message saying that my variable is an untyped member. (warning using FDT in eclipse)

I have tried to cast this using 'root.loaderInfo.parameters.variableName as String' but that isn't working. Can anybody shed some light on this? I'm about ready to turn the warning off but I figure it will be better to understand what is happening and what I can do to fix the warning.

Thanks,
Jason

LoaderInfo Returns Null, Runtime Error #1009
I'm desperately hoping someone can help me here, I'm migrating from as2 to as3 and where previously I would use the onLoadInit I am having trouble with firing an event from the loaderInfo class.

As a code overview, a function recieves an array of data, which it loops over and makes a new object from. In each iteration a load method is called which creates a new clip (via the loader class) within this object and loads a swf into it. I'm attaching an event listener to the loader to wait for Event.INIT, which then calls a function like loadCompleteHandler or similiar. When I run the code I get the #1009 error about null object references.

After some searching I thought that maybe the trouble would be caused/solved by appending the child to the stage at various places in the code, however the error still remains even when nothing is appended to the stage.

Finally (after all this waffle) here is the code


Code:
package com.emakmafu.app {
import flash.display.Sprite;
import flash.events.*;
import flash.display.Loader;
import flash.net.URLRequest;

import utils.MegaTrace;

/* @author Alex */
public class ShapeManager extends Sprite {

//private vars
private var shapeArray : Array;
private var targetClip : Sprite;
private var applicationDomain : String;
private var loadedShapes : Array;

public function ShapeManager(inTarget : Sprite):void {
targetClip = inTarget;
}

public function pushShapesToArray(inItems:Array):void {
shapeArray = [];
loadedShapes=[];
for (var i : Number = 0; i < inItems.length; i++) {
var tempShape : ShapeItem = new ShapeItem(this);
tempShape.myObject = inItems[i];
tempShape.addEventListener(MouseEvent.MOUSE_OVER, shapeHover);
loadShapeSource(tempShape);
shapeArray.push(tempShape);
}
dispatchEvent(new Event("shapesLoaded"));
}

private function loadShapeSource(inShape:ShapeItem):void{
var loadingShape : ShapeItem = inShape;

var shapeGraphic : Loader = new Loader();
//configureLoadListeners(shapeGraphic.loaderInfo);

var graphicSource : URLRequest = new URLRequest(applicationDomain+inShape.mySource);
shapeGraphic.load(graphicSource);

loadingShape.addChild(shapeGraphic);

}

private function resetRegPoint(event:Event) : void {
MegaTrace.printR(event.target);
}

private function shapesComplete(event:Event):void{
loadedShapes.push(1);
if(loadedShapes.length == shapeArray.length){
//dispatchEvent(new Event("shapesLoaded"));
}
}

private function shapeHover(event:Event):void {

}

private function configureLoadListeners(dispatcher:IEventDispatcher):void {
trace('added listneers to object');
dispatcher.addEventListener(flash.events.Event.INIT, shapesComplete);
//dispatcher.addEventListener(Event.INIT, resetRegPoint);
}
Where the line configureLoadListeners(shapeGraphic.loaderInfo); is commentted is where the error occurs

Problem W/loaderInfo.loader. INIT Event Not Dispatched.
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.

The same exact code in Flex has different results. 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 supposed to be dispatched when the properties and methods of a loaded SWF file are accessible, does not appear to be firing which is probably part of the problem. But I can't figure out why it is not being dispatched.

My code snippet of what happens when the object is instantiated is below.

This line of code in the function checkLoaderInfo(...) throws the exception:
if (this.loaderInfo.loader == null)

The exception is caught in handleAddedToStage(...) which adds handlers as follows...
this.loaderInfo.addEventListener(Event.COMPLETE, checkLoaderInfo);
this.loaderInfo.addEventListener(Event.INIT, checkLoaderInfo);

The events are never dispatched and the Flex app just does nothing after that.
I just get that nice blue flex background...


Code:
public class FluidPlayer extends Container // container is a MovieClip...
{
imports...
private vars...
public vars...

public function FluidPlayer():void
{
if(stage)
handleAddedToStage();
else
addEventListener(Event.ADDED_TO_STAGE, handleAddedToStage);
}

private function handleAddedToStage(event:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, handleAddedToStage);
actionsource = new FluidActionSource();
addChild(actionsource);

try
{
checkLoaderInfo();
}
catch (error:Error)
{
this.loaderInfo.addEventListener(Event.COMPLETE, checkLoaderInfo);
this.loaderInfo.addEventListener(Event.INIT, checkLoaderInfo);
}

if (localConnectionName == "")
{
if (ExternalInterface.objectID)
localConnectionName = ExternalInterface.objectID;
else
localConnectionName = "FluidPlayer";
}

if (this.loaderInfo.parameters.hasOwnProperty("listeners"))
{
var listeners:String = this.loaderInfo.parameters.listeners.replace(/s/g,"");
fluidAPI = new FluidAPI(localConnectionName,listeners.split(","));
}
else
fluidAPI = new FluidAPI(localConnectionName);

contentArea = new FluidContentArea();
addChild(contentArea);

fluidController = FluidController.instance;
soundManager = SoundManager.instance;
}

private function checkLoaderInfo(event:Event = null):void
{
this.loaderInfo.removeEventListener(Event.COMPLETE, checkLoaderInfo);
this.loaderInfo.removeEventListener(Event.INIT, checkLoaderInfo);

if (this.loaderInfo.loader == null)
{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.addEventListener(Event.RESIZE, handleResize);
handleResize();

if (this.loaderInfo.parameters.hasOwnProperty("XMLData"))
loadXML(this.loaderInfo.parameters.XMLData);
else
trace("* Missing XMLData flashVar, listening for flashLoadXML() API call...");

if (this.loaderInfo.parameters.hasOwnProperty("skin"))
loadStyleSheet(this.loaderInfo.parameters.skin);
else
trace("Missing skin flashVar, listening for flashLoadXML() API call...");
}
}

...
...

Problem W/loaderInfo.loader. INIT Event Not Dispatched.
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.

The same exact code in Flex has different results. 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 supposed to be dispatched when the properties and methods of a loaded SWF file are accessible, does not appear to be firing which is probably part of the problem. But I can't figure out why it is not being dispatched.

Any ideas?

Thanks!
Chris

Casting LoaderInfo.content (.swf File) To Its Document Class Causes Compilel Err 1180
I have a Flash file (Foo.fla) with a document class Foo that has a movieclip in its library named Bar that is linked to a class Bar (generated bij Flash). The Foo constructor:


Code:
public function Foo() {
addChild(new Bar());
}
Foo.fla compiles to Foo.swf and runs with no errors. Now from a different Flash file (Test.fla) with a document class Test I want to load Foo.swf using the flash.display.Loader class:


Code:
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoad);
loader.load(new URLRequest("Foo.swf"));
In the event handler I get a compile error for Foo.as (the document class for Foo.swf) when I try to cast the content property of the contentLoaderInfo object to an instance of Foo.


Code:
private function onLoad(e:Event):void {
var loaderInfo:LoaderInfo = e.target as LoaderInfo;
loaderInfo.content as Foo; // Cause a compile error in Foo.as
}

Quote:




Foo.as, Line 6
1180: Call to a possibly undefined method ProgressBar.
addChild(new Bar());




Foo.as compiles without errors but Test.as causes a compile error in Foo.as which is unexpected.

Why is this happening and what can I do to prevent it?

Thank you!

Referencing Parent Without Adding It To The Parent's DisplayObjectContainer
When using composition, how do I reference the parent object from the child without having added it to the parent's DisplayObjectContainter (addChild) first?

Example:

class A {
var b:B = new B();
}
NOTE: I didn't use addChild on purpose.

class B{
how do I reference A from here the way I would use 'super' to reference a superclass when using inheritance?
}

Relative Path: Targeting A Parent's Parent?
Does anyone know if it is possible to target a parent's parent in relative paths?

Something like this (but this doesn't work):

_parent._parent.myMovie

Thanks....

"parent" For Object
Is it possible to access the"parent" object from a child object reference? (Like accessing a parent MovieClip from a child mc.)

Copyright © 2005-08 www.BigResource.com, All rights reserved