PDA

Volledige versie bekijken : MovieClip vervangen door een andere MovieClip


Garpie
%Europe/Berlin %024 %2006, 01:35
Ik heb 3 movieclips genaamd appelen, peren, bananen
op frame 1/layer 1 heb ik movieclip appelen geplaatst met instance naam 'fruit_clip'
op frame 1/layer 2 een dynamic text, instance naam 'fruit_txt'
op frame 1/layer 3 heb ik volgende AS:
var fruit = new Array("appelen","bananen","peren");
var a = random(3);
fruit_clip.attachMovie("appelen","fruit[a]",fruit_clip.getNextHighestDepth());
fruit_txt.text = fruit[a];
stop();Als ik dan naar de preview kijk (control + enter) krijg ik wel steeds een andere fruit_txt maar mijn fruit_clip blijft appelen.

Ben nu al 8 uren bezig om iets anders te zien dan appelen en zie het niet meer zitten, kan iemand mij helpen? Heb de forum afgezocht en google geprobeerd maar nergens een oplossing te vinden of allezins niet de juiste oplossing.

Met vriendelijke groet,
Garpie

PS: Ik gebruik Macromedia Flash 8

Tommyfied
%Europe/Berlin %399 %2006, 10:35
Lijkt me logisch, je blijft de "appelen" mc attachen, je geeft hem alleen steeds een andere naam ;)

F1 doet wederom wonderen:

attachMovie (MovieClip.attachMovie method)
public attachMovie(id:String, name:String, depth:Number, [initObject:Object]) : MovieClip

Takes a symbol from the library and attaches it to the movie clip. Use MovieClip.removeMovieClip() or MovieClip.unloadMovie() to remove a SWF file attached with attachMovie() method.

You can extend the methods and event handlers of the MovieClip class by creating a subclass.

Availability: ActionScript 1.0; Flash Player 5

Parameters
id:String - The linkage name of the movie clip symbol in the library to attach to a movie clip on the Stage. This is the name that you enter in the Identifier field in the Linkage Properties dialog box.

name:String - A unique instance name for the movie clip being attached to the movie clip.

depth:Number - An integer specifying the depth level where the SWF file is placed.

initObject:Object [optional] - (Supported for Flash Player 6 and later) An object that contains properties with which to populate the newly attached movie clip. This parameter allows dynamically created movie clips to receive clip parameters. If initObject is not an object, it is ignored. All properties of initObject are copied into the new instance. The properties specified with initObject are available to the constructor function.

Returns
MovieClip - A reference to the newly created instance.

Example
The following example attaches the symbol with the linkage identifier circle to the movie clip instance, which is on the Stage in the SWF file:

this.attachMovie("circle", "circle1_mc", this.getNextHighestDepth());
this.attachMovie("circle", "circle2_mc", this.getNextHighestDepth(), {_x:100, _y:100});


The MovieClip.getNextHighestDepth() method used in this example requires Flash Player 7 or later. If your SWF file includes a version 2 component, use the version 2 components DepthManager class instead of the MovieClip.getNextHighestDepth() method.


Ik neem aan dat je nu ziet wat er fout is en hoe je dat moet oplossen?

Laiverd
%Europe/Berlin %402 %2006, 10:39
fruit_clip.attachMovie(fruit[a],fruit[a],fruit_clip.getNextHighestDepth());In jouw code randomise je wel, maar het enige wat je er mee doet is die random waarde gebruiken voor de instancename van de nieuwe clip, niet om een andere clip te attachen. Lees de handleiding nog maar eens na wat betreft attachMovie. Je zet nu dus gewoon iedere keer 'appelen' neer.

En kijk ook even naar Math.random() als je toch bezig bent; random() is nl. deprecated.

John

Garpie
%Europe/Berlin %639 %2006, 16:20
Thx voor de reacties, het is me gelukt.
1 grote dikke fout gemaakt :#
Vergeten linkage te maken...
AS ook een beetje aangepast en het werkt nu perfect :)

Garpie
%Europe/Berlin %860 %2006, 21:38
Nieuw probleem:
Zoals in eerst post werkt het perfect, nu wil ik het random beeld laten uitzoeken via PHP en het werkt niet.
Hierbij toch maar even mijn .fla en .php toevoegen want ik kan het nogal moeilijk verwoorden.

Zo moet het zijn: Klik hier (http://www.garpie.be/mk/swf/mortal_kombat.swf) (Klik daarna op refresh 'F5')
Hier is mijn .fla en .php in een .zip: Klik hier (http://www.garpie.be/mk/swf/fout.zip)

Garpie
%Europe/Berlin %719 %2006, 18:16
Kan niemand mij helpen?