A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: attachMovie problem

  1. #1
    file not found Captain_404's Avatar
    Join Date
    Apr 2006
    Posts
    457

    attachMovie problem

    What I'm trying to do is move an instance of a movie clip from inside one mc to a different mc.

    on the frame of the to-be-moved:

    Code:
    var i = 0;
    onEnterFrame = function() {
    	i++;
    	if (i == 100) {
    		_root.freshEnTile(1, _x, _y);
    		this.removeMovieClip();
    	}
    }
    stop();
    on the main timeline:

    Code:
    function freshEnTile(a:Number, x:Number, y:Number) {
    	trace("hi y'alls");
    	enNum++;
    	bob.attachMovie("a"+a, "a"+enNum, enNum);
    	bob["a"+enNum]._x = x;
    	bob["a"+enNum]._x = y;
    }
    I do get the "hi y'alls" message, so to some extent it does work. My problem is that when the mc that calls the function removes itself, it somehow takes the new one with it, even though there is absolutely no line in my code saying to remove the new mc.

    I'm completely baffled.

  2. #2
    Pumpkin Carving 2008 ImprisonedPride's Avatar
    Join Date
    Apr 2006
    Location
    Grand Rapids MI
    Posts
    2,377
    I don't understand. Do you mean to say that the mc inside the one deleting itself is deleted also? Because that's completely normal.
    The 'Boose':
    ASUS Sabertooth P67 TUF
    Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
    8GB G.Skill Ripjaws 1600 DDR3
    ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
    New addition: OCZ Vertex 240GB SATA III SSD
    WEI Score: 7.6

  3. #3
    file not found Captain_404's Avatar
    Join Date
    Apr 2006
    Posts
    457


    Sorry, I couldn't think of how to say it with words.

    Anyway, "move" it from one mc to the next by creating a new one, then deleting the old one, but when I delete the old one, it somehow destroys the new as well.

  4. #4
    Pumpkin Carving 2008 ImprisonedPride's Avatar
    Join Date
    Apr 2006
    Location
    Grand Rapids MI
    Posts
    2,377
    My guess would be order becaue more than likely you're trying to create the same thing by the same name somewhere else, so they both get deleted. Try deleting the old one THEN creating the new one. If this still doesn't work, take a look a your naming convention, make sure you haven't assigned both of them to the same name or something easily mistakable somewhere. Finally if that doesn't work, check your scope and always, always, trace every object when testing.
    The 'Boose':
    ASUS Sabertooth P67 TUF
    Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
    8GB G.Skill Ripjaws 1600 DDR3
    ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
    New addition: OCZ Vertex 240GB SATA III SSD
    WEI Score: 7.6

  5. #5
    file not found Captain_404's Avatar
    Join Date
    Apr 2006
    Posts
    457
    Code:
    freshEnTile = function(a, x, y, hep) {
    	trace("fresh!");
    	trace(a+" "+y+" "+x+" "+hep);
    	hep.removeMovieClip();
    	enNum++;
    	bob.attachMovie("bill", "freidrick"+enNum, enNum);
    	trace(scr2["freidrick"+enNum]);
    	bob["freidrick"+enNum]._x = 300;
    	bob["freidrick"+enNum]._y = 200;
    }
    I updated the code to this and I'm still getting the same old errors.

    I programmed our good friend bill over there to trace his name every frame so that I could get an idea if he was there or not and for how long. The mc is only there for about 5 frames and then spontaneously combusts.


    I've never come across the term "scope" in flash before, what do you mean by that exactly?

  6. #6
    Pumpkin Carving 2008 ImprisonedPride's Avatar
    Join Date
    Apr 2006
    Location
    Grand Rapids MI
    Posts
    2,377
    Attach your .fla and I'll take a look...

    scope means where variables "exist". For instance, variables inside a function have a "local" scope, which means they are only recognized inside the function, and only exist for the life of the function. On the otherhand, variables on the _root can be recognized anywhere in that frame, across multiple layers even.

    This actually just arised a question to the general public at FK, take a look at this code:

    Code:
    var temp1 = "first"
    temp2 = "second"
    
    function echo() {
    	trace(temp1 + "\n" + temp2);
    	var temp3 = "third";
    	temp4 = "fourth";
    }
    
    echo();
    trace(temp3 + "\n" + temp4);
    stop();
    My question: Explain to me why variables can have "var" or not and still have scope anywhere, but in a function, non "var" can do the same while variables with "var" can not?



    ADDED: I looked it up and found this in the help files:

    var statement
    var variableName [= value1][...,variableNameN[=valueN]]

    Used to declare local variables. If you declare variables inside a function, the variables are local. They are defined for the function and expire at the end of the function call. More specifically, a variable defined using var is local to the code block containing it. Code blocks are demarcated by curly braces ({}).
    This does not say anything about variables inside a function originally declared without var. Any thoughts?
    Last edited by ImprisonedPride; 05-25-2007 at 07:20 PM.
    The 'Boose':
    ASUS Sabertooth P67 TUF
    Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
    8GB G.Skill Ripjaws 1600 DDR3
    ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
    New addition: OCZ Vertex 240GB SATA III SSD
    WEI Score: 7.6

  7. #7
    file not found Captain_404's Avatar
    Join Date
    Apr 2006
    Posts
    457
    You want to look at my .fla you say...get ready for confusion.

    I'm trying to "mod" strille's tile engine to allow for two different sorts of set's of tiles moving around, enemies, which *in theory* hurt you, and ground which is impassible. This way, I'm only running a shapeflag for two mc's which isn't too cpu taxing in my experience. Although I'm probably attacking this problem the entirely wrong way because I'm too lazy to work out the hard way. Slightly ironic...

    Anyway when you load the movie, hold down space, construct a level with fire, then press "t" to test it. I'll probably have to explain more later on. Thanks a lot though!

    EDIT: the attachment didn't take for some reason, I think the word attach has something against me

    EDITx2: file's too big, I tried to bring the size down but to no avail, could I email it to you maybe?
    Last edited by Captain_404; 05-25-2007 at 07:28 PM.

  8. #8
    Truimagz.com everfornever's Avatar
    Join Date
    Sep 2006
    Location
    St. Louis
    Posts
    1,306
    If the files under 10mb you can put it here.

    http://creativededication.com/upload.html

    Now as to your problem.

    Are you trying to remove a mc and then place that same mc inside a different one?

    That shouldnt be a problem

    just a

    var myClipName:String = this.myHolder.myClip._name
    this.myHolder.myClip.swapDepths(0)
    this.myHolder.myClip.removeMovieClip()

    this.myNewHolder.attachMovie(myClipName,myClipName ,0)


    this is assuming your keeping the name of the attached clip the same as the linkage name in the library.

    this.myNewHolder
    Last edited by everfornever; 05-25-2007 at 08:10 PM.

  9. #9
    file not found Captain_404's Avatar
    Join Date
    Apr 2006
    Posts
    457
    Thanks efn, I forgot about your site.

    http://creativededication.com/hosting/newTileEngine.fla

    Also, that's exactly what I'm doing, but somehow the new mc is removed five frames later and now it seems I can't change it's x/y via my function after attaching.

  10. #10
    Truimagz.com everfornever's Avatar
    Join Date
    Sep 2006
    Location
    St. Louis
    Posts
    1,306
    what do you mean five frames?

    Ill look at this .fla one moment..........

  11. #11
    Truimagz.com everfornever's Avatar
    Join Date
    Sep 2006
    Location
    St. Louis
    Posts
    1,306
    oh geez.... maybie someone else can help....I have no idea.

    Sorry man.

  12. #12
    file not found Captain_404's Avatar
    Join Date
    Apr 2006
    Posts
    457
    I solved my problem, it was actually a combination of several things that caused even more glitches down the line. If any of you are just dying to know what I changed: http://creativededication.com/hosting/newTileEngine.fla


    Thanks so much ImprisonedPride and everfornever!

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