![]() |
|
||||||||||
|
|||||||
|
|
« Предыдущая тема | Следующая тема » |
| Опции темы | Опции просмотра |
|
![]() |
![]() |
|
|||||
|
Регистрация: Apr 2007
Сообщений: 60
|
Здравствуйте.
Написал свой класс. Реализовал несколько методов. Пытаюсь из одного метода вызвать другой. Никаких результатов (оба метода относяться к одному и тому хе классу). Смотрел дебагером - не заходит в нужный метод. Ошибок в коде нет (по-моему). Заранее благодарен, Родион |
|
|||||
|
Если я правильно понял то о чем вы спрашиваете, то у меня это работает
-) |
|
|||||
|
Регистрация: Apr 2007
Сообщений: 60
|
Есть класс.
В нем 2 метода. В первом методе читаеться XML и вызывается второй метод данного класса. Если второй метод вызвать до чтения XML (снаружи xml.onLoad) - все работает. Если же вызвать его внутри xml.onLoad - метод 2 не срабатывает. 2 метод необходимо вызывать внутри чтения XML. |
|
|||||
|
Регистрация: May 2003
Адрес: Tallinn
Сообщений: 3,182
|
Пример в студию
|
|
|||||
|
Регистрация: Apr 2007
Сообщений: 60
|
Не срабатывает tf.text = CurrentSongInfo(Songs[i]); внутри Initialize(...) метода
class Player
{
private var soundObject : Sound;
private var songCount : Number;
private var xml : XML;
private var Songs : Array;
private var XMLurl : String;
private var PlayPointer : Number;
// constructor
public function Player()
{
this.soundObject = new Sound();
this.songCount = 0;
this.xml = new XML();
this.PlayPointer = 0;
}
// initializing controll buttons
private function InitControllButtons(xpos:Number, ypos:Number)
{
var pause_button : MovieClip = _root.attachMovie("pause_button", "pause_button", _root.getNextHighestDepth());
pause_button._x = xpos;
pause_button._y = ypos;
pause_button.onRelease = function()
{
PlayPointer = soundObject.position;
soundObject.stop();
}
var play_button : MovieClip = _root.attachMovie("play_button", "play_button", _root.getNextHighestDepth());
play_button._x = xpos;
play_button._y = ypos + 30;
play_button.onRelease = function()
{
soundObject.start(PlayPointer/1000);
}
}
// gets artist and song title
public function CurrentSongInfo(song:String) : String
{
var Current : Sound = new Sound();
var Attributes : String = "";
Current.loadSound(song, true);
Current.onLoad = function(success:Boolean)
{
if (success)
{
Attributes = Current.id3.artist + Current.id3.songtitle;
delete Current;
}
else
Attributes = "error loading song";
}
return Attributes;
}
// initialize main data and XML
public function Initialize(XMLLocation : String)
{
SetVolumeControll(485, 5, 0xA3ECFE);
InitControllButtons(455, 5);
this.XMLurl = XMLLocation;
xml.ignoreWhite = true;
xml.onLoad = function(success : Boolean)
{
if (success)
{
songCount = this.firstChild.childNodes.length;
Songs = new Array(songCount);
for (var i:Number = 0; i<songCount; i++)
{
var tf : TextField;
Songs[i] = this.firstChild.childNodes[i].childNodes[0].nodeValue;
var curMovieItem : MovieClip = _root.attachMovie("listItem", "listItem"+i, _root.getNextHighestDepth());
tf = curMovieItem.createTextField("tt", 1, 0, 0, 360, 18);
var my_fmt:TextFormat = new TextFormat();
my_fmt.bold = true;
my_fmt.font = "Verdana";
my_fmt.size = 12;
my_fmt.color = 0x000000;
tf.selectable = true;
tf.setNewTextFormat(my_fmt);
tf.text = CurrentSongInfo(Songs[i]);
curMovieItem._y = 10 + 25 * i ;
curMovieItem._x = 10;
curMovieItem.song = Songs[i];
curMovieItem.onRelease = function()
{
//var inTween:Tween = new Tween(this, "_alpha", Strong.easeOut, 100, 25, 2, true);
soundObject.loadSound(this.song, true);
SetAllAlphaToMax();
PlayPointer = 0;
}
}
}
else
trace("Error loading XML !");
}
xml.load(XMLurl);
}
// draws volume controll manipulator, gets coordinates of volume controll
private function SetVolumeControll(xpos:Number, ypos:Number, color)
{
var volumer : MovieClip;
volumer = _root.createEmptyMovieClip("_volumer", _root.getNextHighestDepth());
volumer.left = volumer._x;
volumer.right = volumer._x;
volumer.top = volumer._y;
volumer.bottom = volumer.top-100;
volumer._y = soundObject.getVolume();
with (_root)
{ lineStyle(0, color);
moveTo(xpos, ypos);
lineTo(xpos+60, ypos);
lineTo(xpos+60, ypos+120);
lineTo(xpos, ypos+120);
lineTo(xpos, ypos);
moveTo(xpos+20, ypos+10);
lineTo(xpos+20, ypos+110); }
with (volumer) {
lineStyle(0, color);
beginFill(color);
moveTo(xpos+5, ypos+5);
lineTo(xpos+35, ypos+5);
lineTo(xpos+35, ypos+15);
lineTo(xpos+5, ypos+15);
lineTo(xpos+5, ypos+5);
endFill(); }
volumer.createTextField("volume_txt", volumer.getNextHighestDepth(), 490+volumer._width+4, 6, 30, 22);
volumer.volume_txt.text = soundObject.getVolume();
// events - to controll volume value
volumer.onPress = function()
{ this.startDrag(false, this.left, this.top, this.right, this.bottom);
this.isDragging = true; }
volumer.onMouseMove = function()
{ if (this.isDragging)
this.volume_txt.text = this._y; }
volumer.onRelease = function()
{ this.stopDrag();
this.isDragging = false;
soundObject.setVolume(this._y); }
}
public function SetAllAlphaToMax()
{
for(var i=0; i<songCount; i++)
_root["listItem"+i]._alpha = 100;
}
}
Последний раз редактировалось Rodionnn; 15.10.2007 в 18:14. |
|
|||||
|
Негуру
администратор
Регистрация: Jan 2000
Адрес: Кёнигсберг in Moscow
Сообщений: 21,883
Записей в блоге: 7
|
О чем я и говорил.
Вы объявляете один метод внутри другого и нарушаетет область видимости. Внутри xml(.onLoad) нет метода CurrentSongInfo, есть только то, что касается класса XML. Вам прямая дорога к mx.utils.Delegate. Читайте: http://flash-ripper.com/archives/000680.php |
|
|||||
|
Регистрация: May 2003
Адрес: Tallinn
Сообщений: 3,182
|
там где события (в данном примере onPress, onLoad) исмользуйте такую конструкцию:
|
|
|||||
|
Регистрация: Apr 2007
Сообщений: 60
|
спасибо большое.
буду пробовать |
![]() |
![]() |
Часовой пояс GMT +4, время: 06:18. |
|
|
« Предыдущая тема | Следующая тема » |
|
|