A Flash Developer Resource Site

Results 1 to 15 of 15

Thread: swap throug scripting

  1. #1
    where is my mind linckx's Avatar
    Join Date
    Apr 2002
    Location
    ghent, belgium
    Posts
    111
    Hi there,

    is it possible to swap movieclips throug actionscripting, eg: when you click a button the button switches into a movieclip. This is NOT the effect I need, it's just an example.

    greetings, robin

  2. #2
    Senior Member
    Join Date
    Jul 2000
    Posts
    419
    there is no need to do what you say, just make everything movieclips, and your set

  3. #3
    where is my mind linckx's Avatar
    Join Date
    Apr 2002
    Location
    ghent, belgium
    Posts
    111

    there is need

    I'm not telling you you're wrong, but I need this

    greetings
    Robin

  4. #4
    Senior Member
    Join Date
    Jul 2000
    Posts
    419
    no logically it is impossible to ever need that ability, because everything a button does a movie can also do, my suggestion is to select your button, and on the property inspector change it to a movie clip,

  5. #5
    where is my mind linckx's Avatar
    Join Date
    Apr 2002
    Location
    ghent, belgium
    Posts
    111

    now I see

    I explained it not right

    What I want is that through a variable on a button, the movieclip on the stage changes into another movieclip, like the 'swap' button in your instance palet

    robin

  6. #6
    Senior Member
    Join Date
    Jul 2000
    Posts
    419
    you need to give all your movie clips that the movie might swap out with a linkage name, right click the movieclip in the library and choose linkage, give a name and then add the following code to the first frame of your movie

    Code:
    MovieClip.prototype.swap = function(linkage, instanceName){	
    	var insNam = (instanceName == undefined) ? linkage : this._name;
    	this._parent.attachMovie(linkage, insNam, this.getDepth());	
    }
    now all of your movieClips have a new method "swap" call it like this

    Code:
    Movieclip.swap(linkageName);

    so...

    Code:
    bob.swap("test");

    swaps the movie clip names "bob" with a movie clip in the library with a linkage name of "test"


    hope this helps







  7. #7
    where is my mind linckx's Avatar
    Join Date
    Apr 2002
    Location
    ghent, belgium
    Posts
    111

    extra detail

    Hi there,

    you've given me

    bob.swap("test");

    which works, and is quite a help. Thanx, but I need to fix one more thing, and I haven't got a clue on how to start.

    Now, I can only change from one to another, but what I need to do is that no matter which movieclip is put in there, it changes to the one I want.

    You see? I don't want to give in "bob", but something like an instance name that is equal for all the movieclips, because if I'm not mistaking, flash doesn't remember the instancename after the first swap, or does it?

    greetings...
    Robin


  8. #8
    Senior Member
    Join Date
    Jul 2000
    Posts
    419
    because of the way I set this up for you if you called

    bob.swap("test");

    it swaps out bob with the linked movieclip called "test" and yes it does remember the movies name bob stays bob
    you can then call

    bob.swap("anotherLinkedMovie");

    and it will work fine, if you want to change the name of bob after it swaps then call

    bob.swap("linkedMovie", "newName");

    as for all that other stuff your were talking about, please explain yourself better

  9. #9
    Developer
    Join Date
    Sep 2001
    Location
    The Bluegrass State Will Flash For Food ™
    Posts
    3,789
    (instanceName == undefined) ? linkage : this._name

    care to expain that little if then statement for those who don't understand

  10. #10
    Senior Member
    Join Date
    Jul 2000
    Posts
    419
    what that line of code does is make the instance name argument to the method not required,

    if you call
    bob.swap("mc", "henry");

    it swaps with links movie "mc" and renames the instance "henry"

    bob.swap("mc");

    simply swaps with links movie "mc" but keeps the same name it had before. I do this using the code

    var insNam = (instanceName == undefined) ? this._name: instanceName;
    this._parent.attachMovie(linkage, insNam, this.getDepth());

    if you don't give it an instance name "instanceName" is "undefined" so the first line of code is an if statement

    (instanceName == undefined)


    if it is true meaning the method was called with our "instanceame" argument, then variable insNam is set eq to the linkage name, otherwise it get the name you specify,


    CRAP I now see a problem, I wrote it to fast and made a simple mistake, any way here is the real method

    Code:
    MovieClip.prototype.swap = function(linkage, instanceName){	
    	var insNam = (instanceName == undefined) ? this._name : instanceName;
    	this._parent.attachMovie(linkage, insNam, this.getDepth());	
    }

    the code above will get the naming right sorry about that linckx

  11. #11
    where is my mind linckx's Avatar
    Join Date
    Apr 2002
    Location
    ghent, belgium
    Posts
    111

    positioning

    here i am again...

    everything works fine, except that he puts the swapped cast member in the upper left corner. How can I change that?

    don't bother about the little error, I bet you a thousand dollars I make more mistakes than you did today in the next ten minutes

    grtz

    robin

  12. #12
    Senior Member
    Join Date
    Jul 2000
    Posts
    419
    what do you mean "he puts the swapped cast member in the upper left corner. How can I change that?" who is "he" why top left?

    if you want to move a movie clip around just change it's x and y position like this

    movie._x = 100;
    movie._y = 350;


  13. #13
    That how can I do if that is a MC,not a linkage?

    e.g.

    _root.a.b.c.d.e
    swap with
    _root.skin.sk1.e

    Red -- one of the psychological primary hues.


  14. #14
    Senior Member
    Join Date
    Jun 2001
    Location
    in the back room of a dark pub
    Posts
    454
    that's a nice swap proto but is there any way to drill down through the original mc's properties and get the swapped one to inherit them?, because i can do it by individually swapping values but there must be an easier way of swapping properties?
    ~bugged

    imageWeaver gallery
    microsite direct download

    "Have you ever noticed? Anybody going slower than you is an idiot, and anyone going faster than you is a maniac."

  15. #15
    Senior Member
    Join Date
    Jun 2001
    Location
    in the back room of a dark pub
    Posts
    454
    ok i've managed to pull together this but it's not ideal.. you call it same as b4


    Object.prototype.copyProperties = function(toObj, propertyStr, exclude) {
    if (this instanceof Array) {
    for (var i = 0; i<this.length; i++) {
    if (typeof (this[i]) == "object") {
    toObj[i] = this[i] instanceof Array ? new Array() : new Object();
    this[i].copyProperties(toObj[i], propertyStr, exclude);
    } else {
    toObj[i] = this[i];
    }
    }
    } else {
    for (var i in this) {
    var index = propertyStr.indexOf("#"+i+"#");
    if ((exclude && index == -1) || (!exclude && index != -1)) {
    if (typeof (this[i]) == "object") {
    toObj[i] = this[i] instanceof Array ? [] : {};
    this[i].copyProperties(toObj[i], propertyStr, exclude);
    } else {
    toObj[i] = this[i];
    }
    }
    }
    }
    }
    ASSetPropFlags(Object.prototype, ["copyProperties"], 1);

    MovieClip.prototype.swap = function(linkage, instanceName) {
    var insNam = (instanceName == undefined) ? this._name : instanceName;
    var tempObj = new Object();
    this.x = this._x;
    this.y = this._y;
    this.xs = this._xscale;
    this.ys = this._yscale;
    this.r = this._rotation;
    this.a = this._alpha;
    this.v = this._visible;
    this.copyProperties(tempObj, "#x#y#xs#ys#");
    tempObj._x = tempObj.x;
    tempObj._y = tempObj.y;
    tempObj._xscale = tempObj.xs;
    tempObj._yscale = tempObj.ys;
    tempObj._rotation = tempObj.r;
    tempObj. _alpha = tempObj.a;
    tempObj. _visible = tempObj.v; this._parent.attachMovie(linkage, insNam, this.getDepth(), tempObj);
    };
    ~bugged

    imageWeaver gallery
    microsite direct download

    "Have you ever noticed? Anybody going slower than you is an idiot, and anyone going faster than you is a maniac."

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