A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: onClipEvent() usage

  1. #1

    onClipEvent() usage

    I thought the docs for onClipEvent() were pretty straightforward, but...

    I have a slideshow type of thing with a forward and backward button which fire a function loading the photo into a another clip called pictureFrame. I want to display a "Loading" message in somewhere when a loadMovie() loads a jpg file into it.

    Code:
    var titles:Array = new Array();
    var photos:Array = new Array();
    var captions:Array = new Array();
    var credits:Array = new Array();
    var urls:Array = new Array();
    var junk:Array = new Array();
    
    lv = new LoadVars();
    
    var index:Number;
    var first:Number;
    var last:Number;
    var urlLink:String;
    
    lv.onLoad = function(ok:Boolean) {
    	if (ok) {
    		junk = lv.list.split("^");
    		populateList();
    		index = -1;
    		first = 0;
    		last = photos.length-1;
    		nextPhoto();
    	} else {
    		trace("error");
    	}
    };
    
    lv.load("../html/getPhotoList.php");
    
    function populateList():Void {
    	var fileName:String;
    	var tempString:String;
    	var link:String;
    	tmp = new Array();
    	for (i=0; i<junk.length-1; i++) {
    		tmp = junk[i].split("]");
    		titles[i] = tmp[0];
    		photos[i] = tmp[1];
    		captions[i] = tmp[2];
    		credits[i] = tmp[3];
    		urls[i] = tmp[4];
    	}
    }
    
    function nextPhoto() {
    	if (index<last) {
    		index += 1;
    		loadPhoto();
    	}
    }
    function prevPhoto() {
    	if (index>first) {
    		index -= 1;
    		loadPhoto();
    	}
    }
    
    function loadPhoto() {
    	url = "../images/";
    	var bytesTotal:Number;
    	var bytesLoaded:Number;
    	pictureFrame._xscale = 65;
    	pictureFrame._yscale = 65;
    	pictureFrame.loadMovie(url+photos[index], pictureFrame);
    	if (credits[index] != "") {
    		urlLink = '<a href="'+urls[index]+'"><u>'+urls[index]+'</u></a>';
    		txtCredits.htmlText = "Photo by "+credits[index]+"  "+urlLink;
    	} else {
    		txtCredits.htmlText = "";
    	}
    	txtTitle.text = captions[index];
    }
    
    pictureFrame.onLoad=function() {
    	txtCaption.text="Loading";
    }
    
    stop();
    I thought the thing to use would have been to attach an onClipEvent(load) to the pictureFrame MC but I'm getting a script error when I do that:
    "**Error** Symbol=mcGallery, layer=actions, frame=2:Line 83: Expected a field name after '.' operator.
    pictureFrame.onClipEvent(load) {

    Total ActionScript Errors: 1 Reported Errors: 1
    Not sure how to resolve my error. I need some help understanding the onClipEvent function. It's supposed to be a global function, yes?

    Attached -
    The guts of the slideshow.
    Attached Files Attached Files
    Last edited by TimeTunnel; 07-22-2006 at 10:59 PM.

  2. #2
    Member
    Join Date
    Jul 2006
    Posts
    50
    onClipEvent is used when you are programming inside an object instance (which, by the way, is nowadays not suggested).

    To make a function work when an object is loaded programming from the timeline you have to use mc.onLoad = function () {}. In fact, if you look at that script you got, you'll see it's used several times .

  3. #3
    Amazed and Amused Mazoonist's Avatar
    Join Date
    Mar 2006
    Location
    Northern California
    Posts
    201
    The onClipEvent events go directly on the movie clip(s) themselves. In other words, it's object code rather than frame code. Click on the object on the stage, press F9, and you get the actions panel for writing code on that object. So, you would write, for example:
    Code:
    onClipEvent(load) {
        //do something
    }
    There can never be anything in front of the word "onClipEvent." That's why you're getting the error. The frame code version of the same function is the one you're using in your code:
    Code:
    myMC.onLoad = function() {
        //do something
    }
    These are two different versions of the same event--just the syntax and the placement of the code is different. The event is meant to allow you to initiate some kind of action when the clip itself is first loaded.

  4. #4
    Amazed and Amused Mazoonist's Avatar
    Join Date
    Mar 2006
    Location
    Northern California
    Posts
    201
    After re-reading your post, I realized that what you're really after is a pre-loader. That's not what the "load" function is for--it's for the loading of the clip itself, not whatever you load INTO it.

    You can make a fairly easy preloader, using the "loader" and "progressBar" components. I'm not sure right offhand how to insert them into the code you've got.

  5. #5
    Quote Originally Posted by Neverbirth
    onClipEvent is used when you are programming inside an object instance (which, by the way, is nowadays not suggested).
    I think I recall reading the onClipEvent() was deprecated - or nearly deprecated anyway.

  6. #6
    Quote Originally Posted by Mazoonist
    After re-reading your post, I realized that what you're really after is a pre-loader. That's not what the "load" function is for--it's for the loading of the clip itself, not whatever you load INTO it.

    You can make a fairly easy preloader, using the "loader" and "progressBar" components. I'm not sure right offhand how to insert them into the code you've got.
    Yes, conceptually this is what I'm after - a preloader of sorts.
    I really don't care about a full-blown preloader (progress bar and percentage loaded) I believe.
    Just a simple "Loading" message that pops up somewhere and goes away when the picture appears.

    It's that "loading" event I need to capture.

    I have a sinking feeling I need to deconstruct and rebuild this whole gallery thing.

  7. #7
    Amazed and Amused Mazoonist's Avatar
    Join Date
    Mar 2006
    Location
    Northern California
    Posts
    201
    Hey TimeTunnel,

    Don't feel too bad, you've got a good slideshow there. I don't think you'll have to deconstruct the whole thing.

    I downloaded it and played with it a bit. I even added in the loader and progress bar and got them going. Only thing is, I get "sandbox security violation" errors when I run the app from my computer. I think this happens when you try to pull assets from a different domain. However, it still loads the pictures, and I think you probably won't get the error when you test locally or publish to the same domain that the PHP files and the pictures are on.

    Inside of flash, when you test the movie, go to the view menu, choose "Download settings" and set for 56k. Then go back to view menu, choose "Simulate Download." You should see the progress bar working.

    I deleted the instance of the "pictureFrame" movie clip and replaced it with a loader component, and named it "loader." I added a progress bar, and in the component inspector (for the progress bar), where it says source, I put "loader." Then, in the code, I altered the loadPhoto function by commenting out what was there and inserting a command for the loader to load the URL. Other than that, the file is the same as it was. But I did save it under a new name, so that your previous version is intact.

    Maybe it'll work for you. Give it a shot. The security sandbox violations are the only thing I'm not sure of.

    Oops I forgot. Files with components in them are too big to upload here. Hang on.....

    Edit: http://www.mazoons.com/flash/freepor...wPreloader.fla
    Last edited by Mazoonist; 07-23-2006 at 02:39 AM.

  8. #8
    Hi Mazoonist,
    Thanks for the excellant addition/correction to my flash movie! It does work locally, but when I publish and upload, it does not.

    However, that amounts to just playing around with the contentPath I believe. I will be doing that today.

    One question, and maybe this should be a new thread: When I add the progress bar component, my compile time and system resource usage increase dramatically.
    Compile time shoots from 2 or three seconds. up to like 90-120 seconds or so.

    If that's just the way it is with components, then okedoke, I'll take it!

    Thanks again for your help.

  9. #9

    Resolved

    Never mind. I'm a boob!
    I seemed to have overlooked the Loader component you put in the fla and the ProgressBar's source: the Loader object.

    It works fine Mazoonist. Thanks again.

    Oh - and the compile time I referred to?
    It seems that the jpg I imported for one of the other clips got corrupted somehow when adding new components to the main movie.

    I haven't figured out how that keeps happening, but it's ok now.

  10. #10
    Amazed and Amused Mazoonist's Avatar
    Join Date
    Mar 2006
    Location
    Northern California
    Posts
    201
    There may be a disadvantage to using the components as preloaders, as for those with slow connections, the components themselves may take a little time to load. You'll have to test to see how it behaves with 56k. But the advantage is that it's simple and easy, and you don't have to build it yourself. And more and more people have fast connections nowadays. But if you want to pursue building your own pre-loader, an excellent resource can be found at http://www.gotoandlearn.com. Look for the tutorial "basic flash preloader." Just for general reasons, you should check out that site! It's great-- free video tutorials on various things Flash.

  11. #11
    Quote Originally Posted by Mazoonist
    There may be a disadvantage to using the components as preloaders, as for those with slow connections, the components themselves may take a little time to load. You'll have to test to see how it behaves with 56k. But the advantage is that it's simple and easy, and you don't have to build it yourself. And more and more people have fast connections nowadays. But if you want to pursue building your own pre-loader, an excellent resource can be found at http://www.gotoandlearn.com. Look for the tutorial "basic flash preloader." Just for general reasons, you should check out that site! It's great-- free video tutorials on various things Flash.
    Yeah I've been there. You're right, it is a great site.!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center