-
Flash CS3, AS3 and XML - User Controlled Slideshow
Hello,
I have been learning flash and Actionscript 3 for the past couple of weeks and i have progressed nicely with making a site. I have some images being loaded into a MovieClip which are dynamically loaded from on XML. I can set it up so clicking left/right arrows navigates through the pictures and loops or i can set it so it automatically plays without user intervention.
What i would like to do though is have the images loaded into the MC via XML but have it so that when the Actionscript analyses the XML code it creates a small circle on the stage for each image (child) and then each circle is clickable to that particular image.
I know this sounds confusing so i am i just seeing if it's possible and if so how. I can easily create frames and links for the circles but i would rather it be done through AS3 if possible so that it is easily updatable.
Thanks for any help or advice :-)
-
rabid_Delineator
the best way to do this would be to make a circle class
Code:
package com.stageCircle {
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
public class StageCircle extends MovieClip {
public var id : Number;
private var body : MovieClip;
public function StageCircle ( t : int ) {
id= t;
addEventListener( Event.ADDED_TO_STAGE , onAddedToStage , false , 0 , true );
};
private function onAddedToStage( evt : Event ) : void {
removeEventListener( Event.ADDED_TO_STAGE , onAddedToStage );
init();
};
private function init() : void {
body = new MovieClip();
body.graphics.beginFill( 0x000000, 1 );
body.graphics.drawCircle( 0 , 0 , 10 );
body.graphics.endFill();
addChild( body );
addBehaviors();
};
private function addBehaviors() : void {
addEventListener( MouseEvent.MOUSE_OVER , 'rollOver' );
addEventListener( MouseEvent.MOUSE_OUT , 'rollOut' );
addEventListener( MouseEvent.CLICK , 'doClick' );
useHandCursor = true;
mouseEnabled = true;
mouseChildren = false;
};
private function rollOver( evt : MouseEvent ) : void {
};
private function rollOut( evt : MouseEvent ) : void {
};
private function doClick( evt : MouseEvent ) : void {
};
};
};
Then where you are handling your xml , you would
i
Code:
mport com.stageCircle.StageCircle;
private var holder : MovieClip;
then in some method somewhere , probably where you add images to your mc,
Code:
holder = new MovieClip();
addChild( holder );
for( var i : int = 0 ; i < yourXMLData.length() ; i ++ ) {
var sc : StageCircle = new StageCircle( i );
holder.addChild( sc );
sc.x = ( some value );
sc.y = ( some value );
};
-
Great, thank you very much for that! I will give that a try!!
-
rabid_Delineator
oh also if you are not writing code within a package , like the circle class thing i wrote , you dont need the private indentifier next to the variable declaration.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|