View Full Version : Flash 9 root access ( new display list structure ) inside non default packages
springframework
11-26-2006, 09:23 PM
I used to use eval() to access _root but this doesnt work anymore.
i now figured out that both...
DisplayObjectContainer(root._playlist._playlist).a ddChild(field);
or
Stage[("Stage._playlist._playlist.entry"+e+".container.label1")].textColor = 0x888888;
do the same this as eval.
the problem is that i now i create packages and classes but i dont have access to "root" or "stage" from inside these classes.
does anyone know of a good online tutorial showing how to put together packages and classes that have access to root or stage?
all DisplayObjects have a reference to 'stage', or if your using Flex you can use Application.application to get a reference to what would be the root.
springframework
11-27-2006, 12:51 AM
I am using flash 9 alpha actionscript 3.0 preview.
im looking through the actionscript 3.0 api and i cant find any class Application
for others, in the first post i wrote:
Stage[("root._playlist._playlist.entry"+count+".song")].textColor = 0xDDFFFF;
this doesnt work and u should use:
DisplayObjectContainer(root._playlist._playlist).g etChildByName("entry"+count).getChildByName("song").textColor = 0xDDFFFF;
For right now im writing everything in functions with parameters and inner functions which lets me have something similar to classes and always have access to 'root' but id like to actually have classes for O-O code style.
also this is going to lead to one huge ugly file.
im pretty confused so far with actionscript 3.0.
Does anyone know of a tutorial for flash 9 alpha (not flex) on how to create a fairly complicated program with classes.
I am using flash 9 alpha actionscript 3.0 preview.
im looking through the actionscript 3.0 api and i cant find any class ApplicationThat because, as i mentioned, Application is the base class for Flex.
but as i alos said DisplayObjects also have a reference to 'stage' once they are in a displayList.
devonair
11-27-2006, 03:15 PM
Hey, springframework,
it's difficult to help out without seeing more of how you have your ap structured (Flash forums will definitely need to evolve with AS3 - posting 1 or 2 lines of code just isn't enough to go by these days)..
It's obvious though you're trying to change the color of a playlist's textfield, so what I would suggest would be making your playlist a class and using an explicit setter method that would accept 2 arguments - the textfield to change (your "count" variable) and the color to change it to.. Here's a quick example with a couple classes.. Obviously you wouldn't want to change your playlist when you click the stage and your playlist setup would be more complex, but, you get the idea..
Main (document) class:
// document class
package {
import flash.display.Sprite;
import flash.events.*;
public class Main extends Sprite {
private var _playList:PlayList;
public function Main() {
_playList = new PlayList(5);
_playList.x = 50;
_playList.y = 50;
addChild(_playList);
stage.addEventListener(MouseEvent.MOUSE_DOWN, onDown);
}
private function onDown(me:MouseEvent):void {
_playList.setSongColor(3, 0xDDFFFF);
}
}
}
and PlayList class:
package {
import flash.text.*;
import flash.display.Sprite;
public class PlayList extends Sprite {
private var _list:Array;
private var _numSongs:int;
public function PlayList(numSongs:int) {
_numSongs = numSongs;
_list = new Array();
init();
}
// just set up some textfields for testing
private function init():void {
var fmt:TextFormat = new TextFormat ("Arial", 10, 0x000000);
for (var i:int = 0; i < _numSongs; i++) {
var songField:TextField = new TextField();
songField.selectable = false;
songField.mouseEnabled = false;
songField.defaultTextFormat = fmt;
songField.text = "Song " + (i + 1);
songField.y = i * 20;
_list.push(songField);
addChild(songField);
}
}
// setter method
public function setSongColor(index:int, color:uint):void {
_list[index].textColor = color;
}
}
}
There's a Flash 9/AS3 tutorial here: http://www.onebyonedesign.com/tutorials/as3site/tutorial/
not extremely complex, but it may help out...
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.