473,699 Members | 2,424 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A phrase carousel / rotator

113 New Member
Hi,

I've been trying to create a carousel class which takes an array of phrases and then creates a textfield for each one positioning it vertically based on the order it was added. The next stage would be for it to make the phrases move down the _y axis until they reach the limit of the container. The phrases need to then swap onto a container behind or drop depths so they are behind the other phrases and then make their way back up. The general idea being like an upright carousel.

I first tried to create it in one class (PhraseCarousel ), but then i thought maybe it would be better to separate it into two classes so there's one for the phrase objects aswell (PhraseObject), i did this because i was thinking that i should give the moving behaviour to the phrase objects instead of dealing with that in the carousel.

Anyway where I'm struggling at the moment is how to best add the PhraseObject instances, do I attach them to the main timeline or do i add them to an array on the main timeline and then pass them to the carousel class?

I'm a bit new to OOP so my code is not really making all that much sense at the moment:

Expand|Select|Wrap|Line Numbers
  1. class PhraseObject extends MovieClip {
  2.  
  3.     private var phrase:String;
  4.     private var textObject:TextField;
  5.     private var startPositionY:Number;
  6.     private static var count:Number = 0;
  7.     private static var mTimeLine;
  8.     private var depth:Number;
  9.     private var container:MovieClip;
  10.  
  11.     function PhraseObject(pTimeLine:MovieClip,phrase:String,startPositionY:Number) {
  12.  
  13.         // Initialise variables
  14.         trace("PhraseObject, initialising...");
  15.         this.phrase = phrase;
  16.         this.startPositionY = startPositionY;
  17.  
  18.         // Set the timeline to attach the phrase object to
  19.         mTimeLine = pTimeLine;
  20.  
  21.         // Set the depth for the object
  22.         depth = mTimeLine.getNextHighestDepth();
  23.  
  24.         // Create a movieclip for the object
  25.         container = mTimeLine.createEmptyMovieClip("container"+depth,depth);
  26.  
  27.         // Add the text to the phrase object
  28.         createPhraseObject();
  29.  
  30.         // Update 
  31.         updatePhraseNumber();
  32.     }
  33.     function createPhraseObject() {
  34.  
  35.         // Create textfield
  36.         textObject = container.createTextField("phrase_"+count+"_txt",count, 100, 100, 300, 100);
  37.         textObject.color = 0xFF0000;
  38.         textObject.text = this.phrase;
  39.         textObject._x = 0;
  40.         textObject._y = startPositionY;
  41.  
  42.         // Return a reference 
  43.         return container;
  44.     }
  45.     public function setY(newY:Number) {
  46.  
  47.         this._y = newY;
  48.  
  49.     }
  50.     private static function updatePhraseNumber() {
  51.  
  52.         trace("Updating count: "+count);
  53.         count++;
  54.         return count;
  55.  
  56.     }
  57.  
  58. }
  59.  
