A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: ActionScript Dilemma: An alternative to _root.createEmptyMovieClip ?

  1. #1
    Member
    Join Date
    Apr 2006
    Posts
    49

    ActionScript Dilemma: An alternative to _root.createEmptyMovieClip ?

    I've got some code for a Flash Panorama tool that I cannot figure out how to change. The problem is that it loads .swf files and movieClips using the _root method. I've figured out how to dump my pano .swf into an empty movieClip in my project, but this still means that once you import your panorama master .swf into a larger Flash project, that master .swf clip never goes away after you call it up.

    Is there a way to replace all of the _root load instances in the script with something that you can control? Here's the code:

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

    var radar_offset:Number=0;
    var currentid:Number=0;
    var topid:Number=1;
    var hotspots:Array=new Array;

    // Create container movieclip
    var vr:MovieClip = _root.createEmptyMovieClip("vr", 1);
    // prevent access to "real" root
    vr._lockroot=true;

    function clearHotspots() {
    var mc:MovieClip;
    var i:Number;
    for (i=0;i<hotspots.length;i++) {
    mc=hotspots[i];
    mc.removeMovieClip();
    }
    hotspots=new Array();
    }

    function loadPanorama(id:Number) {
    // Create a Movieclip loader
    var myLoader = new MovieClipLoader();
    var myListener = new Object();

    // remove old Hotspots
    clearHotspots();

    myListener.onLoadStart = function () {
    var filename:String;
    // Set the dimentions and position of the pano
    vr.window_width=500;
    vr.window_height=398;
    vr.window_x=364;
    vr.window_y=0;
    // change autorotation
    vr.autorotate=0.5;
    vr.autorotate_delay=20;

    // add a preview bar...
    var my_fmt:TextFormat = new TextFormat();
    my_fmt.bold = true;
    my_fmt.font = "Arial";
    my_fmt.size = 12;
    my_fmt.color = 0xffffff;
    _root.createTextField("pretxt",10,170,40,200,20);
    _root.pretxt.setNewTextFormat(my_fmt);
    _root.pretxt.selectable = false;
    _root.pretxt.text = "Loading...";
    _root.createEmptyMovieClip("prebar",21);
    };

    myListener.onLoadProgress = function(target_mc:MovieClip, loadedBytes:Number, totalBytes:Number) {
    // update progress bar
    var x1:Number,x2:Number,y1:Number,y2:Number;
    _root.pretxt.text = "Loading... " + Math.floor(100*loadedBytes/totalBytes) + " %";
    _root.prebar.clear();
    _root.prebar.beginFill(0x0000FF, 30);
    _root.prebar.lineStyle(2, 0x000080, 100);

    x1=_root.pretxt._x;
    x2=x1 + 180 * loadedBytes/totalBytes;
    y1=_root.pretxt._y+20;
    y2=y1+10;

    _root.prebar.moveTo(x1, y1);
    _root.prebar.lineTo(x2, y1);
    _root.prebar.lineTo(x2, y2);
    _root.prebar.lineTo(x1, y2);
    _root.prebar.lineTo(x1, y1);
    _root.prebar.endFill();

    };

    myListener.onLoadComplete = function () {
    // remove progress bar
    _root.pretxt.removeTextField();
    _root.prebar.removeMovieClip();
    };

    myListener.onLoadInit = function () {
    setupPanorama(currentid);
    // Add another hotspot to position pan 0, tilt -90 (nadir) without rollover effect
    var hs_p2q:MovieClip=_root.attachMovie("pano2qtvr_lib" ,"hs_textmc2",10200);
    hs_p2q.onRelease=function() {
    _root.getURL('http://www.pano2qtvr.com','_blank');
    }
    vr.pano.addHotspot('p2q',0,-90,hs_p2q);
    // add hotspots to a list to clear them
    hotspots.push(hs_p2q);
    compass.fov._visible=true;
    };

    // add the Listener
    myLoader.addListener(myListener);

    // set the parameters for the different panoramas
    if (id==1) {
    filename="/support/StateFarm-Office.swf";
    radar_offset=0;
    compass._x=map._x+map.bt1._x;
    compass._y=map._y+map.bt1._y;
    }
    if (id==2) {
    filename="/support/StateFarm-Welcome.swf";
    radar_offset=180;
    compass._x=map._x+map.bt2._x;
    compass._y=map._y+map.bt2._y;
    }

    // remove the radar during loading
    compass.fov._xscale=0;
    compass.fov._yscale=0;
    compass.fov._visible=false;

    // ... and finally load the pano!
    myLoader.loadClip(filename, vr);
    currentid=id;

    }





    // add the map
    var map:MovieClip=_root.attachMovie("map","map",20005, {_x:230,_y:0});

    // connect the buttons in the map
    map.bt1.onPress=function () {
    loadPanorama(1);
    }
    map.bt2.onPress=function () {
    loadPanorama(2);
    }


    // ... and the rader is even higher...
    var compass:MovieClip=_root.attachMovie("compass_lib", "compass",20010,{_x:60,_y:200,_alpha:50});

    compass.fov._xscale=0;
    compass.fov._yscale=0;
    compass._visible=true;
    compass.fov._visible=false;

    // update the shape of the rader on each frame
    _root.onEnterFrame=function() {
    compass.fov._rotation=-(vr.pano.getPan()+radar_offset);
    compass.fov._xscale=100*Math.tan(vr.pano.getFov()* Math.PI/360);
    compass.fov._yscale=100*Math.cos(vr.pano.getTilt() *Math.PI/180);
    }

    // load the pavilion pano first
    loadPanorama(2);


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

    Thanks

  2. #2
    http://pat.theorigin.net cresquin's Avatar
    Join Date
    Jun 2003
    Location
    Los Angeles, CA
    Posts
    685
    there are two solutions here: one is to set _lockroot = true. that makes your loaded panorama it's own entity and cam be easily removed with minimal impact to the rest of your movie. The alternative ti to change all the "_root" calls to "this". I haven't looked at the entire structure of this script, (seriously it's 4 pages of un formatted code... who's gonna read all that), but it will probably work with some small tweaks.

  3. #3
    Member
    Join Date
    Apr 2006
    Posts
    49
    Quote Originally Posted by cresquin
    there are two solutions here: one is to set _lockroot = true. that makes your loaded panorama it's own entity and cam be easily removed with minimal impact to the rest of your movie. The alternative ti to change all the "_root" calls to "this". I haven't looked at the entire structure of this script, (seriously it's 4 pages of un formatted code... who's gonna read all that), but it will probably work with some small tweaks.
    I think I've found a solution.

    I've simply removed the

    Code:
    _root.
    whenever there's loading to be done.

    I then took that code and dumped it into a movieClip that resides in my main project library. A button loads the clip to level 10 (which is where all my movieClips reside). Press another menu button and that clip is replaced. If I hadn't removed the root, it gets difficult to remove.

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