Class/Component Question
I am making a class that is suppose to control key board mapping. I want to use the onClipEvent(keyDown) function for and instance of this class. I can't seem to get it to work. I can use AppSimClass.porotype.onEnterFrame = function () {} but I tried this approach before and it is too sensitive to key presses. Is there any way to use an onClipEvent for a instance of a class?
FlashKit > Flash Help > Flash MX
Posted on: 09-18-2002, 09:13 AM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Creating A Component Within A Component Class
Basically I have a component with I have associated a class with - and then attached it to stage using attachMovie and make references to it using its linked name which works great. However within this class I want to attach another movie clip component - which works however how to I reference this second component from this class using linkage doesnt work neither does assigning it to variable. The only way is to call the class - which gives undesired results.
What is the proper way to have a component within a component?
Initializing A Class/Component - Am I Doing This Right?
I'm trying to build a standard Pop Up confirmation window that I can use throughout my application. I created a MovieClip Symbol in the library called PopUpBox, and then I put this actionscript on it's first frame so I can use it as a class and call methods on it like 'setLabel()'.
Right now I'm just setting a default label in the init function, but that's not showing up in the window. I'm also trying to call the setLabel method from my main movie, but that's not working either. Can somebody have a look-see and tell me what I might be doing wrong?
Code:
#initclip
function PopUpClass(){
this.init();
}
Object.registerClass("PopUpBox",PopUpClass);
PopUpClass.prototype=newMovieClip();
PopUpClass.prototype.init=function(){
this.txtLabel.text = 'wuz up mang';
}
PopUpClass.prototype.setLabel = function(lbl){
this.txtLabel.text = lbl;
}
PopUpClass.prototype.getLabel = function(){
return this.txtLabel.text;
}
#endinitclip
stop();
Thanks, Adam.
How To Get Event In Component Class?
Hello,
I want to make ActionScript 2 component. I have one movie clip (my component). Inside it I have ComboBox with instance name myMovieClip. The class associated with component is
Code:
class mypackage.MyComponent extends Object{
static var symbolName:String = "parser.Deroulateur";
static var symbolOwner:Object = parser.Deroulateur;
private var myMovieClip:MovieClip;
function MyComponent(){
}
function change():Void{
trace("change");
}
}
I want to work with event change of the ComboBox. If I put it on the ComboBOx instance like this:
Code:
on(change){
trace("change");
}
it works OK but how to get it in my class? I tried with method
Code:
function change():Void{
trace("change");
}
but it just doesn't work
Please help.
Thank you
Using Tree Component In Class
Hi,
I am trying to use a tree component in flash mx 2004.
I am able to populate a tree compoenent with XML data.
On clicking of a leaf node I am updating the contents of the leaf node in a datagrid.
Alls happening fine as long as I code it in an fla document.
The moment I convert the code into a class nothing seems to happen.
Infact the constructor of the class is also not getting called. Neither can I set an breakpoints in debugg mode.
Heres the code
--------------------------------------------------------------------------
Code:
import mx.controls.Tree;
import mx.controls.DataGrid;
class treeNav extends MovieClip {
private var listArray:Array;
private var xml:XML;
private var myTree:Tree;
public function treeNav() {
var temp = this;
listArray = new Array();
xml = new XML();
xml.ignoreWhite = true;
xml.load("contact info.xml");
xml.onLoad = function() {
temp.createTree(this);
};
trace(this);
}
private function createTree(x:XML) {
myTree.dataProvider = x.firstChild.firstChild.firstChild;
trace(x);
}
public function createdata(x:XMLNode) {
var a = new Array();
for (var i in x.attributes) {
a[i] = x.attributes[i];
}
listArray[0] = a;
}
}
I have created a tree component on stage inside a movieclip and attached the above class to the movieclip.
The problem seems to be at line number 6 "private var myTree:Tree;" where I am storing a refernce to the tree compoenent on stage by the name "myTree". The moment I comment this line the constructor is called.
Not sure what is this issue,
please help.
Component And Tween Class Help
Hi All,
I have a simple component which is dynamically added to a movieClip (‘parent_mc’) and is then made a listener of that movieClip. I’m creating 5 different component instances and each one is given a unique ‘id_number’. The component uses a tween calss function for moving to a different x position. The ‘parent_mc’ broadcasts a message (this.broadcastMessage("moveComp", compId, newX); and only the component with the matching id moves to the new position.
Everything works as expected but the problem I’m having is trying to call a function to let the 'parent_mc' know when the tween has finished. Can anyone help??
Thanks,
Ty
This is a cut down of the components script.
Attach Code
#initclip
import mx.transitions.Tween;
import mx.transitions.easing.*;
//
myCom.prototype.moveComp = function(compId, newX) {
if (compId == this.id_number) {
trace("moving component "+this.id_number);
var myTweenX = new Tween(this, "_x", Regular.easeOut, this._x, newX, 0.2, true);
myTweenX.onMotionFinished = function() {
// trace works but the id_number is undefned
trace(“move finished”+this.id_number);
// calling a ‘parent_mc’ function or a function in the component doesn’t work!!
this._parent.moveFinished(this.id_number);
this.moveFinished();
};
}
};
//
myComp.prototype.moveFinished = function() {
trace (“finish moving ”+this.id_number);
};
//
Using Tween Class In A Component
hi, I have made a list menu component and it uses transitions.Back tween when open and close. Before compiling as SWC, that is as a movieclip, the component works well but after compiling as swc and import in another document, tween functions does not work. Why can I not use this classes in a component? Here is the code :
#initclip
import mx.transitions.Tween;
import com.robertpenner.easing.*;
//---------------------------------------------------------------------------------------
//constructor
function MultiListMenuClass() {
this.isOpen = false;
this.columnNumber = -1;
}
//---------------------------------------------------------------------------------------
//inherit from the MovieClip Class
MultiListMenuClass.prototype = new MovieClip();
//---------------------------------------------------------------------------------------
//methods
MultiListMenuClass.prototype.open = function() {
openTween = new Tween(this, "_y", Back.easeOut, this._y, this._height-40, 0.5, true);
this.isOpen = true;
};
MultiListMenuClass.prototype.close = function() {
closeTween = new Tween(this, "_y", Back.easeIn, this._y, 0, 0.5, true);
this.isOpen = false;
};
Attach Component Within A Class
Hello,
i'm looking for a way to add an instance to a component from a class...
Something like
Code:
class myClass extends MovieClip{
function myClass(){
}
function addComponent(){
attachMovie(thecomponent, "compoInstance", 0, 0, 1);
}
}
but i dont know about the "thecomponent" part.. i tried "textInput" but it doesn't work.. any idea?
Help With Component And Tween Class
Hi All,
I have main movieClip which creates several instances of a library component each with a different id_number variable. The components are made listeners of the main movieClip so when it broadcasts moveComp(id_number,newX) only the matching component respond and moves to the new x location.
Everything works fine but the problem I have is trying get the tween class onMotionFinished to call a function either in the parent movieClip or a function in the component itself. What am I doing wrong? Can anyone help??
Many Thanks,
Ty
This is the relevant bit of the components script.
Code:
//---------8<-----
myCom.prototype.moveComp = function(compId, newX) {
if (compId == this.id_number) {
trace("moving component "+this.id_number);
var myTweenX = new Tween(this, "_x", Regular.easeOut, this._x, newX, 0.2, true);
myTweenX.onMotionFinished = function() {
// trace works but the id_number is undefned
trace(move finished - +this.id_number);
// calling a parent_mc function or a function in the component doesnt work!!
this._parent.moveFinished(this.id_number);
this.moveFinished();
};
}
};
//
myComp.prototype.moveFinished = function() {
trace(move finished - +this.id_number);
};
//---------8<-----
Component Add In A Class And Use Object
Hi
I m creating a common class of component which i want to use in different class .
In My project i have a color.as class in which i had create a colorPicker and added it.Now i want to use it into many class where i could access all method of colorPicker without adding colorPicker Component into all class . Can it possible
Thanks
How To Get Event In Component Class?
Hello,
I want to make ActionScript 2 component. I have one movie clip (my component). Inside it I have ComboBox with instance name myMovieClip. The class associated with component is
class mypackage.MyComponent extends Object{
static var symbolName:String = "parser.Deroulateur";
static var symbolOwner:Object = parser.Deroulateur;
private var myMovieClip:MovieClip;
function MyComponent(){
}
function change():Void{
trace("change");
}
}
I want to work with event change of the ComboBox. If I put it on the ComboBOx instance like this:
on(change){
trace("change");
}
it works OK but how to get it in my class? I tried with method
function change():Void{
trace("change");
}
but it just doesn't work
Please help.
Thank you
Component Instance Name In A Class?
I am a longtime user of a very useful tool http://www.slideshowpro.net a slideshow component that has a really great API.
To use it you need to drag the component to the stage and give it an instance name in the properties pane, I'm using my_ssp. I have always coded this stuff on the first frame of the time line, such as setting the position of a TextField in relation to the component instance on the stage.
Code:
_galleryTextField.x = my_ssp.x;
_galleryTextField.y = my_ssp.y - (_galleryTextField.textHeight * 2) ;
So I had the need to create a class that will create the TextField "_galleryTextField" so I can access it as a public var in other places of my project. Here's the problem, now that I need to access the my_ssp instance name inside of this new class, It becomes an undefined property. I have imported the appropriate package, but trying to figure out how to tell this class what my_ssp is? Normally I set the Linkage in the library to make it available, like with a MovieClip, but this is a component and I can't do that in the Library. I'm thinking I need to declare it as a public var in the document class, but then I'm not sure what to set the type to? Can I make a component's instance name available to a class or am I going about this completely wrong?
I hope this makes some sense, thanks for any help.
AS 2.0 AttachMovie In Component Class Function
I am trying to attach a movie dynamically to the stage and reference its variables from a response from a php script. This method works fine in regular timeline coding, but when it is in a component class, it wont attach the movies dynamically when the component loads up. Please help.
code:
import mx.core.*;
import mx.containers.*;
import mx.controls.*;
import mx.transitions.easing.*;
//Associate custom component image
[IconFile("Menu.png")]
//declare the class and identify the parent class
dynamic class mx.controls.Menu.phpMenu extends mx.core.UIComponent{
//identify the symbol name that this class is bound to
static var symbolName:String = "phpMenu";
//identify the fully qualified package name of the symbol owner
static var symbolOwner:Object = Object(mx.controls.Menu.phpMenu);
//provide the className variable
var className:String = "phpMenu";
//Declare all movieclips and properties going to be used in component
private var mainCategoryLoader:LoadVars;
private var subCategoryLoader:LoadVars;
private var mcHolder:MovieClip;
private var backGround:MovieClip;
private var scroller:ScrollPane;
private var scrollPaneContent:MovieClip;
private var subCategory:String;
private var i:Number;
private var nexty:Number;
private var randInt:Number;
private var _rootURL:String;
private var _fileName:String;
public var statusBox:String;
public var headerBox:TextField;
//constructor
function phpMenu(){}
//Create children
private function createChildren():Void{
}
//define init method for this component, and initialize super class
public function init(Void):Void {
super.init();
randInt = int(Math.random() * 123456789);
loadMainCategories(_rootURL, _fileName, randInt);
}
//Draw
private function draw():Void{
super.draw();
this.scroller.contentPath = "scrollPaneContent";
}
//Introduce property inspector parameters
[Inspectable(defaultValue="menuLoad.php")]
public function set fileName(theFile:String){
if(theFile == ""){
trace("Please fill in a file name");
}else{
_fileName = theFile;
trace("file name is " + _fileName);
}
}
[Inspectable(defaultValue="http://")]
public function set rootURL(theRoot:String){
if(theRoot == "http://"){
trace("Please fill in a root directory.");
}else{
_rootURL = theRoot;
trace("root URL is " + _rootURL);
}
}
//declare main menu load function
public function loadMainCategories(u,f,r):Void{
mainCategoryLoader = new LoadVars();
mainCategoryLoader.handler = this;
mainCategoryLoader.sendAndLoad(u + f + "?" + r, mainCategoryLoader, "POST");
mainCategoryLoader.onLoad = function(success){
if(this.status = "ok"){
trace("loaded successfully");
trace("url is " + u + f + "?" + r);
nexty = 0;
trace("nexty is set to " + nexty);
this.headerBox.text = this.header;
for(i=0;i<this.mainCategoryCount;i++){
trace("i = " + i);
trace("header = " + this.header);
trace(this["mcHolder" + i]);
trace("nexty is set to " + nexty);
scroller.content.attachMovie("mcHolder", "mcHolder" + i, getNextHighestDepth());
//scroller.content["mcHolder"+i].subCategory.text = this["mainCategory" + i];
setProperty(scroller.content["mcHolder"+i],_y,nexty);
scroller.invalidate();
trace(scroller.content["mcHolder"+i]._height);
}
}else if(mainCategoryLoader.status = "error"){
trace("Sorry, loaded unsuccessfully");
statusBox = mainCategoryLoader.error;
}else{
trace("No response from Database");
statusBox = "Loading Menu...";
}
}
}
}
Using Component Inside Custom Class
Hi,
I'm creating a registration form that contains a ComboBox component.
This component works as expected on its own:
code:
import mx.controls.ComboBox;
for (var i = 1930; i <= 1990; i++)
{
year_cb.addItem({data:i, label:i});
}
var year_cbListener:Object = new Object();
year_cbListener.change = function(evt_obj:Object)
{
var item_obj:Object = year_cb.selectedItem;
trace(item_obj.data);
};
year_cb.addEventListener("change", year_cbListener);
But when I try to use it inside my custom class (wich will handle all the data of the registration), it simply doesn't work. The ComboBox doesn't even get populated:
code:
import mx.controls.ComboBox;
//
class Registration extends MovieClip
{
private var year_cb : ComboBox;
private var year_cbListener : Object
//
public function Registration ()
{
myInit ();
}
//
private function myInit ()
{
trace (year_cb); // works
for (var i = 1930; i <= 1990; i ++)
{
year_cb.addItem (
{
data : i, label : i
});
}
year_cbListener = new Object ();
year_cbListener.change = function (evt_obj : Object)
{
var item_obj : Object = year_cb.selectedItem;
trace (item_obj.data);
};
year_cb.addEventListener ("change", year_cbListener);
}
}
Here are the files (combobox working alone, and the class files).
Any ideas?
Thanks.
Getter/Setter Within A Class With A Component
I have a class file which loads comboboxes on the stage. In the interaction various things happen which need to be recorded, and I had done this in the past by setting properties on movie clips. I.E. -
mc1.propertyName = true/false;
I try to do that with a component and get a message saying that the property can't be created on fl.controls.ComboBox.
The property name is: isRed. It's being set like this:
combo1.isRed = true/false;
Here's the getter/setter:
public function get isRed():Boolean {
return _isRed;
}
public function set isRed(value:Boolean):void {
_isRed = value;
}
Also tried this:
[Inspectable(defaultValue=false)]
public function get isRed():Boolean {
return _isRed;
}
public function set isRed(value:Boolean):void {
_isRed = value;
}
Any ideas? Thanks.
Instantiating MXML Component Within AS3 Class
I have a MXML component that is pretty much this:
MXML Component name is "TestPlan.mxml"
Code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300">
</mx:Canvas>
inside my AS3 I do this
pt:TestPlan = new TestPlan()
hbox.addChild(pt);
I get a TypeError #1009.
Can anyone help?
Accessing A Class Inside Of A Component
I would like to give the users of a component, that I am making, access to some of the classes being used inside of the component.
Is there a way to do this without distributing the source of this class?
Thanks.
How To Add Parameters To Component W/class Path
Hi, I'm new to Flash 9 and I don't know how to add parameters to a Flash 9 component I create via the Component Definition dialog box if my component uses a class file.
The second I enter a class path for the component, it wipes out any created variables. I'm trying to create a simple label component that's not based on the fl.core.UIComponent class. I just want to see what's the simplest component I can create.
All I want the component to do is display a colored background with a text field on top whose value I can change from the inspector. It doesn't need to resize, change state or anything. I figured I could do this without the overhead of the UIComponent, more as a learning exercise, but I've had no luck and would appreciate any help.
I assume if I were basing this on UIComponent, I could take advantage of the Inspectable metadata structure, but I suspect I don't have that route.
Thanks,
Jennifer
Oop As2 - Component - Problem With Referring Class To Itself
hello, im currently creating a component which calls on an xml file. i want a function from the class to be called once the xml is loaded, but i cant seem to target the function.
Code:
class className {
// variable
var inputXML:XML;
// constructor
public function className () {
this.init ();
}
// initialization
private function init () {
this.inputXML = new XML ();
this.inputXML.ignoreWhite = true;
this.inputXML.load ("xmlfile.xml");
this.inputXML.onLoad = function (success) {
if (success){
this._parent.setContent (this);
}
}
}
// functions
private function setContent (xml:XML) {
trace (xml);
}
}
logic suggests that since inputXML belongs to the class, it's parent should be the class. however, with the onload, it seems that it cannot reach its parent. i even tried without relating to the class (setContent (this) instead of this._parent.setContent (this)) and still doesnt work
what should i look for?
Targetting Problem In Class (Component)
So here we go. I'm kind of a stuck on creating AS2 component. Its my first one and I think thats probaply the reason im stuck in this stubid situation.
So lets move to the point. I have created Mouse listener which is working fine, only thing I just cant understand is how can I target to something inside of the listener when event is launched from it.
Heres a small example:
Code:
Class ..... extends MovieClip {
var changeMe:Number;
var theListener:Object = new Object();
function constructor(){
createMouseEvents();
}
function createMouseEvents() {
Mouse.addListener(theListener);
theListener.onRelease = function(){
// Here comes the problem
// For example im trying to give "changeMe" variable a new value
// but i cant target it.
changeMe = 10; // no luck
this._parent.changeMe = 10; // no luck
trace(this); // Equals to: [object Object] thats correct
trace(_parent); // Equals to: undefined
trace(this._parent) // Equals to: undefined
}
}
} // class ends
I hope I just havent missed anything cause im getting tired with this. I dont know are there other threads about this cause I cant get in my mind any search words for this.
Thanks in advance. Ill hope heres some AS hero (I know heres many).
And btw. love your tutorials. User them alot when I started with Flash and AS.
AS2 Class And Component Loading Problem
Hi all,
I'm testing this movie in flash 8. Here's how it's set up.
*I have a one frame preloader that works in the first frame.
*I'm exporting my AS2 classes to the second frame.
*I have all my components thrown inside a movieclip on the 11th frame so I don't have to export them to the first frame.
When I test the movie for high bandwidth, It goes to the frame that it's supposed to go, it connects to my remoting gateway, but the components don't show up. However, if I test the movie for 56k, the components show up, but it won't connect to my remoting gateway.
I've attached the zipped fla for your viewing enjoyment.
I've spent about 3 days on this problem, so any help will likely make me weep with joy.
Any Ideas?
Dynamically Attaching A Component To Another Components Class
Basically I have a component and a class - in it I want to attach another custom component within it
my classes extend UIObject and have set size, init draw and createchildren in
And in the createchildren method I do this
this inst = createClassObject(myClass, "MyNewComponent", this.getNextHighestDepth());
I only works if second component is a compiled clip.
However repeatingly goes into second components constructor method
Has anyone had experience of attaching a user created component within a component???
Class Files And List Component Variables...
Hey everyone!
Has any of you came across the error:
The class 'List' could not be loaded.
var fileList:List;
I've got a class file and this is just a variable declared at the top as I'm wanting to make the list component named "fileList" accessible and need to declare it.
A solution would be greatly appreciated cos this is for a final year uni assignment due in next week
unless someone wants to send me a media player that has video, audio and images using class files and gets data from xml
Sounds simple but I've got 5 other assignments...
Thanks!!
Dan
Problem On Accessing A Component Class Methods
Hello. I'm developing a component which incorporates standart Button and TextInput components. To handle those components events, for example "click" or "change" event, i'm creating an object in main class, and creating functions attached to that object. When coding in this object scope, "this" statement for main class becoming unaccessible and pointing to current object context. Is there a way to access class dynamic methods or variables from sub-object context? Example:
class something extends UIComponent {
...
private var btnOk:Button;
private var btnOkEvent:Object;
public function something() {
...
}
public function init() {
btnOkEvent.click = function(objEv) {
//In this context "this" statement does not point to
//something class. I mean i couldn't call beginDraw()
//method from here.
//(I know, if beginDraw method begins with static
//keyword, i can call it like something.beginDraw() )
}
btnOk = Create("Button"); //Sample
btnOk.addEventListener(btnOkEvent);
}
private function beginDraw() {
...
}
/*
I know, i can use class it self with event-name functions to handle
other components events but there must be an another way.
public function init() {
...
btnOk.addEventListener(this);
}
private function click(objEv) {
...
}
*/
}
This is a general question/problem for me. Perhaps it has a very simple answer, but i don't know. Is there a way? If so, how? Please help!
MediaPlayback Component Problems When Using NetStream Class
I am using the mediaPlayback component to play external .flv files. First problem I had was that they were stopping intermittently when loaded to the server.. so I read up on the netStream class and attached this basic code...
var netConn:NetConnection = new NetConnection();
netConn.connect(null);
var netStream:NetStream = new NetStream(netConn);
//my_video is the name of the component instance on the stage
my_video.attachVideo(netStream);
netStream.setBufferTime(20);
netStream.play("introDemo.flv");
Now.. the audio plays but no video plays and the controls on the component do not work now... ie.. can't pause it. or adjust the volume.
MXML Component As Actionscript Class Property
I am trying to create a custom actionscript component that has an HTTPService property that I define in MXML and pass to the "service" property of a DatabaseNavigator component. However I keep getting null object errors. Here is my code:
index.mxml
Code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:db="database.containers.*" layout="absolute" width="700" height="700">
<mx:Style source="assetscss
scsadmin.css"></mx:Style>
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.IndexChangedEvent;
import database.containers.DatabaseNavigator;
]]>
</mx:Script>
<mx:Fade id="fader" duration="1000" alphaFrom="1.0" alphaTo="0.0"/>
<mx:HTTPService id="databaseService" resultFormat="xml" method="POST" />
<db:DatabaseNavigator service="{databaseService}" host="localhost"/>
</mx:Application>
DatabaseNavigator.as
Code:
package database.containers
{
import mx.containers.TabNavigator;
import mx.controls.Alert;
import mx.events.FlexEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.http.mxml.HTTPService;
public class DatabaseNavigator extends TabNavigator
{
private var _host:String;
private var _username:String;
private var _password:String;
private var _database:String;
private var _service:HTTPService;
private var metaData:XMLList;
private var params:Object;
public function DatabaseNavigator()
{
super();
params = new Object();
addEventListener(FlexEvent.INITIALIZE, superInitHandler);
}
public function get host():String {
return _host;
}
public function set host(value:String):void {
_host = value;
}
public function get username():String {
return _username;
}
public function set username(value:String):void {
_username = value;
}
public function get password():String {
return _password;
}
public function set password(value:String):void {
_password = value;
}
public function get database():String {
return _database;
}
public function set database(value:String):void {
_database = value;
}
public function get service():HTTPService {
return _service;
}
public function set service(value:HTTPService):void {
_service = value;
}
private function superInitHandler(event:FlexEvent):void {
params.host = host;
params.username = username;
params.password = password;
params.database = database;
try {
if(!service) {
throw(new Error("Error: Databse service not specified"));
} else {
service.addEventListener(ResultEvent.RESULT, serviceResultHandler);
service.send(params);
}
} catch (error:Error) {
Alert.show(error.message);
}
}
private function serviceResultHandler(event:ResultEvent):void {
Alert.show(event.result.toString());
}
}
}
Flex Actionscript Class & MXML Component
Hi all,
I was using AS3 projects in Flex for a year and started playing with Flex recently.
I am not infront of a Dec PC but i was wondering if someone can confirm this correct?
If i make an actionscript class called MyClass.
class MyClass
{
public var justaproperty:int = 0;
public function MyClass()
{
trace("a new class was created");
}
}
Does that mean that i can automatically use a flex component like this or is there more to it?
<local:MyClass id="myClass" justaproperty="15" />
Thanks.
MediaPlayback Component Problems When Using NetStream Class
I am using the mediaPlayback component to play external .flv files. First problem I had was that they were stopping intermittently when loaded to the server.. so I read up on the netStream class and attached this basic code...
var netConn:NetConnection = new NetConnection();
netConn.connect(null);
var netStream:NetStream = new NetStream(netConn);
//my_video is the name of the component instance on the stage
my_video.attachVideo(netStream);
netStream.setBufferTime(20);
netStream.play("introDemo.flv");
Now.. the audio plays but no video plays and the controls on the component do not work now... ie.. can't pause it. or adjust the volume.
Including Own Class Kills Button Component
Hi Guys,
I hope you can help me out here, since i have few hairs on my head left. It's driving me crazy.
I have a simple stage with 3 components on it, a combobox, a textfield and a button. (all v2).
on the button i say :
Code:
on(click) {
trace("A");
}
If i export, everything goes ok, if i click the button, it traces A.
But here it comes, if i use a custom created class inside this swf, the button stops sending the trace command!! In other words, the click event is not being called .
The code in my class which creates this error is :
Code:
mx.events.EventDispatcher.initialise(this);
Commenting this lin in my class makes my button work ok again.
Anybody know of a solution? And if there are other things i should know when using components with a custom preloader? (swf containing comp is loaded inside other swf -> this is btw not the case in above error)
tnx in advance!
Mx.data.components - Unable To Declare Data Component Types In External Class Files
Hi all,
FlashMX 2004, v7.2:
I am trying to declare instances of data-components (DataSet and DataHolder) in external classfiles, but Flash can't find the sourcefiles for any of the data component classes in the classpath.
According to the help-files, the classname for the DataHolder component is:
Code:
mx.data.components.DataHolder
Similarly, the classname for the ComboBox component is:
mx.controls.ComboBox
Code:
mx.data.components.DataHolder
In the following, the ComboBox gets declared, and the DataHolder generates a "Class can't be loaded" error:
Code:
class my_class extends MovieClip {
var my_cbox:mx.controls.ComboBox;
var my_data:mx.data.components.DataHolder;
function my_class() {
// constructor function
}
}
Sure, it fails because there is no "components" folder in the mx.data folder (at least on my system), and I have been unable to find any DataHolder.as file anywhere either, even though the documentation gives examples that reference the mx.data.components-folder for various data components. I even tried re-installing to make sure I had not accidentally deleted any classfiles, but still no luck.
Am I missing something really obvious here? Does anyone know how to successfully import, declare or otherwise make use of data-components in external class files? Any help greatly appreciated.
Class Question: How To Access Timeline Objects From Class W/o Arguments
Hey all,
I am looking into builiding an application with OO functionality. I understand most of it. Except I cannot figure out how to access something in my app from a class. For instance, lets say I have one Loader class that loads some data and stores it in a variable inside the class (or on the main timeline, doesn't matter). Now, I know I can pass a reference to the data in an argument to another class for that class to manipulate. But if I have several data sources, and other variables and such, that I need to modify in a single class function, how would I do that without having to give the function access to them through arguments? I just want to be able to say, from a class, something like _root.someObject.someFunction();
So, any help would be greatly appreciated, and sorry if that made no sense at all, I tried to explain as best I could.
Happy Holidays!
Dave
[Flash 8] Referencing Class Variables From OnEnterFrame Created Within Class
Hi,
It's been a while since my last post here, but I was hoping someone could help me with a problem I'm having. I want to reference and change a class variable from within an onEnterframe function defined within a class. I can actually do this right now, but I want to do it in a different way. Here's a code sample of what I am talking about:
Test.fla file:
Code:
var t:tester = new tester()
Working tester.as file:
Code:
class tester{
private var num:Number = 100;
function tester(){
var classObj:tester = this;
var mc:MovieClip = _root.createEmptyMovieClip("test",1);
mc.onEnterFrame = function(){
trace(classObj.num); //This traces 100 (CORRECT!!!)
}
}
}
This traces 100 to the output window, just like it should
Here is the way that I would like to do it, because I want to reuse my onEnterFrame Stuff:
Code:
class tester{
private var num:Number = 100;
function tester(){
var classObj:tester = this;
var mc:MovieClip = _root.createEmptyMovieClip("test",1);
mc.onEnterFrame = this.mcOnEnterFrame;
}
private function mcOnEnterFrame(){
trace(num) //this traces undefined (BAD!!!)
}
}
As you can see, the work around to reading the class variable in the onEnterFrame function is to create a reference to the class object, before defining that function, then using the reference you created to access the class variables.
I have tried various iterations to get the second example working, but have had no luck. Does anyone know a way to get the second method working, or am I stuck using the first method.
AS3 Project In FDT + Flex SDK. Root Class Extends Visual Class From Swc
hello
question about compiling as3 project under FDT 3.0 with Flex SDK.
I want my main root class to contain some graphics already at the start. In Flash IDE I put some objects on the stage, make new symbol with all those objects inside, set linkage to MainClassGraphics, export it to swc, add this swc to source folder class-path. Then I write my root class:
Code:
package {
public class MainClass extends MainClassGraphics {
public function MainClass() {
trace('hey');
}
}
}
compiling with flex2 sdk - and I don't see any graphics. why?
if i try this way:
Code:
package {
import flash.display.Sprite;
public class MainClass extends Sprite {
public function MainClass() {
var s:Sprite = new MainClassGraphics();
addChild(s);
trace('hey');
}
}
}
then I see my graphics.. so swc looks like fine
crosspost here http://fdt.powerflasher.com/forum/vi...hp?f=21&t=2268
Accessing A Dynamic Text Field In A Class Other Than The Primary Class
I have tried to read and understand some of the other threads for this issue but, I think it would be easier to understand if I show my specific issue. I left some code out to make my issue more clear.
Alpha is the primary class with access to the stage. If I write the event listener and function contained in the Bravo function into the Alpha function it works. Although, I want it to be in a different class in the same package (such as the Bravo class).
I have created a instance of a class which is a physical object on the stage (lets say it's a card). The event listener is in the instance so that each instance has a self contained listener.
The bottom line is it works in the primary class but in no others. How can I make it access the text field (so when I click on the "card" the text field shows "something"?
ActionScript Code:
package a {
public class Alpha {
public function Alpha() {
x:Bravo = new Bravo();
}
}
}
package a {
public class Bravo {
public function Bravo() {
this.addEventListener(MouseEvent:CLICK, clickEvt);
function clickEvt(event:MouseEvent) {
<MovieClip>.<MovieClip>.<DynamicTextField>.text = "something";
}
}
}
}
Calling SetTimeout Within Custom Class And Cannot Access The Class' Variables
Hi All,
I'm creating an user interface with Flash 8, I'm new to Flash, my background is Java therefore I decided to use ActionScript to create a custom component that is reference within an external file.
My problem I believe is scope related. I have a status bar (label component), once I update the status bar I want to call the
"setTimeout" function to wait a couple of seconds before clearing my status bar. The "setTimeout" function is executing, but for some reason my status bar is not being cleared (accessed).
Below is a snippet of my code. Any help appreciated. Thanks.
/*
External File
*/
import mx.controls.Button;
import mx.controls.Label;
class MyApp
{
//private properties
private var mc_container:MovieClip;
private var btn:Button;
private var lbl_status:Label;
private var str:String = "do see me";
//constructor
public function MyApp(target:MovieClip)
{
trace("-- MyApp --");
mc_container = target.createEmptyMovieClip("mc_container", 100);
}
//public methods
public function init(width:Number, height: Number, xPos:Number, yPos:Number):Void
{
var my_app:MyApp = this;
btn = mc_container.createClassObject(Button, "btn", 1, {label:"click me"});
btn.setSize(100, 25);
btn.move(10, 10);
btn.clickHandler = function():Void
{
trace("btn clicked");
setTimeout(my_app.clearStatus, 2400);
//correct if I call directly
//my_app.clearStatus();
trace(str);
}
lbl_status = mc_container.createClassObject(Label, "lbl_status", 2, {text:"status bar message"});
lbl_status.setSize(200, 25);
lbl_status.move(0, 50);
}
public function clearStatus():Void
{
trace("calling clearStatus");
lbl_status.text = "";
}
}
/*
Called for Flash IDE
*/
var app:MyApp = new MyApp(this);
app.init(200, 200, 0, 0);
ActionScript 2.0 Class Scripts May Only Define Class Or Interface Constructs.
This is driving me nuts. I have an old AS1 project which I upgraded to AS2. It uses an include file, settings.as, which has stuff like this:
settings = new Object();
settings.property = 'some value';
Then I include it on the main timeline like this:
#include "settings.as"
Every time I render, I get a million and one Compile Errors stating:
"ActionScript 2.0 class scripts may only define class or interface constructs."
But it isn't an ActionScript 2.0 class! It's just a regular include. How do I avoid the bogus Compile Errors?
AddChild Works With Document Class, But Not Timeline-instantiated Class
I cannot get a sprite to display for me when I create an instance of a very simple class in my FLA file's timeline.
However, when I make the class file the FLA's document class file, it displays just fine.
The task in question is simply drawing a square with the shape class.
Problem example:
My class, Test.as, resides in the same folder as my FLA file - so I don't use any import statement. I'm new to lots of CS3 stuff. Can anyone tell me why this doesn't work and create the shape on the stage? This seems to fail silently without any errors:
var myTest:Test = new Test();
Working example:
Setting the document class to Test.
Attach Code
// Test class
package {
import flash.display.*;
public class Test extends Sprite {
public function Test():void{
doThing();
}
private function doThing():void{
var myRect:Shape = new Shape();
myRect.graphics.lineStyle (2, 0xcc0000, 1);
myRect.graphics.beginFill(0xcccccc, 1);
myRect.graphics.drawRect(10, 10, 200, 200);
addChild(myRect);
}
}
}
[AS3] Making An Auto-generated Class Inherit From Custom Class?
hi, just wondering if this is possible
i was hoping to find a way to get a bunch of objects in my library to inherit from (or even be) one class that i have made, but without having to make .as files for every single one
is this possible, or is there any other way to give objects another classes functionality in an auto-generated class?
cheers
Tough One: Accessing Class Methodes From Other Class Files
Tough question for the experts...
In my classfile class Classes.tools.depthManager, I've got a static methode
Code:
public static function getLoopDepth():Number {
In another classfile Classes.tools.frameRateViewer, I want to access that methode
Code:
var tempDepth = Classes.tools.depthManager.getLoopDepth();
The compiler claims: "There is no class or package with the name 'Classes.tools.depthManager' found in package 'Classes.tools'."
So I tried writing import Classes.tools.* at the top of my Classes.tools.frameRateViewer.as, hoping I could just write
Code:
var tempDepth =depthManager.getLoopDepth();
But there the compiler claims: "The class being compiled, 'Classes.tools.depthManager', does not match the class that was imported, 'depthManager'."
I'm sure the Classes.tools.depthManager.as works fine: I can call the static depthManager.getLoopDepth() from a button in the fla file...
Any ideas? Thanks!
Button Created Within Class Cannot Access Class Properties
Hi,
I'm using the following code within a class:
code:
_head_mc.attachMovie("headButton", "head_btn", this.getNextHighestDepth());
_head_mc.head_btn.onRelease = function () {
containingClip_mc._parent._parent.clickedHead(_per sonName);
}
The button gets attached (line 1). This works because I can see the mouse changing to a finger.
The onRelease function is declared and works. I know because if I put a trace in there, it works.
The function it calls (containingClip_mc._parent._parent.clickedHead also works, becuase I can see traces from within it.
But the _personName variable is passed as undefined.
I know that this variable has a value, because I can trace it outside the function, but it seems that this onRelease function is not able to see the variable. It's declared as private, but setting it to public doesn't fix anything.
I imagine there's something I don't understand about the scoping of variables. I've tried _parent references, but that doesn't appear to help either. Is there a better way to do this or a workaround?
Barrette
Added by edit
Okay, I've pretty much determined this is a scoping issue. From the onRelease function, I'm unable to access ANY of the functions within my class. I still would like advice on how to do so..
Barrette
**Error** ActionScript 2.0 Class Scripts May Only Define Class........
**Error** ActionScript 2.0 class scripts may only define class or interface constructs.
b2.onPress = function() {
**Error** ActionScript 2.0 class scripts may only define class or interface constructs.
b3.onPress = function() {
**Error** ActionScript 2.0 class scripts may only define class or interface constructs.
b4.onPress = function() {
ok this is what i have.
1 Movie clip with links to a .as file all is working fine the above error occurs when i publish the 1 movie clip which is getting pulled into the main movie
Any idea's it does not happen when 1 movie clip is published on its own just when 1 move clip is pulled into my main movie clip.
[F8] Referencing A Static Class Inside Another Class's Instance
I've got a movie loading into a framework.
This framework has 1 instance of the class main called main.
Inside this class, another class is used, but it is used directly, not as an instance. E.g.:
code:
import com.StaticClass;
class main {
private function UseStaticClass():void {
StaticClass.init();
}
}
From my movie, I can reference the main instance as _root.main. Can I reference StaticClass at all if there's no explicit instance created or it's not assigned to a public variable?
I can't modify main to include getter/setter methods, that's why I ask.
Thanks.
Child Class Trigger Event For Parent Class
is there a way for a parent class to listen to a variable in a subclass, and when it changes, run a function?
This seems like a pretty simple thing to do. I'm trying to keep my subclass independent of my main class, so i just have a variable that is set to false, and when its finished, it sets the variable to true.
The only thing i can think of is having an onEnterFrame that keeps checking the variable...but it seems like an event would be more efficient.
thanks!
Tween Class Applied In Custom Class Not Working
var sizerW:Object = new Tween(pda_mc,"_xscale",mx.transitions.Tween.None.e aseNone,pdaOrigW,pdaSmallW,3,true);
this code produces and error when applied in a custom class but not in a fla?
the error = There is no property with the name 'None'.
Custom Transitionmanager Class Problem/class Scope?
I'm writing a class that fades from one scene to another in a video game. A custom transitionManager object is created, and a listener is attached. Once the fade out from one scene is complete, the listener is triggered, the scene switches, and the new scene fades in.
This is the error I'm getting: "There is no method with the name 'myTransitionManager'.
myTransitionManager.addEventListener("allTransitio nsOutDone", fadeListener);". It is given everytime myTransitionManager is accessed by any of the class functions.
I assume this is a class scope issue. How can I create a custom transitionManager object accessable to the entire class? I need it to be accessed by at least three separate class functions.
Here's the source, starting with the constructor for the GameSection class:
Code:
public function GameSection(clip_to_fade:MovieClip){
var myTransitionManager:TransitionManager = new TransitionManager();
}
//class methods
function switch_section(clip_to_fade:MovieClip, fade_in_scene:String) {
// Define a listener object to use with the Tween objects.
var fadeListener:Object = new Object();
//create event listener for transitions being complete
fadeListener.allTransitionsOutDone = function(eventObj:Object) {
trace("allTransitionsOutDone event occurred.");
gotoAndPlay(fade_in_scene);
fadeIn(clip_to_fade);
};
myTransitionManager.addEventListener("allTransitionsOutDone", fadeListener);
fadeOut(clip_to_fade);
}
function fadeIn(in_mc:MovieClip) {
myTransitionManager.start(in_mc, {type:Fade, direction:Transition.IN, duration:1, easing:None.easeNone});
}
function fadeOut(out_mc:MovieClip) {
myTransitionManager.start(out_mc, {type:Fade, direction:Transition.OUT, duration:1, easing:None.easeNone});
}
Thanks!
Static Class Variable Referencing Class Instance
I was given the task of writing a class that would send serial requests for xml data, the idea being that the requests could be added while previous requests were still in progress, but the class would queue them and wait for the reply of one request to come back before sending the next.
The way I did this was to create a class instance for each request, and the request itself would be stored in an instance variable, waiting to be sent. A static variable called queue (accessible to all instances) was then given a reference to the instance, and when this reference got to the top of the queue, queue would call the sendRequest() method on that instance.
The reason why I am using one instance per request is so that the replies can be retrieved via the instance, so keeping each request entirely discreet.
Everything works very nicely, but the problem is my IT manager looked at the code and told me that you cannot put a reference to a class instance in a class static variable... and for this reason he has informed my line manager that he has serious reservations about the code, and recommends that it is not incorporated it into the project. However, the code works very well on my local machine and on the testsite, and no-one has experienced any problems with it.
Can someone reassure me here... I can see absolutely nothing wrong with having a class static array hold references to each of the instantiated class instances. And the proof is in the pudding.. it works. Can anyone else see a problem here?
Why Is An Event On One Class Object Being Broadcast For All Instances Of That Class?
I have a custom class called McText which extends MovieClip, and includes an input text field. That class has a function to register itself as a listener to Key - Key.addListener(this). It does not register by default.
There are multiple instances of McText. But even though I only call the function to register on one of those instances, ALL of them fire an onKeyDown function when i type into their text field, regardless of whether i've registered that particular object to Key or not. I register one, I register them all.
This is a little annoying because I use this class everywhere, and I want to be able to assign an onKeyDown function for only one of them. At first i tried writing that function outside of the class itself, as in:
classObject.onKeyDown = function()
But that, perhaps unsurprisingly, created an onKeyDown function for every instance again.
I thought to myself "I know, I'll register McText with Key by default (in the constructor), write an McText.onKeyDown function in the class itself, and then get that function to use a broadcaster". The idea being that onKeyDown will fire on all of them, but the broadcaster will be registered to a specific listener on an object by object basis.
So I did that, and created a function to register a broadcaster listener. I then created a broadcaster listener in a seperate, different, class, throw it to the McText function so it registers with its broadcaster and guess what? Now that listener receives an event from every instance of that class.
There's no explicit use of static vars or functions anywhere.
Sorry for the long question, but can anyone enlighten me as to what's going on? You get virtual chocolate if you do
|