Expand|Select|Wrap|Line Numbers
  1. class PhraseCarousel extends MovieClip {
  2.  
  3.     /* //////////////////////////////////////////// */
  4.     /* //////        Define Variables       /////// */
  5.     /* //////////////////////////////////////////// */
  6.  
  7.     private var phrases:Array = new Array();
  8.     private var phraseStack:Array = new Array();    
  9.     private var phraseCount:Number;
  10.     private var phraseTotal:Number;
  11.     private var phraseInterval:Number;
  12.     private var phraseIntervalCount:Number;
  13.     private var count:Number;
  14.     public var mcPhraseCarousel:MovieClip;
  15.     public var thisObj:PhraseCarousel;
  16.  
  17.     /* //////////////////////////////////////////// */
  18.     /* //////    Define Public Functions    /////// */
  19.     /* //////////////////////////////////////////// */
  20.  
  21.     public function PhraseCarousel (phrases:Array) {
  22.  
  23.         trace("PhraseCarousel loaded.");
  24.  
  25.         // Set the phrase count 
  26.         phraseCount = 0;        
  27.  
  28.         // Set the number of phrases
  29.         phraseTotal = phrases.length;                
  30.  
  31.         // Set how often we want a phrase to appear
  32.         phraseInterval = 10;
  33.  
  34.         // Set the count for the phrase interval
  35.         phraseIntervalCount = 10;
  36.  
  37.         // Set the base count for the carousel
  38.         count = 0;
  39.  
  40.     }
  41.     public function PushPhrase() {
  42.  
  43.         trace(" Adding a phrase: "+phraseCount);    
  44.  
  45.         // Check if all phrases have been pushed onto the stack
  46.         if(phraseCount < phraseTotal) {
  47.  
  48.             // Push a new phrase onto the stack
  49.             phraseStack[phraseCount] = phrases[phraseCount];        
  50.  
  51.             // Increment phrase interval count
  52.             phraseCount++;
  53.  
  54.         }
  55.         else {
  56.  
  57.             trace(" Resetting phrase interval count");
  58.  
  59.             // Reset phrase interval count
  60.             phraseCount = 0;
  61.  
  62.         }
  63.  
  64.     }
  65.  
  66.     /* //////////////////////////////////////////// */
  67.     /* //////    Define Private Functions   /////// */
  68.     /* //////////////////////////////////////////// */
  69.  
  70.     private function display() {
  71.  
  72.         trace(" Displaying phrase stack");
  73.  
  74.         var i = 0;     
  75.  
  76.         // Display phrase stack
  77.         for(i=0;i<phraseStack.length;i++) {
  78.  
  79.             trace("  Phrase Stack Pos: "+i+" Phrase "+phraseCount+" = "+phraseStack[i]);
  80.  
  81.         }
  82.  
  83.     }
  84.     private function onEnterFrame() {
  85.  
  86.         // Check if phraseInterval has reached and then push a phrase
  87.         // otherwise display phrase interval count
  88.         if(phraseIntervalCount == phraseInterval) {
  89.  
  90.             trace(" Phrase Interval reached, resetting to 0");
  91.  
  92.             // Reset phrase inteval count
  93.             phraseIntervalCount = 0;
  94.  
  95.             // Push a phrase onto the stack
  96.             PushPhrase();
  97.  
  98.             // Display phrase stack
  99.             display();
  100.         }
  101.         else {
  102.             //trace(" Count: "+count);
  103.             trace(" Phrase Interval Count: "+phraseIntervalCount);
  104.             // Increment phrase interval count
  105.             phraseIntervalCount++;
  106.  
  107.         }
  108.  
  109.     }
  110.     private function startCarousel() {
  111.  
  112.  
  113.     }
  114. }
  115.  
Hope someone can point me in the right direction, thanks.

chromis
Mar 16 '09 #1
1 2613
chromis
113 New Member
Ok so perhaps my question was a bit complicated, i've simplified my goal and gone for one class with two functions one for adding phrases and one for organising them on the stage.
I've having trouble organising them now, what i'm trying to do is loop throuh the array of phrases and position them vertically below each other each time a new phrase is added, i can't seem to get the code quite right though could somone point out where i'm going wrong please?

PhraseCarousel. as:
Expand|Select|Wrap|Line Numbers
  1. class PhraseCarousel extends MovieClip {
  2.  
  3.     /* //////////////////////////////////////////// */
  4.     /* //////        Define Variables       /////// */
  5.     /* //////////////////////////////////////////// */
  6.  
  7.     public var phrases:Array;
  8.     private var phraseCount:Number;
  9.     private var phraseTotal:Number;    
  10.     private var speed:Number;
  11.     private var spacing:Number;    
  12.     private var lastPhrase:Number;
  13.  
  14.     /* //////////////////////////////////////////// */
  15.     /* //////    Define Public Functions    /////// */
  16.     /* //////////////////////////////////////////// */
  17.  
  18.     public function PhraseCarousel() {
  19.  
  20.         trace("PhraseCarousel loaded.");
  21.  
  22.         // Initialise phrases array
  23.         phrases = new Array();
  24.  
  25.         // Set the phrase count 
  26.         phraseCount = 0;        
  27.  
  28.     }
  29.     public function addPhrase(phrase:String) {
  30.  
  31.         trace(" Adding a phrase: "+phraseCount);    
  32.         var newPhrase:TextField;
  33.  
  34.         // Create textfield format object
  35.         var textField_fmt:TextFormat = new TextFormat();
  36.         textField_fmt.font = "Arial";
  37.         textField_fmt.color = 0xFF0000;
  38.         textField_fmt.size = 15;
  39.         textField_fmt.bold = true;        
  40.         textField_fmt.align = "left"
  41.         textField_fmt.underline = true;
  42.  
  43.         // Create textfield
  44.         newPhrase = this.createTextField("phrase_"+phraseCount,phraseCount, 0, 0, 200, 20);
  45.         newPhrase.text = phrase;
  46.         newPhrase.setTextFormat(textField_fmt);
  47.  
  48.         trace("Phrases: "+phrases+" newPhrase "+newPhrase);
  49.  
  50.         // Set speed
  51.         speed = 2;
  52.  
  53.         // Set spacing
  54.         spacing = 10;
  55.  
  56.         // Set last phrase
  57.         lastPhrase = phraseCount;
  58.  
  59.         // Add new textfield to phrases array
  60.         phrases.push(newPhrase);
  61.  
  62.         // Organise phrases
  63.         organise(phraseCount);
  64.  
  65.         // Increment phrase count
  66.         phraseCount++;
  67.     }
  68.  
  69.     /* //////////////////////////////////////////// */
  70.     /* //////    Define Private Functions   /////// */
  71.     /* //////////////////////////////////////////// */
  72.  
  73.     private function organise(latestPhrase:Number) {
  74.  
  75.         trace(" Organising phrase stack");
  76.  
  77.         var i = 0;     
  78.         var latestPhrase:Number;
  79.         var newYPos:Number;
  80.         var newYLimit:Number;
  81.         var currentPhrase:Number;
  82.  
  83.         if(phrases.length > 1) {
  84.  
  85.             trace("  Phrases count = "+phrases.length+" continuing..");
  86.  
  87.             this.onEnterFrame = function() {    
  88.  
  89.  
  90.                 // Loop through phrases, moving all phrases apart from the first one down 
  91.                 for(i=1;i<phrases.length;i++) {
  92.  
  93.                     if(phrases[i]._y < (phrases[lastPhrase]._y + phrases[lastPhrase]._height)) {
  94.  
  95.                         phrases[i]._y = phrases[i]._y + 20;
  96.  
  97.                     }
  98.                     else {
  99.                         delete this.onEnterFrame;
  100.                     }
  101.  
  102.                 }
  103.  
  104.             }
  105.  
  106.         }
  107.         else {
  108.  
  109.             trace(" Currently no phrases on the stack.");
  110.  
  111.         }
  112.  
  113.     }
  114.  
  115. }
  116.  
