PDA

View Full Version : Target movieclip from an AS3 class file



numediaweb
November 21st, 2008, 09:13 AM
It seems a stupid question, but, believe me I searched the last 3 days on the net and guess what; thousends of tutorials but none that works for my case! :h:
what i wanna do is simple; I have 3 movie clips on the timeline, but i don't want to control them from the timeline, but, from a separate class (and also control other movieclips/textfield inside them), i have so far, an AS3 file BST_main.as that is the document class of my flash file BST_main.swf and inside my project I have 3 movie clips index_search_bar and index_criteria_bar and index_menu_bar
my class is:


package {
/*///////////////////////
Importing display class
*///////////////////////
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
/*///////////////////////
Library Movie Clips
*///////////////////////
// Initialising
addMovieFromLibrary(index_search_bar);
addMovieFromLibrary(index_criteria_bar);
addMovieFromLibrary(index_menu_bar);
index_search_bar.y = 100;

believe me I m lost :book: any help?

numediaweb
November 21st, 2008, 09:41 AM
i tried this code on my class, but errrrrrrooooorrrrssss!

package {
/*///////////////////////
Importing display class
*///////////////////////
import flash.display.MovieClip;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
/*///////////////////////
Library Movie Clips
*///////////////////////
// Initialising

public class BST_main extends MovieClip {
public static var index_search_bar_mc:MovieClip = new index_search_bar();

stage.addChild(index_search_bar_mc);
Test.index_search_bar_mc.y = 100;

}
}

senocular
November 21st, 2008, 10:14 AM
You don't have to add anything in code if they're already added to the main timeline.

Your document class BST_main will represent the class defining your main timeline instance. You can reference your timeline objects directly by their instance name there.

numediaweb
November 21st, 2008, 10:25 AM
keep getting errors;
1120 access to undefined property index_search_bar.x
1120 access to undefined property stage



package {

import flash.display.MovieClip;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;

index_search_bar.x = stage.stageWidth/2;
}

could you plesae provide some examples?
this thing reall got me crazy :hangover:

senocular
November 21st, 2008, 11:10 AM
The code you have there is incomplete.

A package {} block contains a definition, such as a class or even a funtion, though classes are the most common. Your class is BST_main and needs to be defined as a class using the class keyword (you had it before). That class then needs a constructor that is run when the class instance (your main timeline) is created. You can place your access to index_search_bar in there, or define event handlers that can change it such as click, mouseMove, etc.

You might want to read up on how classes work a little more. :)

numediaweb
November 23rd, 2008, 05:47 AM
thank you sinocular for your permanent help.

i'will try to find a great tutorial showing me how to work it out (i'm nw to AS3). the reason why i need to separate code from timeline, is because, this projec is intended for Flex and web a the same time, so i must have all the code in a separate clas file, bu seems not to be easy.
all tutorials i found gave examples on how to create a textfield dynamicly from a class but none of hem gave an example on how to conrol a movieclip that already exist on timeline!!.. even Adobe :z: