I have an array list which is connected with a private static function and would like to make another array list on a different view (Flex builder, Action script) so I copied the private static function edited the name and the "Select" parts but I get an error saying:
"1061: call to a possibly undefined method members through a reference with static type class."
Here is the code of the AS:
package model
{
import flash.data.SQLConnection;
import flash.data.SQLResult;
import flash.data.SQLStatement;
import flash.events.SQLEvent;
import flash.filesystem.File;
import flash.filesystem.FileMode;
import flash.filesystem.FileStream;
import model.Dish;
import mx.collections.ArrayCollection;
public class SQLiteDatabase
{
private static var _sqlConnection:SQLConnection;
public static function get sqlConnection():SQLConnection
{
if (_sqlConnection)
return _sqlConnection;
openDatabase(File.desktopDirectory.resolvePath("test.db"));
return _sqlConnection;
}
public function getNote(id:int):Dish
{
var sql:String = "SELECT id, title, time, message FROM notes WHERE id=?";
var stmt:SQLStatement = new SQLStatement();
stmt.sqlConnection = sqlConnection;
stmt.text = sql;
stmt.parameters[0] = id;
stmt.execute();
var result:Array = stmt.getResult().data;
if (result && result.length == 1)
return processRow(result[0]);
else
return null;
}
public function getmember(id:int):Dish
{
var sql:String = "SELECT id, title, time, message FROM notes WHERE id=?";
var stmt:SQLStatement = new SQLStatement();
stmt.sqlConnection = sqlConnection;
stmt.text = sql;
stmt.parameters[0] = id;
stmt.execute();
var result:Array = stmt.getResult().data;
if (result && result.length == 1)
return processRow(result[0]);
else
return null;
}
public function getMYBlist(id:int):Dish
{
var sql:String = "SELECT id, title, time, message FROM notes WHERE id=?";
var stmt:SQLStatement = new SQLStatement();
stmt.sqlConnection = sqlConnection;
stmt.text = sql;
stmt.parameters[0] = id;
stmt.execute();
var result:Array = stmt.getResult().data;
if (result && result.length == 1)
return processRow(result[0]);
else
return null;
}
public static function notes():ArrayCollection
{
var noteList:ArrayCollection = new ArrayCollection();
var sql:String = "SELECT id, title, time, message FROM notes";
var stmt:SQLStatement = new SQLStatement();
stmt.sqlConnection = sqlConnection;
stmt.text = sql;
stmt.execute();
var sqlResult:SQLResult = stmt.getResult();
if (sqlResult) {
var result:Array = sqlResult.data;
if (result) {
for (var index:Number = 0; index < result.length; index++) {
noteList.addItem(processRow(result[index]));
}
}
}
return noteList;
}
public static function members():ArrayCollection
{
var memberslist:ArrayCollection = new ArrayCollection();
var sql:String = "SELECT id, name FROM members";
var stmt:SQLStatement = new SQLStatement();
stmt.sqlConnection = sqlConnection;
stmt.text = sql;
stmt.execute();
var sqlResult:SQLResult = stmt.getResult();
if (sqlResult) {
var result:Array = sqlResult.data;
if (result) {
for (var index:Number = 0; index < result.length; index++) {
memberslist.addItem(processRow(result[index]));
}
}
}
return memberslist;
}
public static function addNote(note:Dish):void
{
var sql:String =
"INSERT INTO notes (title, time, message) " +
"VALUES (?,?,?)";
var stmt:SQLStatement = new SQLStatement();
stmt.sqlConnection = sqlConnection;
stmt.text = sql;
stmt.parameters[0] = note.title;
stmt.parameters[1] = note.time;
stmt.parameters[2] = note.message;
stmt.execute();
}
public static function addMember(note:Dish):void
{
var sql:String =
"INSERT INTO notes (title, time, message) " +
"VALUES (?,?,?)";
var stmt:SQLStatement = new SQLStatement();
stmt.sqlConnection = sqlConnection;
stmt.text = sql;
stmt.parameters[0] = note.title;
stmt.parameters[1] = note.time;
stmt.parameters[2] = note.message;
stmt.execute();
}
public static function deleteNote(note:Dish):void
{
var sql:String = "DELETE FROM notes WHERE id=?";
var stmt:SQLStatement = new SQLStatement();
stmt.sqlConnection = sqlConnection;
stmt.text = sql;
stmt.parameters[0] = note.id;
stmt.execute();
}
public static function updateNote(note:Dish):void
{
var sql:String = "UPDATE notes SET title=?, time=?, message=? WHERE id=?";
var stmt:SQLStatement = new SQLStatement();
stmt.sqlConnection = sqlConnection;
stmt.text = sql;
stmt.parameters[0] = note.title;
stmt.parameters[1] = note.time;
stmt.parameters[2] = note.message;
stmt.parameters[3] = note.id;
stmt.execute();
}
protected static function processRow(o:Object):Dish
{
var note:Dish = new Dish();
note.id = o.id;
note.title = o.title == null ? "" : o.title;
note.time = o.time == null ? "" :o.time;
note.message = o.message == null ? "" : o.message;
return note;
}
public static function openDatabase(file:File):void
{
var newDB:Boolean = true;
if (file.exists)
newDB = false;
_sqlConnection = new SQLConnection();
_sqlConnection.open(file);
if (newDB)
{
createDatabase();
populateDatabase();
}
}
protected static function createDatabase():void
{
var sql:String =
"CREATE TABLE IF NOT EXISTS notes ( "+
"id INTEGER PRIMARY KEY AUTOINCREMENT, " +
"title VARCHAR(50), " +
"time VARCHAR(50), " +
"message VARCHAR(200))";
var stmt:SQLStatement = new SQLStatement();
stmt.sqlConnection = sqlConnection;
stmt.text = sql;
stmt.execute();
}
protected static function populateDatabase():void
{
var file:File = File.applicationDirectory.resolvePath("assets/notes.xml");
if (!file.exists) return;
var stream:FileStream = new FileStream();
stream.open(file, FileMode.READ);
var xml:XML = XML(stream.readUTFBytes(stream.bytesAvailable));
stream.close();
for each (var n:XML in xml.note)
{
var note:Dish = new Dish();
note.id = n.id;
note.title = n.title;
note.time = n.time;
note.message = n.message;
addNote(note);
}
}
}
}
and the code of the MXML file:
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" title="Profile">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import model.Dish;
import model.SQLiteDatabase;
import spark.events.IndexChangeEvent;
protected function onNote2Selected(event:IndexChangeEvent):void {
var selectedNote:Dish = event.currentTarget.dataProvider[event.newIndex];
navigator.pushView(MemberDetailsView, selectedNote);
}
protected function onAddButtonClicked(event:MouseEvent):void {
navigator.pushView(AddMemberView);
}
]]>
</fx:Script>
<s:VGroup gap="-1">
</s:VGroup>
**<s:List dataProvider="{SQLiteDatabase.members()}" change="onNoteSelected(event)"**
left="0" right="0" top="0" bottom="0">
<s:itemRenderer>
<fx:Component>
<s:IconItemRenderer labelField="title" messageField="message"/>
</fx:Component>
</s:itemRenderer>
</s:List>
</s:View>
The error is because you are accessing a static method to a non-static class. The meaning is that the instance has not been created yet, so while the linker should be able to locate the static member function, there is no way to resolve which instance of the object. If you declare the class static, it should solve this problem.
public static function notes():ArrayCollection
{
var noteList:ArrayCollection = new ArrayCollection();
var sql:String = "SELECT id, title, time, message FROM notes";
var stmt:SQLStatement = new SQLStatement();
stmt.sqlConnection = sqlConnection;
stmt.text = sql;
stmt.execute();
var sqlResult:SQLResult = stmt.getResult();
if (sqlResult) {
var result:Array = sqlResult.data;
if (result) {
for (var index:Number = 0; index < result.length; index++) {
noteList.addItem(processRow(result[index]));
}
}
}
return noteList;
}
public static function members():ArrayCollection
{
var noteList:ArrayCollection = new ArrayCollection();
var sql:String = "SELECT testid, Dish_Name FROM DishInventory";
var stmt:SQLStatement = new SQLStatement();
stmt.sqlConnection = sqlConnection;
stmt.text = sql;
stmt.execute();
var sqlResult:SQLResult = stmt.getResult();
if (sqlResult) {
var result:Array = sqlResult.data;
if (result) {
for (var index:Number = 0; index < result.length; index++) {
noteList.addItem(processRow2(result[index]));
}
}
}
return noteList;
}
protected static function processRow(o:Object):Dish
{
var note:Dish = new Dish();
note.id = o.id;
note.title = o.title == null ? "" : o.title;
note.time = o.time == null ? "" :o.time;
note.message = o.message == null ? "" : o.message;
return note;
}
protected static function processRow2(o:Object):Dish
{
var note:Dish = new Dish();
note.id = o.testID;
note.title = o.Dish_Name == null ? "" : o.Dish_Name;
return note;
}
Still got to clean my coding though
The solution is:
private function sqlResult(res:SQLEvent):void {
var sqlResult:SQLResult = stmt.getResult();
if (sqlResult) {
var data:Array = sqlResult.data;
contactList = new ArrayCollection();
for each(var item:Object in data){
contact = new Contact(item);
contactList.addItem(contact);
}
}
}
Related
I can not figure out how I get more XML file from the language images,
In the image here you will look at setupItems how it is built
Here it explains how I build the missing XML file but I do not understand how I build it properly that will work for me on the site
public function init(param1:int) : void
{
var _loc2_:String = null;
this.itemHolder.addChild(this.hairHolder);
this.itemHolder.addChild(this.shirtHolder);
this.shirtHolder.visible = false;
this.itemHolder.addChild(this.pantsHolder);
this.pantsHolder.visible = false;
this.itemHolder.addChild(this.shoesHolder);
this.shoesHolder.visible = false;
this.activeHolder = this.hairHolder;
this.initButtons();
this.randomTimer = new Timer(this.randomTimerInitDelay,this.randomTimerCount);
this.randomTimer.addEventListener(TimerEvent.TIMER,this.changeRandomClothes,false,0,true);
this.xml = new XML();
if(param1 == 1)
{
_loc2_ = "boyItems.xml";
}
else if(param1 == 2)
{
_loc2_ = "girlItems.xml";
}
this.xmlLoader = new URLLoader(new URLRequest("./website/common/register/xmls/" + _loc2_));
this.xmlLoader.addEventListener(Event.COMPLETE,this.xmlLoaded);
this.xmlLoader.addEventListener(IOErrorEvent.IO_ERROR,this.errorLoadingXml);
}
another code
private function xmlLoaded(param1:Event) : void
{
this.xmlLoader.removeEventListener(Event.COMPLETE,this.xmlLoaded);
this.xmlLoader.removeEventListener(IOErrorEvent.IO_ERROR,this.errorLoadingXml);
this.xml = XML(this.xmlLoader.data);
Register.AVATAR_HAIR = this.xml.hair.child(0).#id;
var _loc2_:int = Math.random() * 2 + 1;
this.bubble.gotoAndStop("hair_" + Register.language + _loc2_);
this.setupItems(this.xml.hair,this.hairItems,this.hairHolder);
this.setupItems(this.xml.shirt,this.shirtItems,this.shirtHolder);
this.setupItems(this.xml.pants,this.pantsItems,this.pantsHolder);
this.setupItems(this.xml.shoes,this.shoesItems,this.shoesHolder);}
private function setupItems(param1:*, param2:Array, param3:Sprite) : void
{
var _loc9_:* = undefined;
var _loc10_:Item = null;
var _loc4_:int = 54.5;
var _loc5_:Number = 64.5;
var _loc6_:*;
var _loc7_:int = (_loc6_ = param1).children().length();
var _loc8_:int = 0;
while(_loc8_ < _loc7_)
{
_loc9_ = _loc6_.child(_loc8_);
(_loc10_ = new Item()).x = _loc4_;
_loc4_ += this.itemSpacing;
_loc10_.y = _loc5_;
_loc10_.loadItem(_loc9_.#type,_loc9_.#ordinal,_loc9_.#id,_loc9_.#inventoryType,Register.pathToItemsFolder);
param2.push(_loc10_);
param3.addChild(_loc10_);
_loc8_++;
}
}
This is the loadItem file:
(Maybe here you can see how I build the XML files)
public function loadItem(param1:int, param2:int, param3:int, param4:int, param5:String) : void
{
this.type = param1;
this.ordinal = param2;
this.id = param3;
this.itemImage = new ImageItemNoCache(param1,param2,param3,param4,null,null,param5);
this.itemImage.mouseEnabled = false;
this.itemImage.mouseChildren = false;
this.itemImage.addEventListener(ImageItem.DATA_LOADED,this.positionImage,false,0,true);
addChild(this.itemImage);
addEventListener(MouseEvent.CLICK,this.clickedMe,false,0,true);
}
Code for ImageItemNoCache:
public class ImageItemNoCache extends ImageItem
{
private var textData:Object;
private var itemData:Object;
private var pathToItemsFolder:String;
public function ImageItemNoCache(param1:int, param2:int, param3:int, param4:int, param5:Object = null, param6:Object = null, param7:String = ".")
{
this.textData = param5;
this.itemData = param6;
this.pathToItemsFolder = param7;
super(param1,param2,param3,param4);
}
override protected function getImageItemData(param1:int, param2:int = -1, param3:int = -1, param4:int = -1) : ImageItemData
{
return new ImageItemDataNoCache(param1,param2,param3,param4,this.textData,this.itemData,this.pathToItemsFolder);
}
override public function clone() : DisplayItem
{
return new ImageItemNoCache(getType(),getOrdinal(),getId(),getInventoryType(),this.textData,this.itemData,this.pathToItemsFolder);
}
}
I need you help to fin a solution to order an array by creation date time.
I try this but this function seems to order only by date and not by time together.
private function triImgDate(folder:Array):void {
var acDirectory:ArrayCollection = new ArrayCollection();
for each (var tmp:File in folder) {
if (!tmp.isDirectory) {
if (tmp.extension != null && ArrayFunction.inArray(tabExt, tmp.extension.toLowerCase()))
{
listeImages.addItem(tmp);
}
}
else {
triImgDate(tmp.getDirectoryListing());
}
}
var dataSortField:SortField = new SortField();
dataSortField.name = "creationDate";
dataSortField.numeric = false;
var numericDataSort:Sort = new Sort();
numericDataSort.fields = [dataSortField];
listeImages.sort = numericDataSort;
listeImages.refresh();
}
So if you can help me.
Best regards
// solution
private function triImgDate(folder:Array):void {
var acDirectory:ArrayCollection = new ArrayCollection();
var arTempListeImages:ArrayCollection = new ArrayCollection();
var arTempListeCompar:ArrayCollection = new ArrayCollection();
var objImg:Object;
for each (var tmp:File in folder) {
if (!tmp.isDirectory) {
if (tmp.extension != null && ArrayFunction.inArray(tabExt, tmp.extension.toLowerCase())) {
objImg= new Object();
//listeImages.addItem(tmp);
arTempListeImages.addItem(tmp);
objImg.creationDate=tmp.creationDate;
objImg.url=tmp.url;
objImg.pos=arTempListeCompar.length;
arTempListeCompar.addItem(objImg)
}
} else {
triImgDate(tmp.getDirectoryListing());
}
}
var dataSortField:SortField = new SortField();
dataSortField.name = "creationDate";
dataSortField.compareFunction = function (a:Object, b:Object) : int {
var na:Number = a.creationDate.getTime();
var nb:Number = b.creationDate.getTime();
if (na < nb)
return -1;
if (na > nb)
return 1;
return 0;
};
var numericDataSort:Sort = new Sort();
numericDataSort.fields = [dataSortField];
arTempListeCompar.sort= numericDataSort;
arTempListeCompar.refresh();
var cpt:int=0;
for each (var objTem:Object in arTempListeCompar) {
listeImages.addItem(arTempListeImages[arTempListeCompar[cpt].pos]);
cpt++;
}
arTempListeImages=[];
arTempListeCompar=[];
acDirectory=[];
}
What you're trying to do here, is comparing twe dates by their string representation, which is obviously not a good way to do it.
you should rather use compareFunction property of the SortField object. Something like that (not tested):
private function triImgDate(folder:Array):void {
var acDirectory:ArrayCollection = new ArrayCollection();
for each (var tmp:File in folder) {
if (!tmp.isDirectory) {
if (tmp.extension != null && ArrayFunction.inArray(tabExt, tmp.extension.toLowerCase())) {
listeImages.addItem(tmp);
}
} else {
triImgDate(tmp.getDirectoryListing());
}
}
var dataSortField:SortField = new SortField();
dataSortField.name = "creationDate";
dataSortField.sortFunction = function(date1:Date, date2:Date):int {
const t1:uint = date1.time;
const t2:uint = date2.time;
if (t1 < t2) {
return -1;
}
if (t1 == t2) {
return 0;
}
return 1;
}
var numericDataSort:Sort = new Sort();
numericDataSort.fields = [dataSortField];
listeImages.sort = numericDataSort;
listeImages.refresh();
}
How can I skew a Textfield in order to set a ascending space for each line.
Following image should illustrate my intention:
Got it:
adobe
public class TextBlock_createTextLineExample extends Sprite {
public function TextBlock_createTextLineExample():void {
var str:String = "I am a TextElement, created from a String and assigned " +
"to the content property of a TextBlock. The createTextLine() method " +
"then created these lines, 300 pixels wide, for display." ;
var fontDescription:FontDescription = new FontDescription("Arial");
var format:ElementFormat = new ElementFormat(fontDescription);
format.fontSize = 16;
var textElement:TextElement = new TextElement(str, format);
var textBlock:TextBlock = new TextBlock();
textBlock.content = textElement;
createLines(textBlock);
}
private function createLines(textBlock:TextBlock):void
{
var lineWidth:Number = 300;
var xPos:Number = 15.0;
var yPos:Number = 20.0;
var textLine:TextLine = textBlock.createTextLine (null, lineWidth);
while (textLine)
{
//increase textLine every Line 10 px to get an offset
textLine.x += 10
textLine.y = yPos;
yPos += textLine.height + 2;
addChild (textLine);
textLine = textBlock.createTextLine (textLine, lineWidth);
}
}
}
}
private static const _DEG2RAD:Number = Math.PI/180;
public static function skew(target:DisplayObject, skewXDegree:Number, skewYDegree:Number):void
{
var m:Matrix = target.transform.matrix.clone();
m.b = Math.tan(skewYDegree*_DEG2RAD);
m.c = Math.tan(skewXDegree*_DEG2RAD);
target.transform.matrix = m;
}
public static function skewY(target:DisplayObject, skewDegree:Number):void
{
var m:Matrix = target.transform.matrix.clone();
m.b = Math.tan(skewDegree*_DEG2RAD);
target.transform.matrix = m;
}
public static function skewX(target:DisplayObject, skewDegree:Number):void
{
var m:Matrix = target.transform.matrix.clone();
m.c = Math.tan(skewDegree*_DEG2RAD);
target.transform.matrix = m;
}
I am working on actionscript to generate a SWF dynamically using JSON data coming from an HTTP request. I receive the data on creationComplete and try to generate a tree like structure. I don’t create the whole tree at the same time. I create 2 levels, level 1 and level 2. My goal is to attach custom events on the panels which represent tree nodes. When users click the panels, it dispatches custom events and try to generate the next level. So, it goes like this :
On creation complete -> get JSON-> create top tow levels -> click on level 2-> create the level 2 and level 3 -> click on level 3-> create level 3 and 4. …and so on and so on. I am attaching my code with this email. Please take a look at it and if you have any hints on how you would do this if you need to paint a tree having total level number = “n” where n = 0 to 100
Should I carry the data around in CustomPageClickEvent class.
[code]
import com.iwobanas.effects.*;
import flash.events.MouseEvent;
import flash.filters.BitmapFilterQuality;
import flash.filters.BitmapFilterType;
import flash.filters.GradientGlowFilter;
import mx.controls.Alert;
private var roundedMask:Sprite;
private var panel:NewPanel;
public var oldPanelIds:Array = new Array();
public var pages:Array = new Array();
public var delPages:Array = new Array();
public function DrawPlaybook(pos:Number,title:String,chld:Object):void {
panel = new NewPanel(chld);
panel.title = title;
panel.name=title;
panel.width = 100;
panel.height = 80;
panel.x=pos+5;
panel.y=40;
var gradientGlow:GradientGlowFilter = new GradientGlowFilter();
gradientGlow.distance = 0;
gradientGlow.angle = 45;
gradientGlow.colors = [0xFFFFF0, 0xFFFFFF];
gradientGlow.alphas = [0, 1];
gradientGlow.ratios = [0, 255];
gradientGlow.blurX = 10;
gradientGlow.blurY = 10;
gradientGlow.strength = 2;
gradientGlow.quality = BitmapFilterQuality.HIGH;
gradientGlow.type = BitmapFilterType.OUTER;
panel.filters =[gradientGlow];
this.rawChildren.addChild(panel);
pages.push(panel);
panel.addEventListener(MouseEvent.CLICK,
function(e:MouseEvent){onClickHandler(e,title,chld)});
this.addEventListener(CustomPageClickEvent.PANEL_CLICKED,
function(e:CustomPageClickEvent){onCustomPanelClicked(e,title)});
}
public function onClickHandler(e:MouseEvent,title:String,chld:Object):void {
for each(var stp1:NewPanel in pages){
if(stp1.title==title){
var eventObj:CustomPageClickEvent = new CustomPageClickEvent("panelClicked");
eventObj.panelClicked = stp1;
dispatchEvent(eventObj);
}
}
}
private function onCustomPanelClicked(e:CustomPageClickEvent,title:String):void {
Alert.show("onCustomPanelClicked" + title);
var panel:NewPanel;
for each(var stp:NewPanel in pages){
startAnimation(e,stp);
}
if(title == e.panelClicked.title){
panel = new NewPanel(null);
panel.title = title;
panel.name=title;
panel.width = 150;
panel.height = 80;
panel.x=100;
panel.y=40;
this.rawChildren.addChild(panel);
var slideRight:SlideRight = new SlideRight();
slideRight.target=panel;
slideRight.duration=750;
slideRight.showTarget=true;
slideRight.play();
var jsonData = this.map.getValue(title);
var posX:Number = 50;
var posY:Number = 175;
for each ( var pnl:NewPanel in pages){
pages.pop();
}
for each ( var stp1:Object in jsonData.children){
panel = new NewPanel(null);
panel.title = stp1.text;
panel.name=stp1.id;
panel.width = 100;
panel.id=stp1.id;
panel.height = 80;
panel.x = posX;
panel.y=posY;
posX+=150;
var s:String="hi" + stp1.text;
panel.addEventListener(MouseEvent.CLICK,
function(e:MouseEvent){onChildClick(e,s);});
this.addEventListener(CustomPageClickEvent.PANEL_CLICKED,
function(e:CustomPageClickEvent){onCustomPnlClicked(e)});
this.rawChildren.addChild(panel);
pages.push(panel);
this.addEventListener(CustomPageClickEvent.PANEL_CLICKED,
function(e:CustomPageClickEvent){onCustomPanelClicked(e,title)});
var slide:SlideUp = new SlideUp();
slide.target=panel;
slide.duration=1500;
slide.showTarget=false;
slide.play();
}
}
}
public function onChildClick(e:MouseEvent,s:String):void {
for each(var stp1:NewPanel in pages){
if(stp1.title==e.currentTarget.title){
var eventObj:CustomPageClickEvent = new CustomPageClickEvent("panelClicked");
eventObj.panelClicked = stp1;
dispatchEvent(eventObj);
}
}
}
private function onCustomPnlClicked(e:CustomPageClickEvent):void {
for each ( var pnl:NewPanel in pages){
pages.pop();
}
}
private function fadePanel(event:Event,panel:NewPanel):void{
panel.alpha -= .005;
if (panel.alpha <= 0){
panel.removeEventListener(Event.ENTER_FRAME,
function(e:Event){fadePanel(e,panel);});
};
panel.title="";
}
private function startAnimation(event:CustomPageClickEvent,panel:NewPanel):void{
panel.addEventListener(Event.ENTER_FRAME,
function(e:Event){fadePanel(e,panel)});
}
[/code]
Thanks in advance.
Palash
completely forgot i don't have enough rep to edit...
import com.iwobanas.effects.*;
import flash.events.MouseEvent;
import flash.filters.BitmapFilterQuality;
import flash.filters.BitmapFilterType;
import flash.filters.GradientGlowFilter;
import mx.controls.Alert;
private var roundedMask:Sprite;
private var panel:NewPanel;
public var oldPanelIds:Array = new Array();
public var pages:Array = new Array();
public var delPages:Array = new Array();
public function DrawPlaybook(pos:Number,title:String,chld:Object):void {
panel = new NewPanel(chld);
panel.title = title;
panel.name=title;
panel.width = 100;
panel.height = 80;
panel.x=pos+5;
panel.y=40;
var gradientGlow:GradientGlowFilter = new GradientGlowFilter();
gradientGlow.distance = 0;
gradientGlow.angle = 45;
gradientGlow.colors = [0xFFFFF0, 0xFFFFFF];
gradientGlow.alphas = [0, 1];
gradientGlow.ratios = [0, 255];
gradientGlow.blurX = 10;
gradientGlow.blurY = 10;
gradientGlow.strength = 2;
gradientGlow.quality = BitmapFilterQuality.HIGH;
gradientGlow.type = BitmapFilterType.OUTER;
panel.filters = [gradientGlow];
this.rawChildren.addChild(panel);
pages.push(panel);
panel.addEventListener(MouseEvent.CLICK, function(e:MouseEvent){onClickHandler(e,title,chld)});
this.addEventListener(CustomPageClickEvent.PANEL_CLICKED, function(e:CustomPageClickEvent){onCustomPanelClicked(e,title)});
}
public function onClickHandler(e:MouseEvent,title:String,chld:Object):void {
for each(var stp1:NewPanel in pages){
if(stp1.title==title){
var eventObj:CustomPageClickEvent = new CustomPageClickEvent("panelClicked");
eventObj.panelClicked = stp1;
dispatchEvent(eventObj);
}
}
}
private function onCustomPanelClicked(e:CustomPageClickEvent,title:String):void {
Alert.show("onCustomPanelClicked" + title);
var panel:NewPanel;
for each(var stp:NewPanel in pages){
startAnimation(e,stp);
}
if(title == e.panelClicked.title){
panel = new NewPanel(null);
panel.title = title;
panel.name=title;
panel.width = 150;
panel.height = 80;
panel.x=100;
panel.y=40;
this.rawChildren.addChild(panel);
var slideRight:SlideRight = new SlideRight();
slideRight.target=panel;
slideRight.duration=750;
slideRight.showTarget=true;
slideRight.play();
var jsonData = this.map.getValue(title);
var posX:Number = 50;
var posY:Number = 175;
for each ( var pnl:NewPanel in pages){
pages.pop();
}
for each ( var stp1:Object in jsonData.children){
panel = new NewPanel(null);
panel.title = stp1.text;
panel.name=stp1.id;
panel.width = 100;
panel.id=stp1.id;
panel.height = 80;
panel.x = posX;
panel.y=posY;
posX += 150;
var s:String="hi" + stp1.text;
panel.addEventListener(MouseEvent.CLICK, function(e:MouseEvent){onChildClick(e,s);});
this.addEventListener(CustomPageClickEvent.PANEL_CLICKED, function(e:CustomPageClickEvent){onCustomPnlClicked(e)});
this.rawChildren.addChild(panel);
pages.push(panel);
this.addEventListener(CustomPageClickEvent.PANEL_CLICKED, function(e:CustomPageClickEvent){onCustomPanelClicked(e,title)});
var slide:SlideUp = new SlideUp();
slide.target=panel;
slide.duration=1500;
slide.showTarget=false;
slide.play();
}
}
}
public function onChildClick(e:MouseEvent,s:String):void {
for each(var stp1:NewPanel in pages){
if(stp1.title==e.currentTarget.title){
var eventObj:CustomPageClickEvent = new CustomPageClickEvent("panelClicked");
eventObj.panelClicked = stp1;
dispatchEvent(eventObj);
}
}
}
private function onCustomPnlClicked(e:CustomPageClickEvent):void {
for each ( var pnl:NewPanel in pages){
pages.pop();
}
}
private function fadePanel(event:Event,panel:NewPanel):void{
panel.alpha -= .005;
if (panel.alpha <= 0){
panel.removeEventListener(Event.ENTER_FRAME,
function(e:Event){fadePanel(e,panel);});
};
panel.title="";
}
private function startAnimation(event:CustomPageClickEvent,panel:NewPanel):void{
panel.addEventListener(Event.ENTER_FRAME,
function(e:Event){fadePanel(e,panel)});
}
my problem is that after I create the new movie clips I don't know how to access them
var numOfBalls:int = 5;
var balls:Array = new Array();
import flash.utils.getDefinitionByName;
function addBall(instanceName:String) {
var mcIName:String = "ball";
var tMC:Class = getDefinitionByName(mcIName) as Class;
var newMc:MovieClip = new tMC() as MovieClip;
newMc.name = instanceName;
trace("added " + newMc.name);
newMc.x = randRange(10, 300);
newMc.y = randRange(10, 300);
addChild(newMc);
return this.newMc;
}
function randRange(start:Number, end:Number) : Number {
return Math.floor(start +(Math.random() * (end - start)));
}
var i = 0;
while ( i < numOfBalls) {
balls[i] = addBall("ball_" + i);
i++;
}
trace (this.balls[0]); // returnes error
trace (this.balls_0); //returnes error
function addBall(instanceName:String):MovieClip {
var mcIName:String = "ball";
var tMC:Class = getDefinitionByName(mcIName) as Class;
var newMc:MovieClip = new tMC() as MovieClip;
newMc.name = instanceName;
trace("added " + newMc.name);
newMc.x = randRange(10, 300);
newMc.y = randRange(10, 300);
addChild(newMc);
return newMc;
}
That should fixe it. return typed to MovieClip, and the fix bit,
return newMc instead of this.newMc;
newMC doesn't belong to this.
if you had this.newMc = newMC maybe.
you need to specify what the addBall function is returning
function addBall(instanceName:String):MovieClip {
and you may have to push the balls into the balls array, like
balls[i].push(addBall("ball_" + i));
try this, i'm not sure about your problem
The only thing i can see is the index i where you write the name of the new MovieClip, in ActionScript3 you can't pass a numeric value to a String without convert it with toString() method, try to fix it and see if it works
var numOfBalls:int = 5;
var balls:Array = new Array();
import flash.utils.getDefinitionByName;
function addBall(instanceName:String):MovieClip {
var mcIName:String = "ball";
var tMC:Class = getDefinitionByName(mcIName) as Class;
var newMc:MovieClip = new tMC() as MovieClip;
newMc.name = instanceName;
trace("added " + newMc.name);
newMc.x = randRange(10, 300);
newMc.y = randRange(10, 300);
addChild(newMc);
return this.newMc;
}
function randRange(start:Number, end:Number) : Number {
return Math.floor(start +(Math.random() * (end - start)));
}
var i = 0;
while ( i < numOfBalls) {
// convert i with toString() is requested in as3 or will return ERRORS
balls.push(addBall("ball_" + i.toString ()));
i++;
}
trace (MovieClip(this.balls[0]));