Thanks.

Chromis
Mar 18 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
1966
by: Carolyn Gill | last post by:
It was working fine on the test server. loaded it onto iis6 server after installing php and got everything working (after redirecting it to the correct directory) except for 1 annoying error that I don't understand. Any help would be appreciated - the sooner the better so I can get some sleep tonight! Undying gratitude to anyone willing to help a php beginner! here's the page with the error http://www.ioworldwide.com/ and...
1
1675
by: jonathanthio | last post by:
How do I create a page rotator? Is there a script for that? Also is there a way to do a page rotator that's not random but based on cookies. For example, if a new person see my website, it'll go to my website. If he visits my website a second time, it'll go to a traffic exchange website. Can that be done?
3
1663
by: Mark A. Sam | last post by:
Hello, Does anyone know of a third party ad rotator that automatically changes the images? It seems like the ad rotator in that comes with Visual Web Developer changes images only when the pages is refreshes. Is that correct? Thank you and God Bless, Mark A. Sam
0
3394
by: dimkar | last post by:
I finished my first design in flsh 8 using autoscript. It is a carousel gallery of 14 images rotating around. I am very new to this area but i hava a knowledge on programming language. What i want is when an image comes in the center of the monitor to scale automatically, stay at the max scale for around 2 secs then scale back to its original size. when an image is in the proccess of scaling, the other images should stop and wait until the...
7
1943
by: raknin | last post by:
Hi I have a carousel script. I want to load the carousel with a new set of pictures every time I press a button. The problem that I have that the script append the new pictures to the olds one and the next and previous buttons are added again and again. Please help meto solve the problem. The full html and javascript are attached for your conviniet. HTML ------- <HTML> <HEAD> <META http-equiv="Content-Language" content="en-us">
6
2939
by: empiresolutions | last post by:
I'm trying to slightly alter the script found here, http://www.adrianhodge.com/web-design/mootools-horizontal-div-slider-121/. What i want to do is make the carousel work on a Next/Previous feature versus a 1, 2, 3 method. I tried to do it myself but found i was was just going in circles and nothing was working. Any help is appreciated. I have listed below the only parts that should matter. Javascript <script language="Javascript"> <!--...
3
3020
by: zenzero | last post by:
I was wondering if anyone knows any Carousel script that can display photos, which one can slide in between using a slider? I.e similar to Mooflow, but I want to display only one photo at the time and don't want the zooming effect when sliding. I was hoping there might also be something like this that can also display html content? Thanks in advance!
1
2661
by: jrsjrs | last post by:
I have been trying to adapt the photo carousel script located at -- http://www.dynamicdrive.com/dynamicindex14/carousel.htm to open a new page in another frame located directly below the clickable carousel frame photos. I know that the basic script to do this is as in -- <a href="http://www.example.org/" target="bottom">Click</a> but I cannot figure out how to modify the script from
0
9184
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8931
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8892
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7767
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5878
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4386
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4635
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3064
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2359
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.