1120:访问未定义的属性_stop

Posted

技术标签:

【中文标题】1120:访问未定义的属性_stop【英文标题】:1120: Access of undefined property _stop 【发布时间】:2012-04-08 21:44:36 【问题描述】:

我在通过 as3 在 flash 中创建视频播放器时遇到问题,问题是每当我尝试编译项目时,编译器错误都会显示:

1120: Access of undefined property _stop.
1120: Access of undefined property _pause.
1120: Access of undefined property _play.
1180: Call to a possibly undefined method Button.
1120: Access of undefined property _prev.
1180: Call to a possibly undefined method Button.
1120: Access of undefined property _next.

而且我已经提到了这些对象,所以请帮我解决这个问题。我是新手,我很难找到错误。

as3:

import flash.events.MouseEvent;

var _xmlLoader      :URLLoader      = null;

var _urlRequest     :URLRequest     = null;

var _xml            :XML            = null;

var _netConn        :NetConnection  = null;

var _netstr         :NetStream      = null;

var _video          :Video          = null; 

var _currentVideoId :int            = 0;

var _isPlaying      :Boolean        = false;

var _soundTransform :SoundTransform = new SoundTransform();

var _volume         :int            = 1;

var _duration       :Number         = 0;

function Init():void


    _urlRequest = new URLRequest("vids.xml");

    _xmlLoader = new URLLoader();
    _xmlLoader = new URLLoader(_urlRequest);
    _xmlLoader.addEventListener(Event.COMPLETE, XMLLoaded, false, 0, true);


function XMLLoaded($e:Event):void

    _xml = new XML($e.target.data);


function SetupVideo():void

    _netConn = new NetConnection();
    _netConn.addEventListener(NetStatusEvent.NET_STATUS, OnStatusEvent, false, 0, true);
    _netConn.connect(null);



function OnStatusEvent(stat:Object):void

    trace(stat.info.code);
    switch(stat.info.code)
    
        case "NetConnection.Connect.Success":
             SetupNetStream();
             break;
        case "NetStream.Play.Stop":
             _stop.enabled = false;
             _pause.enabled = false;
             _play.enabled = true;
             _isPlaying = false;
             _netstr.close();
             break;
    


function SetupNetStream():void

    _netstr = new NetStream(_netConn);
    _netstr.addEventListener(NetStatusEvent.NET_STATUS, OnStatusEvent, false, 0, true);

    var $customClient = new Object();
    $customClient.onMetaData = onMetaData;

    _netstr.client = $customClient

    _video = new Video(500, 250);
    _video.smoothing = true;
    _video.y
    _video.x = stage.stageWidth/2 - _video.width/2;
    _video.attachNetStream(_netstr);
    addChild(_video);


function onMetaData($info:Object):void 

    _duration = $info.duration;


function SetupButtons():void

    _prev.addEventListener(MouseEvent.CLICK, PreviousVideo, false, 0, true);
    _next.addEventListener(MouseEvent.CLICK,NextVideo,false,0,true);
    _play.addEventListener(MouseEvent.CLICK, PlayVideo, false, 0, true);
    _pause.addEventListener(MouseEvent.CLICK, PauseVideo, false, 0, true);
    _stop.addEventListener(MouseEvent.CLICK, StopVideo, false, 0, true);
    _sound.addEventListener(MouseEvent.CLICK, SoundVolume, false, 0, true);

    _stop.enabled = false;
    _pause.enabled = false;
    _prev.enabled = false;
    _next.enabled = false;


function PreviousVideo($e:MouseEvent):void

    _currentVideoId -=1;

    _stop.enabled = true;
    _pause.enabled = true;
    _play.enabled = false;

    if(_currentVideoId < 0)
    
        _currentVideoId = _xml.video.length()-1;
    

    _videoName.text = _xml.video[_currentVideoId].@name;
    _netstr.play(String(_xml.video[_currentVideoId].@path));


function NextVideo($e:MouseEvent):void

    _currentVideoId +=1;

    _stop.enabled = true;
    _pause.enabled = true;
    _play.enabled = false;

    if(_currentVideoId == _xml.video.length())
    
        _currentVideoId = 0;
    
    _videoName.text = _xml.video[_currentVideoId].@name;
    _netstr.play(String(_xml.video[_currentVideoId].@path));


function PlayVideo($e:MouseEvent):void

    _play.enabled= false;
    _next.enabled = true;
    _prev.enabled = true;
    _stop.enabled= true;
    _pause.enabled= true;

    if(_isPlaying == false)
    
        _isPlaying = true;
        _netstr.play(String(_xml.video[_currentVideoId].@path));
        _videoName.text = _xml.video[_currentVideoId].@name;
        addEventListener(Event.ENTER_FRAME, Update, false, 0, true);
    else
        _netstr.resume();
    


function PauseVideo($e:MouseEvent):void

    _play.enabled= true;
    _pause.enabled= false;
    _netstr.pause();


function StopVideo($e:MouseEvent):void

    _stop.enabled= false;
    _pause.enabled= false;
    _play.enabled= true;

    _isPlaying = false;
    removeEventListener(Event.ENTER_FRAME, Update);
    _netstr.close();


function Update($e:Event):void

    _track.value = (_netstr.time / _duration) * _track.maximum;


function SoundVolume($e:MouseEvent):void

    if( _volume == 1 )
    
        _volume = 0;
        _sound.label = "Sound On";
    else
        _volume = 1;
        _sound.label = "Sound Off";
    

    _soundTransform.volume = _volume;
    _netstr.soundTransform = _soundTransform;


Init();
SetupVideo();
SetupButtons();

甚至我已经将这些对象转换为按钮符号。

【问题讨论】:

【参考方案1】:

可能您忘记为对象分配实例名称,用作_stop、_pause、_play 按钮等。

还要检查库属性中的“为 ActionScript 导出”标志。

【讨论】:

将对象指定为影片剪辑重要吗? 对不起,我没听懂你..你是在告诉我将对象或按钮分配为电影剪辑..如果是这样,那么我这样做了,但也没有用.. 不,我的意思是你必须为场景中的每个对象指定名称,如果你要在代码中使用它。它不仅可以是电影剪辑。 这可能会有所帮助youtube.com/watch?v=wClLhl6qEIs&feature=related 他甚至没有使用按钮的实例名称,很抱歉我忘了说我是在 as3 中制作的,所以我无法添加按钮,我必须添加时间线上的所有动作脚本..

以上是关于1120:访问未定义的属性_stop的主要内容,如果未能解决你的问题,请参考以下文章

如何修复 1120:在初始化八哥部分时访问未定义的属性 main?

求助如何在 flask 中访问未定义的 url 时重定向到其他页面

TypeError:无法读取 Object.stop anguar 5 处未定义的属性“UpdateXY”

查找数据时无法读取未定义的属性“查找”

如何在 FlashBuilder 中使用外部动作脚本类(我以为我知道)

魔术方法