I guess Features and Concepts -> ActionScript 3 (AS3) would be the correct category in the docs. Ideally, this category will eventually be filled with many pages that teach a user how to use each of the language features of AS3. So there should probably be a page that teaches how to cast an object to a different type.
At the bare minimum, the page about casting should also demonstrate the syntax and explain how each type of cast behaves: ActionScript has two different types of casts. Function casts: var obj:MyType = MyType(anotherObj); As casts: var obj:MyType = anotherObj as MyType; Function casts throw an exception when the cast fails. As casts return null when the cast fails. -- Josh Tynjala Bowler Hat LLC <https://bowlerhat.dev> On Wed, Apr 21, 2021 at 9:16 AM Andrew Wetmore <cottag...@gmail.com> wrote: > Where in the docs should I capture this wisdom? > > On Wed., Apr. 21, 2021, 12:57 p.m. Josh Tynjala, < > joshtynj...@bowlerhat.dev> > wrote: > > > Just like how things worked in Flash, you can't just cast a random `var > > obj:Object = {}` to a class. It needs to be a real instance of that > class. > > The basic rule to keep in mind is this: You can use `as CustomVO` with > > something that was created with `new CustomVO()`. For any other type, an > as > > cast returns null. > > > > -- > > Josh Tynjala > > Bowler Hat LLC <https://bowlerhat.dev> > > > > > > On Tue, Apr 20, 2021 at 4:24 PM gbarbosa <gbarbosa...@gmail.com> wrote: > > > > > Hi Royale, > > > > > > I was recently trying to cast an Object > > > > > > obj as CustomVO > > > > > > but it would always turn to null. The as operator kept thinking > CustomVO > > > was > > > type Function() why would this be? > > > > > > The workaround ending up being to set the prototype. > > > > > > Object.setPrototypeOf(obj, CustomVO.prototype); > > > > > > and this successfully casted correctly. Is there a better way to do > this? > > > Most likely something something to do with the structure of CustomVO? > the > > > classes it extends? > > > > > > Thanks for your time. > > > > > > -Gabriel Barbosa > > > > > > > > > > > > -- > > > Sent from: http://apache-royale-development.20373.n8.nabble.com/ > > > > > >