yishayw commented on a change in pull request #880: URL: https://github.com/apache/royale-asjs/pull/880#discussion_r448920597
########## File path: frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/ErrorImage.as ########## @@ -0,0 +1,151 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.royale.html.beads { + + import org.apache.royale.core.IBead; + import org.apache.royale.core.IStrand; + import org.apache.royale.events.Event; + + import org.apache.royale.events.EventDispatcher; + import org.apache.royale.core.IImage; + import org.apache.royale.core.IImageModel; + + /** + * The ErrorImage class is a bead that can be used to + * display an alternate image, in the event that the specified image + * cannot be loaded. + * + * It will be supported by controls that load the ImageModel bead and + * implement the IImage interface + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion Royale 0.9.8 + */ + + public class ErrorImage implements IBead { + + protected var _strand:IStrand; + + public function ErrorImage() { + } + + private var _src:String; + /** + * The source of the image + */ + public function get src():String { + return _src; + } + + public function set src(value:String):void { + _src = value; + } + + COMPILE::JS{ + private var _hostElement:HTMLImageElement; + protected function get hostElement():HTMLImageElement + { + return _hostElement; + } + } + protected function get hostModel():IImageModel + { + return _strand.getBeadByType(IImageModel) as IImageModel; + } + + /** + * @copy org.apache.royale.core.IBead#strand + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion Royale 0.9.8 + */ + public function set strand(value:IStrand):void + { + _strand = value; + + COMPILE::JS { + + if(_strand is IImage) + { + _hostElement = (_strand as IImage).imageElement as HTMLImageElement; + if(_hostElement){ + + _hostElement.addEventListener('error', errorHandler); + + if(_emptyIsError) + { + (_strand as EventDispatcher).addEventListener("beadsAdded", beadsAddedHandler); + } + } + } + } + } + + COMPILE::JS + private function beadsAddedHandler(event:Event):void + { + (_strand as EventDispatcher).removeEventListener("beadsAdded", beadsAddedHandler); + + if(hostModel) + hostModel.addEventListener("urlChanged",srcChangedHandler); + srcChangedHandler(null); + } + + private var _emptyIsError:Boolean = false; Review comment: Good start, but you need to add some annotations to make it visible to IDEs and API Docs. E.g. /** * Indicates whether the "empty or null" values will be treated as errors and replaced by the indicated src * * @langversion 3.0 * @playerversion Flash 10.2 * @playerversion AIR 2.6 * @productversion Royale 0.9.8 */ ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
